feat(theme): persistent light/dark toggle in the titlebar

This commit is contained in:
pj committed 2026-06-20 18:46:43 -04:00
1 parent a5b3c0c0e3
commit 9991d318ba
5 files changed
+61 -3

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
export type Theme = "light" | "dark";
const KEY = "margin-theme";
export function initialTheme(): Theme {
const attr = document.documentElement.getAttribute("data-theme");
if (attr === "light" || attr === "dark") return attr;
const saved = localStorage.getItem(KEY);
if (saved === "light" || saved === "dark") return saved;
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
}
export function applyTheme(theme: Theme) {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem(KEY, theme);
}