mirror of
https://git.aramjonghu.nl/AramJonghu/aramjonghu-site.git
synced 2026-06-06 17:18:24 +02:00
31 lines
640 B
JavaScript
31 lines
640 B
JavaScript
const LIGHT = "latte";
|
|
const DARK = "macchiato";
|
|
|
|
export function getSystemTheme() {
|
|
return window.matchMedia("(prefers-color-scheme: dark)").matches
|
|
? DARK
|
|
: LIGHT;
|
|
}
|
|
|
|
export function getStoredTheme() {
|
|
return localStorage.getItem("theme");
|
|
}
|
|
|
|
export function getInitialTheme() {
|
|
return getStoredTheme() || getSystemTheme();
|
|
}
|
|
|
|
export function applyTheme(theme) {
|
|
const root = document.documentElement;
|
|
|
|
root.classList.remove(LIGHT, DARK);
|
|
|
|
root.classList.add(theme);
|
|
|
|
localStorage.setItem("theme", theme);
|
|
}
|
|
|
|
export function toggleTheme(current) {
|
|
return current === DARK ? LIGHT : DARK;
|
|
}
|