From dab9bc97509c58bed307b6ebfaa8f3ca4f038ce2 Mon Sep 17 00:00:00 2001 From: wonder Date: Sun, 24 May 2026 21:08:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(theme):=20Zustand=20=E4=B8=BB=E9=A2=98=20s?= =?UTF-8?q?tore=EF=BC=8ClocalStorage=20=E6=8C=81=E4=B9=85=E5=8C=96?= =?UTF-8?q?=EF=BC=8C=E9=BB=98=E8=AE=A4=E6=B5=85=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/stores/theme.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 frontend/src/stores/theme.ts diff --git a/frontend/src/stores/theme.ts b/frontend/src/stores/theme.ts new file mode 100644 index 0000000..ed54a79 --- /dev/null +++ b/frontend/src/stores/theme.ts @@ -0,0 +1,22 @@ +import { create } from 'zustand' +import { persist } from 'zustand/middleware' + +type Theme = 'light' | 'dark' + +interface ThemeState { + theme: Theme + toggleTheme: () => void + setTheme: (t: Theme) => void +} + +export const useThemeStore = create()( + persist( + (set) => ({ + theme: 'light', + toggleTheme: () => + set((state) => ({ theme: state.theme === 'light' ? 'dark' : 'light' })), + setTheme: (t) => set({ theme: t }), + }), + { name: 'gen2d_theme' }, + ), +)