mirror of
https://git.aramjonghu.dev/AramJonghu/aramjonghu-site.git
synced 2026-09-05 23:23:31 +02:00
TS7 upgrade + write to TS over JS
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const LIGHT = "latte";
|
||||
const DARK = "macchiato";
|
||||
|
||||
export function getSystemTheme(): string {
|
||||
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? DARK
|
||||
: LIGHT;
|
||||
}
|
||||
|
||||
export function getStoredTheme(): string | null {
|
||||
return localStorage.getItem("theme");
|
||||
}
|
||||
|
||||
export function getInitialTheme(): string {
|
||||
return getStoredTheme() || getSystemTheme();
|
||||
}
|
||||
|
||||
export function applyTheme(theme: string): void {
|
||||
const root = document.documentElement;
|
||||
|
||||
root.classList.remove(LIGHT, DARK);
|
||||
|
||||
root.classList.add(theme);
|
||||
|
||||
localStorage.setItem("theme", theme);
|
||||
}
|
||||
|
||||
export function toggleTheme(current: string): string {
|
||||
return current === DARK ? LIGHT : DARK;
|
||||
}
|
||||
Reference in New Issue
Block a user