Skip to content

Commit 03f5a4f

Browse files
committed
Update reflectColorPreference to apply web awesome's wa-dark class
* Web Awesome provides its own `wa-dark` class to trigger dark mode, which we need `reflectColorPreference` to use * See: https://backers.webawesome.com/docs/themes/classic#dark-mode
1 parent e396ea9 commit 03f5a4f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/util/theme-preference.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ export function setColorPreference(value){
2121
}
2222

2323
export function reflectColorPreference(){
24-
document.firstElementChild.setAttribute(htmlDataAttributeName, getColorPreference())
24+
const preference = getColorPreference()
25+
const browserPrefersDark = window.matchMedia(`(prefers-color-scheme:dark)`).matches
26+
const forcedDarkMode = preference == "dark"
27+
const systemMatchMode = preference == "match-system" && browserPrefersDark
28+
29+
if(forcedDarkMode || systemMatchMode) {
30+
document.firstElementChild.classList.add("wa-dark")
31+
} else {
32+
document.firstElementChild.classList.remove("wa-dark")
33+
}
2534
}
2635

2736

@@ -30,4 +39,4 @@ export function setDefaultColorPreference(defaultValue){
3039
if(!localStorage){ return }
3140
if(localStorage.getItem(storageKey)){ return }
3241
setColorPreference(defaultValue)
33-
}
42+
}

0 commit comments

Comments
 (0)