From 01deafa5bf5b68784d434d6f361c21d72cf89069 Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 8 Feb 2022 00:43:03 +0000 Subject: Add initial dark theme --- pydis_site/static/css/base/navbar.css | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 pydis_site/static/css/base/navbar.css (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css new file mode 100644 index 00000000..95ca36b8 --- /dev/null +++ b/pydis_site/static/css/base/navbar.css @@ -0,0 +1,83 @@ +.switch { + position: relative; + height: 3.25em; + width: 6.5em; + cursor: pointer; +} + +.switch-outer { + position: absolute; + height: 100%; + width: 100%; + border-radius: 2em; + transition: background-color 0.3s ease-out; +} + +.switch.dark .switch-outer { + background-color: #22272E; +} + +.switch.light .switch-outer { + background-color: #3f61d9; +} + +.switch-inner { + width: 95%; + top: 50%; + border-radius: 2em; + transition: background-color 0.2s ease-out; +} + +.switch.light .switch-inner { + background-color: #7289da; +} +.switch.dark .switch-inner { + background-color: #1b2137; +} + +.knob { + position: absolute; + height: 75%; + width: 37.5%; + top: 50%; + transform: translate(0%, -65%); + border-radius: 10em; + transition: all 0.5s ease-out; +} + +.knob.dark { + background-color: #586282; + margin: 6% auto auto 8%; +} + +.knob.light { + background-color: #364c94; + margin: 6% auto auto 56%; +} + +.theme-icon { + position: absolute !important; + color: white; + --ggs: 1.25; + opacity: 100%; + transition: opacity 0.2s ease-out; + top: 33%; + bottom: auto; +} + +.theme-icon.light { + left: 18%; +} + +.theme-icon.dark { + right: 18%; + top: 35% +} + +.switch.dark .theme-icon.light { + opacity: 0; +} + +.switch.light .theme-icon.dark { + opacity: 0; +} \ No newline at end of file -- cgit v1.2.3 From 2f0fa9b82e32bb6c7febf5285d5d5461de2eed6b Mon Sep 17 00:00:00 2001 From: GDWR Date: Tue, 8 Feb 2022 08:44:20 +0000 Subject: Resize switch --- pydis_site/static/css/base/navbar.css | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css index 95ca36b8..497429c6 100644 --- a/pydis_site/static/css/base/navbar.css +++ b/pydis_site/static/css/base/navbar.css @@ -1,7 +1,7 @@ .switch { position: relative; - height: 3.25em; - width: 6.5em; + height: 2em; + width: 5em; cursor: pointer; } @@ -58,20 +58,20 @@ .theme-icon { position: absolute !important; color: white; - --ggs: 1.25; + --ggs: 1; opacity: 100%; - transition: opacity 0.2s ease-out; - top: 33%; + transition: opacity 0.3s ease-out; bottom: auto; } .theme-icon.light { - left: 18%; + left: 15%; + top: 20% } .theme-icon.dark { - right: 18%; - top: 35% + right: 15%; + top: 20% } .switch.dark .theme-icon.light { -- cgit v1.2.3 From 9c3a4b677e29598329a03a1c613bfc22dc1e232f Mon Sep 17 00:00:00 2001 From: GDWR Date: Wed, 9 Feb 2022 00:50:34 +0000 Subject: Resize theme switch --- pydis_site/static/css/base/navbar.css | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css index 497429c6..66744c99 100644 --- a/pydis_site/static/css/base/navbar.css +++ b/pydis_site/static/css/base/navbar.css @@ -1,7 +1,7 @@ .switch { position: relative; height: 2em; - width: 5em; + width: 4em; cursor: pointer; } @@ -21,56 +21,38 @@ background-color: #3f61d9; } -.switch-inner { - width: 95%; - top: 50%; - border-radius: 2em; - transition: background-color 0.2s ease-out; -} - -.switch.light .switch-inner { - background-color: #7289da; -} -.switch.dark .switch-inner { - background-color: #1b2137; -} - .knob { position: absolute; - height: 75%; + padding-top: 20%; + height: 70%; width: 37.5%; - top: 50%; - transform: translate(0%, -65%); border-radius: 10em; transition: all 0.5s ease-out; } .knob.dark { background-color: #586282; - margin: 6% auto auto 8%; + margin: 7% auto auto 8%; } .knob.light { background-color: #364c94; - margin: 6% auto auto 56%; + margin: 7% auto auto 56%; } .theme-icon { position: absolute !important; - color: white; --ggs: 1; - opacity: 100%; transition: opacity 0.3s ease-out; - bottom: auto; } .theme-icon.light { - left: 15%; - top: 20% + left: 10%; + top: 15% } .theme-icon.dark { - right: 15%; + right: 10%; top: 20% } -- cgit v1.2.3 From 00638be5e4dc6fdea0398b70301e5bb956c18a39 Mon Sep 17 00:00:00 2001 From: GDWR Date: Wed, 9 Feb 2022 00:51:35 +0000 Subject: Resize theme switch --- pydis_site/static/css/base/navbar.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css index 66744c99..bf8913ab 100644 --- a/pydis_site/static/css/base/navbar.css +++ b/pydis_site/static/css/base/navbar.css @@ -42,7 +42,7 @@ .theme-icon { position: absolute !important; - --ggs: 1; + --ggs: 0.75; transition: opacity 0.3s ease-out; } -- cgit v1.2.3 From 1177f0d442a40e603b5d4d06dfe6590133724dbf Mon Sep 17 00:00:00 2001 From: hedy Date: Thu, 14 Dec 2023 20:29:27 +0800 Subject: Automatically fix lint --- pydis_site/static/css/base/navbar.css | 2 +- pydis_site/static/js/base/navbar.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css index bf8913ab..9d71e799 100644 --- a/pydis_site/static/css/base/navbar.css +++ b/pydis_site/static/css/base/navbar.css @@ -62,4 +62,4 @@ .switch.light .theme-icon.dark { opacity: 0; -} \ No newline at end of file +} diff --git a/pydis_site/static/js/base/navbar.js b/pydis_site/static/js/base/navbar.js index b49c86b1..a4b8a0aa 100644 --- a/pydis_site/static/js/base/navbar.js +++ b/pydis_site/static/js/base/navbar.js @@ -91,4 +91,4 @@ document.addEventListener("DOMContentLoaded", () => { displayThemedElements(); toggleThemeSwitch(); }); -}); \ No newline at end of file +}); -- cgit v1.2.3 From 7559cb72da7e8b84dd81b33d54ba6c6abd156fd7 Mon Sep 17 00:00:00 2001 From: hedy Date: Fri, 5 Jan 2024 20:55:34 +0800 Subject: Dark: Name JS & CSS files according to their content We have the CSS for the navbar in base.css, the relevant files only contain code for the theme toggle, so they should be named as such. If we ever implement CSS variables per-theme, they could then be done in `themes.css`. --- pydis_site/static/css/base/navbar.css | 65 ------------------------- pydis_site/static/css/base/themes.css | 67 ++++++++++++++++++++++++++ pydis_site/static/js/base/navbar.js | 91 ----------------------------------- pydis_site/static/js/base/themes.js | 91 +++++++++++++++++++++++++++++++++++ pydis_site/templates/base/navbar.html | 4 +- 5 files changed, 160 insertions(+), 158 deletions(-) delete mode 100644 pydis_site/static/css/base/navbar.css create mode 100644 pydis_site/static/css/base/themes.css delete mode 100644 pydis_site/static/js/base/navbar.js create mode 100644 pydis_site/static/js/base/themes.js (limited to 'pydis_site/static/css/base') diff --git a/pydis_site/static/css/base/navbar.css b/pydis_site/static/css/base/navbar.css deleted file mode 100644 index 9d71e799..00000000 --- a/pydis_site/static/css/base/navbar.css +++ /dev/null @@ -1,65 +0,0 @@ -.switch { - position: relative; - height: 2em; - width: 4em; - cursor: pointer; -} - -.switch-outer { - position: absolute; - height: 100%; - width: 100%; - border-radius: 2em; - transition: background-color 0.3s ease-out; -} - -.switch.dark .switch-outer { - background-color: #22272E; -} - -.switch.light .switch-outer { - background-color: #3f61d9; -} - -.knob { - position: absolute; - padding-top: 20%; - height: 70%; - width: 37.5%; - border-radius: 10em; - transition: all 0.5s ease-out; -} - -.knob.dark { - background-color: #586282; - margin: 7% auto auto 8%; -} - -.knob.light { - background-color: #364c94; - margin: 7% auto auto 56%; -} - -.theme-icon { - position: absolute !important; - --ggs: 0.75; - transition: opacity 0.3s ease-out; -} - -.theme-icon.light { - left: 10%; - top: 15% -} - -.theme-icon.dark { - right: 10%; - top: 20% -} - -.switch.dark .theme-icon.light { - opacity: 0; -} - -.switch.light .theme-icon.dark { - opacity: 0; -} diff --git a/pydis_site/static/css/base/themes.css b/pydis_site/static/css/base/themes.css new file mode 100644 index 00000000..35273d44 --- /dev/null +++ b/pydis_site/static/css/base/themes.css @@ -0,0 +1,67 @@ +/* Theme switch toggle */ + +.switch { + position: relative; + height: 2em; + width: 4em; + cursor: pointer; +} + +.switch-outer { + position: absolute; + height: 100%; + width: 100%; + border-radius: 2em; + transition: background-color 0.3s ease-out; +} + +.switch.dark .switch-outer { + background-color: #22272E; +} + +.switch.light .switch-outer { + background-color: #3f61d9; +} + +.knob { + position: absolute; + padding-top: 20%; + height: 70%; + width: 37.5%; + border-radius: 10em; + transition: all 0.5s ease-out; +} + +.knob.dark { + background-color: #586282; + margin: 7% auto auto 8%; +} + +.knob.light { + background-color: #364c94; + margin: 7% auto auto 56%; +} + +.theme-icon { + position: absolute !important; + --ggs: 0.75; + transition: opacity 0.3s ease-out; +} + +.theme-icon.light { + left: 10%; + top: 15% +} + +.theme-icon.dark { + right: 10%; + top: 20% +} + +.switch.dark .theme-icon.light { + opacity: 0; +} + +.switch.light .theme-icon.dark { + opacity: 0; +} diff --git a/pydis_site/static/js/base/navbar.js b/pydis_site/static/js/base/navbar.js deleted file mode 100644 index 2a57cad4..00000000 --- a/pydis_site/static/js/base/navbar.js +++ /dev/null @@ -1,91 +0,0 @@ -"use strict"; - -const defaultTheme = "light"; -const lightStylesheet = document.getElementById("bulma-css"); -const darkStylesheet = document.getElementById("bulma-css-dark"); - -// Get saved preference for the site in local storage, optionally accounting -// for system preference used when a page loads. -function getCurrentTheme(systemPrefers) { - const theme = localStorage.getItem("theme"); - - if (theme !== null && theme !== "") - return theme; - - if (systemPrefers !== undefined) - return systemPrefers; - - return defaultTheme; -} - -// Disable & enable the correct CSS stylesheets based on chosen theme. -function setStyleSheets(newTheme) { - switch (newTheme) { - case "light": - lightStylesheet.disabled = false; - darkStylesheet.disabled = true; - break; - case "dark": - lightStylesheet.disabled = true; - darkStylesheet.disabled = false; - break; - } - - document.querySelector("html").setAttribute("data-theme", newTheme); -} - -// Reflect chosen theme on the switch toggle. -function toggleThemeSwitch(newTheme) { - const switchToggle = document.getElementById("theme-switch"); - const knob = document.getElementById("theme-knob"); - - switch (newTheme) { - case "light": - knob.classList.remove("dark"); - knob.classList.add("light"); - setTimeout(function() { - switchToggle.classList.remove("dark"); - switchToggle.classList.add("light"); - }, 100); - break; - case "dark": - knob.classList.remove("light"); - knob.classList.add("dark"); - setTimeout(function() { - switchToggle.classList.remove("light"); - switchToggle.classList.add("dark"); - }, 100); - break; - } -} - -// Executed when the page has finished loading. -document.addEventListener("DOMContentLoaded", () => { - let theme; - const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)"); - - if (systemPrefersDark.matches) - theme = getCurrentTheme("dark"); - else - theme = getCurrentTheme(); - - setStyleSheets(theme); - toggleThemeSwitch(theme); - - systemPrefersDark.addEventListener("change", ({matches: isDark}) => { - const newTheme = isDark ? "dark" : "light"; - // Let the new system preference take precedence over toggle preference - // on page reloads. - localStorage.removeItem("theme"); - setStyleSheets(newTheme); - toggleThemeSwitch(newTheme); - }) - - const switchToggle = document.getElementById("theme-switch"); - switchToggle.addEventListener("click", () => { - const newTheme = getCurrentTheme() === "light" ? "dark" : "light"; - localStorage.setItem("theme", newTheme); - setStyleSheets(newTheme); - toggleThemeSwitch(newTheme); - }); -}); diff --git a/pydis_site/static/js/base/themes.js b/pydis_site/static/js/base/themes.js new file mode 100644 index 00000000..2a57cad4 --- /dev/null +++ b/pydis_site/static/js/base/themes.js @@ -0,0 +1,91 @@ +"use strict"; + +const defaultTheme = "light"; +const lightStylesheet = document.getElementById("bulma-css"); +const darkStylesheet = document.getElementById("bulma-css-dark"); + +// Get saved preference for the site in local storage, optionally accounting +// for system preference used when a page loads. +function getCurrentTheme(systemPrefers) { + const theme = localStorage.getItem("theme"); + + if (theme !== null && theme !== "") + return theme; + + if (systemPrefers !== undefined) + return systemPrefers; + + return defaultTheme; +} + +// Disable & enable the correct CSS stylesheets based on chosen theme. +function setStyleSheets(newTheme) { + switch (newTheme) { + case "light": + lightStylesheet.disabled = false; + darkStylesheet.disabled = true; + break; + case "dark": + lightStylesheet.disabled = true; + darkStylesheet.disabled = false; + break; + } + + document.querySelector("html").setAttribute("data-theme", newTheme); +} + +// Reflect chosen theme on the switch toggle. +function toggleThemeSwitch(newTheme) { + const switchToggle = document.getElementById("theme-switch"); + const knob = document.getElementById("theme-knob"); + + switch (newTheme) { + case "light": + knob.classList.remove("dark"); + knob.classList.add("light"); + setTimeout(function() { + switchToggle.classList.remove("dark"); + switchToggle.classList.add("light"); + }, 100); + break; + case "dark": + knob.classList.remove("light"); + knob.classList.add("dark"); + setTimeout(function() { + switchToggle.classList.remove("light"); + switchToggle.classList.add("dark"); + }, 100); + break; + } +} + +// Executed when the page has finished loading. +document.addEventListener("DOMContentLoaded", () => { + let theme; + const systemPrefersDark = window.matchMedia("(prefers-color-scheme: dark)"); + + if (systemPrefersDark.matches) + theme = getCurrentTheme("dark"); + else + theme = getCurrentTheme(); + + setStyleSheets(theme); + toggleThemeSwitch(theme); + + systemPrefersDark.addEventListener("change", ({matches: isDark}) => { + const newTheme = isDark ? "dark" : "light"; + // Let the new system preference take precedence over toggle preference + // on page reloads. + localStorage.removeItem("theme"); + setStyleSheets(newTheme); + toggleThemeSwitch(newTheme); + }) + + const switchToggle = document.getElementById("theme-switch"); + switchToggle.addEventListener("click", () => { + const newTheme = getCurrentTheme() === "light" ? "dark" : "light"; + localStorage.setItem("theme", newTheme); + setStyleSheets(newTheme); + toggleThemeSwitch(newTheme); + }); +}); diff --git a/pydis_site/templates/base/navbar.html b/pydis_site/templates/base/navbar.html index 57fdbf6a..64518146 100644 --- a/pydis_site/templates/base/navbar.html +++ b/pydis_site/templates/base/navbar.html @@ -1,9 +1,9 @@ {% load static %} {% block head %} - + - + {% endblock %}