From a2bd99031a871efc381d816294bced9f7401dca5 Mon Sep 17 00:00:00 2001 From: Daniel <50356015+danny007in@users.noreply.github.com> Date: Fri, 24 Mar 2023 15:18:12 +0530 Subject: [PATCH] color mode docs created --- src/html/components/_head.astro | 12 +- src/html/components/_scripts.astro | 65 +---- src/html/components/dashboard/_sidenav.astro | 10 + src/html/components/dashboard/_topbar.astro | 32 +-- .../components/docs/color-mode/navbar-html.md | 80 ++++++ .../docs/color-mode/toggle-script.md | 48 ++++ src/html/pages/docs/color-mode.astro | 227 ++++++++++++++++++ src/scss/_docs.scss | 4 + src/scss/parts/_core.scss | 1 + 9 files changed, 380 insertions(+), 99 deletions(-) create mode 100644 src/html/components/docs/color-mode/navbar-html.md create mode 100644 src/html/components/docs/color-mode/toggle-script.md create mode 100644 src/html/pages/docs/color-mode.astro create mode 100644 src/scss/_docs.scss diff --git a/src/html/components/_head.astro b/src/html/components/_head.astro index a7c2f24a3..5a71c4fe6 100644 --- a/src/html/components/_head.astro +++ b/src/html/components/_head.astro @@ -16,13 +16,15 @@ const cssPath = isRtl ? '.rtl' : '' - + + + - - + + - - + + diff --git a/src/html/components/_scripts.astro b/src/html/components/_scripts.astro index 5859a8f85..c911676c3 100644 --- a/src/html/components/_scripts.astro +++ b/src/html/components/_scripts.astro @@ -3,8 +3,8 @@ const { path } = Astro.props const distPath = (path != undefined) ? path : '../../../dist' --- - - + + @@ -36,64 +36,3 @@ const distPath = (path != undefined) ? path : '../../../dist' } }) - - - diff --git a/src/html/components/dashboard/_sidenav.astro b/src/html/components/dashboard/_sidenav.astro index f85ffa682..e897415fd 100644 --- a/src/html/components/dashboard/_sidenav.astro +++ b/src/html/components/dashboard/_sidenav.astro @@ -162,6 +162,7 @@ const htmlPath = (path != undefined) ? '.' : '..' + + + + + - + - + +``` \ No newline at end of file diff --git a/src/html/components/docs/color-mode/toggle-script.md b/src/html/components/docs/color-mode/toggle-script.md new file mode 100644 index 000000000..52892aae4 --- /dev/null +++ b/src/html/components/docs/color-mode/toggle-script.md @@ -0,0 +1,48 @@ +```js +// Color Mode Toggler +(() => { + 'use strict' + const storedTheme = localStorage.getItem('theme') + const getPreferredTheme = () => { + if (storedTheme) { + return storedTheme + } + return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light' + } + const setTheme = function (theme) { + if (theme === 'auto' && window.matchMedia('(prefers-color-scheme: dark)').matches) { + document.documentElement.setAttribute('data-bs-theme', 'dark') + } else { + document.documentElement.setAttribute('data-bs-theme', theme) + } + } + setTheme(getPreferredTheme()) + const showActiveTheme = theme => { + const activeThemeIcon = document.querySelector('.theme-icon-active i') + const btnToActive = document.querySelector('[data-bs-theme-value="' + theme + '"]') + const svgOfActiveBtn = btnToActive.querySelector('i').getAttribute('class') + document.querySelectorAll('[data-bs-theme-value]').forEach(element => { + element.classList.remove('active') + }) + btnToActive.classList.add('active') + activeThemeIcon.setAttribute('class', svgOfActiveBtn) + } + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => { + if (storedTheme !== 'light' || storedTheme !== 'dark') { + setTheme(getPreferredTheme()) + } + }) + window.addEventListener('DOMContentLoaded', () => { + showActiveTheme(getPreferredTheme()) + document.querySelectorAll('[data-bs-theme-value]') + .forEach(toggle => { + toggle.addEventListener('click', () => { + const theme = toggle.getAttribute('data-bs-theme-value') + localStorage.setItem('theme', theme) + setTheme(theme) + showActiveTheme(theme) + }) + }) + }) +})() +``` \ No newline at end of file diff --git a/src/html/pages/docs/color-mode.astro b/src/html/pages/docs/color-mode.astro new file mode 100644 index 000000000..41ce69ae2 --- /dev/null +++ b/src/html/pages/docs/color-mode.astro @@ -0,0 +1,227 @@ +--- +import Head from "@components/_head.astro"; +import Footer from "@components/dashboard/_footer.astro"; +import Topbar from "@components/dashboard/_topbar.astro"; +import Sidenav from "@components/dashboard/_sidenav.astro"; +import Scripts from "@components/_scripts.astro"; +import NavbarHtml from "@components/docs/color-mode/navbar-html.md"; +import ToggleScript from "@components/docs/color-mode/toggle-script.md"; +const title = "AdminLTE 4 | General Form Elements"; +const mainPage = "forms"; +const page = "general"; +--- + + + + + + + +
+ + + +
+
+
+
+
+

Color Mode Toggle

+
+
+ +
+
+
+
+ +
+
+
+ +
+ + +
+ +
+
+ +
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ + + + + + + diff --git a/src/scss/_docs.scss b/src/scss/_docs.scss new file mode 100644 index 000000000..c93304051 --- /dev/null +++ b/src/scss/_docs.scss @@ -0,0 +1,4 @@ +.lte-code-snippet .astro-code { + padding: 1.5rem; + @include border-radius($border-radius); +} diff --git a/src/scss/parts/_core.scss b/src/scss/parts/_core.scss index 57dd0e87d..f7f1c9baa 100644 --- a/src/scss/parts/_core.scss +++ b/src/scss/parts/_core.scss @@ -9,3 +9,4 @@ @import "../app-main"; @import "../app-footer"; @import "../dropdown"; +@import "../docs";