forked from chakra-ui/chakra-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreview-head.html
31 lines (25 loc) · 856 Bytes
/
preview-head.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<script>
;(function setColorModeVar(initialValue) {
const mql = window.matchMedia("(prefers-color-scheme: dark)")
const systemPreference = mql.matches ? "dark" : "light"
let persistedPreference
try {
persistedPreference = localStorage.getItem("chakra-ui-color-mode")
} catch (error) {
console.log(
"Chakra UI: localStorage is not available. Color mode persistence might not work as expected",
)
}
const isInStorage = typeof persistedPreference === "string"
let colorMode
if (isInStorage) {
colorMode = persistedPreference
} else {
colorMode = initialValue === "system" ? systemPreference : initialValue
}
if (colorMode) {
const root = document.documentElement
root.style.setProperty("--chakra-ui-color-mode", colorMode)
}
})("light")
</script>