feat(webui): theme helpers
This commit is contained in:
parent
fbffc67638
commit
47e497867f
16
webui/src/lib/theme.js
Normal file
16
webui/src/lib/theme.js
Normal file
@ -0,0 +1,16 @@
|
||||
const STORAGE_KEY = "picobot-theme";
|
||||
|
||||
export function preferredTheme() {
|
||||
const saved = localStorage.getItem(STORAGE_KEY);
|
||||
if (saved === "light" || saved === "dark") return saved;
|
||||
return matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
}
|
||||
|
||||
export function applyTheme(theme) {
|
||||
document.documentElement.dataset.theme = theme;
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
document
|
||||
.querySelector('meta[name="theme-color"]')
|
||||
?.setAttribute("content", theme === "dark" ? "#0b1017" : "#eef1f5");
|
||||
localStorage.setItem(STORAGE_KEY, theme);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user