Enable dark mode in browser UI (#16025)

This commit is contained in:
Alexey Pyltsyn 2022-10-31 17:29:01 +03:00 committed by GitHub
parent 86659ea8a9
commit 41b42d94fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 24 deletions

View File

@ -4,6 +4,7 @@ html {
-ms-text-size-adjust: 100%;
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
color-scheme: light;
}
body {

View File

@ -1,18 +1,22 @@
body.night {
background-color: $bg-body-night;
color: $body-text-night;
html.night {
color-scheme: dark;
body {
background-color: $bg-body-night;
color: $body-text-night;
&.landing {
background-color: $bg-body-landing-night;
.header > .container {
background-color: $bg-header-night;
}
.card, .cardlet {
color: inherit;
background-color: $bg-card-night;
}
footer {
background-color: $bg-footer-landing-night;
&.landing {
background-color: $bg-body-landing-night;
.header > .container {
background-color: $bg-header-night;
}
.card, .cardlet {
color: inherit;
background-color: $bg-card-night;
}
footer {
background-color: $bg-footer-landing-night;
}
}
}

View File

@ -53,7 +53,7 @@ The available classes are:
blockquote {
body.night & {
html.night & {
// DARK THEME
&:not(.important):not(.warning):not(.restricted):not(.experimental) {
@ -102,7 +102,7 @@ blockquote {
}
}
body:not(.night) & {
html:not(.night) & {
// LIGHT THEME
&:not(.important):not(.warning):not(.restricted):not(.experimental) {

View File

@ -1,11 +1,11 @@
.docker-upgrade-cta {
body.night & {
html.night & {
background-color: change-color($orange-10, $alpha: 0.3);
border: 1px solid $orange-10;
p, .docker-upgrade-cta__heading { color: $white-0; }
}
body:not(.night) & {
html:not(.night) & {
background-color: $orange-10;
border: 1px solid $orange-20;
p, .docker-upgrade-cta__heading { color: inherit; }

View File

@ -22,17 +22,17 @@ const darkMode = window.matchMedia && window.matchMedia("(prefers-color-scheme:
const selectedTheme = window.localStorage ? localStorage.getItem("theme") : null;
if (selectedTheme !== null) {
if (selectedTheme === "night") _("body").classList.add("night");
if (selectedTheme === "night") _("html").classList.add("night");
} else if (darkMode) {
_("body").classList.add("night");
_("html").classList.add("night");
}
function themeToggler() {
const sw = _("#switch-style"), b = _("body");
if (sw && b) {
sw.checked = b.classList.contains("night")
const sw = _("#switch-style"), h = _("html");
if (sw && h) {
sw.checked = h.classList.contains("night")
sw.addEventListener("change", function (){
b.classList.toggle("night", this.checked)
h.classList.toggle("night", this.checked)
if (window.localStorage) {
this.checked ? localStorage.setItem("theme", "night") : localStorage.setItem("theme", "day")
}