mirror of
https://github.com/NotXia/notxia.github.io.git
synced 2025-12-15 19:22:21 +01:00
Migration to Nuxt3
This commit is contained in:
22
utils/theme_handler.ts
Normal file
22
utils/theme_handler.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export function getTheme() : string {
|
||||
return localStorage.getItem("theme") ?? "dark";
|
||||
}
|
||||
|
||||
export function setTheme(theme:string) : void {
|
||||
if (theme !== "dark" && theme !== "light") { theme = "dark"; }
|
||||
localStorage.setItem("theme", theme);
|
||||
}
|
||||
|
||||
export function flipTheme() : void {
|
||||
setTheme(getTheme() === "dark" ? "light" : "dark");
|
||||
}
|
||||
|
||||
export function applyTheme(theme?:string) : void {
|
||||
if (!theme) { theme = getTheme(); }
|
||||
|
||||
switch (theme) {
|
||||
case "dark": document.documentElement.classList.add("dark"); break;
|
||||
case "light": document.documentElement.classList.remove("dark"); break;
|
||||
default: document.documentElement.classList.add("dark"); break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user