aboutsummaryrefslogtreecommitdiff
path: root/web/src/hooks/useTheme.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/hooks/useTheme.ts')
-rw-r--r--web/src/hooks/useTheme.ts21
1 files changed, 21 insertions, 0 deletions
diff --git a/web/src/hooks/useTheme.ts b/web/src/hooks/useTheme.ts
new file mode 100644
index 0000000..a5457b6
--- /dev/null
+++ b/web/src/hooks/useTheme.ts
@@ -0,0 +1,21 @@
+import { useState, useEffect } from 'react';
+import { Theme } from '../types';
+
+export const useTheme = () => {
+ const [theme, setTheme] = useState<Theme>(() => {
+ const savedTheme = localStorage.getItem('theme');
+ return (savedTheme as Theme) || Theme.Light;
+ });
+
+ useEffect(() => {
+ localStorage.setItem('theme', theme);
+ document.documentElement.classList.remove(Theme.Light, Theme.Dark);
+ document.documentElement.classList.add(theme);
+ }, [theme]);
+
+ const toggleTheme = () => {
+ setTheme(prev => prev === Theme.Light ? Theme.Dark : Theme.Light);
+ };
+
+ return { theme, toggleTheme };
+}; \ No newline at end of file