adds dark mode
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import { browser } from "$app/environment";
|
||||
import { get, writable, type Writable } from "svelte/store";
|
||||
|
||||
type Theme = "dark" | "light"
|
||||
|
||||
export const theme: Writable<Theme> = writable("light");
|
||||
|
||||
export const theme: Writable<Theme> = writable(browser && localStorage.getItem("theme") as Theme || "light" );
|
||||
|
||||
export function toggleTheme() {
|
||||
if (get(theme) === "light") {
|
||||
theme.set("dark")
|
||||
} else {
|
||||
theme.set("light");
|
||||
}
|
||||
const newTheme = get(theme) === "light" ? "dark" : "light";
|
||||
theme.set(newTheme)
|
||||
localStorage.setItem("theme", newTheme);
|
||||
}
|
||||
Reference in New Issue
Block a user