From afdc982863b6cca573f1db58e1795aa8c45fabca Mon Sep 17 00:00:00 2001
From: schererleander <leander@schererleander.de>
Date: Fri, 30 May 2025 01:01:17 +0200
Subject: rewrite site

---
 src/hooks/theme.tsx | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
 create mode 100644 src/hooks/theme.tsx

(limited to 'src/hooks/theme.tsx')

diff --git a/src/hooks/theme.tsx b/src/hooks/theme.tsx
new file mode 100644
index 0000000..d65b18c
--- /dev/null
+++ b/src/hooks/theme.tsx
@@ -0,0 +1,33 @@
+// hooks/theme.ts
+import { useState, useEffect, useCallback } from 'react';
+
+type Theme = 'light' | 'dark';
+
+const STORAGE_KEY = 'theme';
+
+export function useTheme() {
+  const [theme, setTheme] = useState<Theme>(() => {
+    const stored = typeof window !== 'undefined' ? localStorage.getItem(STORAGE_KEY) : null;
+    if (stored === 'light' || stored === 'dark') {
+      return stored;
+    }
+    
+    if (typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches) {
+      return 'dark';
+    }
+    return 'light';
+  });
+
+  useEffect(() => {
+    const root = document.documentElement;
+    root.setAttribute('data-theme', theme);
+    root.classList.toggle('dark', theme === 'dark');
+    localStorage.setItem(STORAGE_KEY, theme);
+  }, [theme]);
+
+  const toggleTheme = useCallback(() => {
+    setTheme(prev => (prev === 'dark' ? 'light' : 'dark'));
+  }, []);
+
+  return { theme, toggleTheme };
+}
-- 
cgit v1.3.1

