mirror of
https://git.aramjonghu.nl/AramJonghu/aramjonghu-site.git
synced 2026-06-07 01:28:24 +02:00
Dark/light mode added + switcher
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user