mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: add theme system with dark/light/system support and persistence
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { useEffect } from "react";
|
||||
import { useThemeStore } from "../stores/theme-store";
|
||||
|
||||
export function useTheme() {
|
||||
const { theme, resolvedTheme, setTheme } = useThemeStore();
|
||||
|
||||
useEffect(() => {
|
||||
const resolved =
|
||||
theme === "system"
|
||||
? window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: "light"
|
||||
: theme;
|
||||
document.documentElement.classList.toggle("dark", resolved === "dark");
|
||||
}, [theme]);
|
||||
|
||||
const toggleTheme = () => {
|
||||
setTheme(resolvedTheme === "dark" ? "light" : "dark");
|
||||
};
|
||||
|
||||
return { theme, resolvedTheme, setTheme, toggleTheme };
|
||||
}
|
||||
Reference in New Issue
Block a user