You've already forked Atomcms-edit
e6d92f27b3
- Rename all .js/.jsx files to .ts/.tsx across resources/js and theme dirs - Add TypeScript 6.0 with strict mode, tsconfig.json - Add type definitions for Inertia page props, Alpine.js, Turbolinks - Update vite.config.js entries to .ts/.tsx extensions - Update all Blade @vite() calls to match new .ts/.tsx entry points - Add TypeScript ESLint config (replacing unused Vue plugin) - Add @types/react, @types/react-dom, @types/lodash - Add typecheck script and integrate into check pipeline - Full tsc --noEmit, ESLint, and production build pass cleanly
46 lines
1.1 KiB
TypeScript
Executable File
46 lines
1.1 KiB
TypeScript
Executable File
type Theme = "light" | "dark";
|
|
|
|
interface ThemeSwitcherStore {
|
|
currentTheme: Theme;
|
|
init(): void;
|
|
initButton(): void;
|
|
toggleTheme(): void;
|
|
}
|
|
|
|
const ThemeSwitcher: ThemeSwitcherStore = {
|
|
currentTheme: "light",
|
|
|
|
init() {
|
|
if (
|
|
localStorage.theme === "dark" ||
|
|
(typeof window.matchMedia !== "undefined" &&
|
|
window.matchMedia("(prefers-color-scheme: dark)").matches &&
|
|
localStorage.theme !== "light")
|
|
) {
|
|
this.toggleTheme();
|
|
}
|
|
|
|
document.addEventListener("turbolinks:load", () => this.initButton());
|
|
},
|
|
|
|
initButton() {
|
|
const themeSwitcher = document.getElementById("theme-switcher");
|
|
|
|
themeSwitcher?.addEventListener("click", () => this.toggleTheme());
|
|
},
|
|
|
|
toggleTheme() {
|
|
if (this.currentTheme === "light") {
|
|
this.currentTheme = "dark";
|
|
document.documentElement.classList.add("dark");
|
|
} else {
|
|
this.currentTheme = "light";
|
|
document.documentElement.classList.remove("dark");
|
|
}
|
|
|
|
localStorage.setItem("theme", this.currentTheme);
|
|
},
|
|
};
|
|
|
|
export { ThemeSwitcher as default };
|