aboutsummaryrefslogtreecommitdiff
path: root/src/stores/useThemeStore.ts
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-06-05 20:52:54 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-06-05 20:52:54 +0000
commit09f964451d7d92e9891430ec4595c1276d486aab (patch)
tree28da4483f5c28924a8c47fceb648b1baebe88224 /src/stores/useThemeStore.ts
downloadyace-master.tar.gz
yace-master.zip
feat: uploadHEADmaster
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'src/stores/useThemeStore.ts')
-rw-r--r--src/stores/useThemeStore.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/stores/useThemeStore.ts b/src/stores/useThemeStore.ts
new file mode 100644
index 0000000..d9c3d06
--- /dev/null
+++ b/src/stores/useThemeStore.ts
@@ -0,0 +1,41 @@
+import { create } from 'zustand'
+
+export type Theme = 'dark' | 'light'
+
+interface ThemeState {
+ theme: Theme
+ setTheme: (theme: Theme) => void
+ toggleTheme: () => void
+}
+
+function getInitialTheme(): Theme {
+ const stored = localStorage.getItem('yace_theme')
+ if (stored === 'light' || stored === 'dark') return stored
+ return 'dark'
+}
+
+function applyTheme(theme: Theme) {
+ document.documentElement.setAttribute('data-theme', theme)
+}
+
+const initial = getInitialTheme()
+applyTheme(initial)
+
+export const useThemeStore = create<ThemeState>((set) => ({
+ theme: initial,
+
+ setTheme: (theme: Theme) => {
+ applyTheme(theme)
+ localStorage.setItem('yace_theme', theme)
+ set({ theme })
+ },
+
+ toggleTheme: () => {
+ set((state) => {
+ const next = state.theme === 'dark' ? 'light' : 'dark'
+ applyTheme(next)
+ localStorage.setItem('yace_theme', next)
+ return { theme: next }
+ })
+ },
+}))