Skip to content

Commit ca8f9cc

Browse files
authored
Theme initialization code can switch back to light theme. (#8531)
1 parent da854e4 commit ca8f9cc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

static/js/dark-init.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818
// ignore errors e.g. when media query matching is not supported
1919
}
2020

21-
// Detects whether the dartdoc control was set to use dark theme
22-
let dartdocDarkThemeIsSet = window.localStorage.getItem('colorTheme') == 'true';
21+
// Detects whether the control widget was set to use a specific theme
22+
let colorTheme = window.localStorage.getItem('colorTheme');
23+
let lightThemeIsSet = colorTheme == 'false';
24+
let darkThemeIsSet = colorTheme == 'true';
2325

24-
// Switch the top-level style marker to use dark theme instead of the light theme default.
25-
if (mediaPrefersDarkScheme || dartdocDarkThemeIsSet) {
26+
if (lightThemeIsSet) {
27+
// nothing to do here, the default style is the light-theme
28+
} else if (mediaPrefersDarkScheme || darkThemeIsSet) {
29+
// switch to the dark theme
2630
document.body.classList.remove('light-theme');
2731
document.body.classList.add('dark-theme');
2832
}

0 commit comments

Comments
 (0)