Files
banner/web/src/lib/stores/theme.svelte.ts
Xevion 5fab8c216a feat: add course search UI with ts-rs type bindings
Integrate ts-rs for Rust-to-TypeScript type generation, build course
search page with filters, pagination, and expandable detail rows,
and refactor theme toggle into a reactive store with view transition
animation.
2026-01-28 22:11:17 -06:00

37 lines
892 B
TypeScript

class ThemeStore {
isDark = $state<boolean>(false);
private initialized = false;
init() {
if (this.initialized || typeof window === "undefined") return;
this.initialized = true;
const stored = localStorage.getItem("theme");
if (stored === "light" || stored === "dark") {
this.isDark = stored === "dark";
} else {
this.isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
}
this.updateDOMClass();
}
toggle() {
this.isDark = !this.isDark;
localStorage.setItem("theme", this.isDark ? "dark" : "light");
this.updateDOMClass();
}
private updateDOMClass() {
if (typeof document === "undefined") return;
if (this.isDark) {
document.documentElement.classList.add("dark");
} else {
document.documentElement.classList.remove("dark");
}
}
}
export const themeStore = new ThemeStore();