Import source: src/context/ThemeContext

Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
arsam
2026-09-18 23:17:42 +03:30
parent 4bd8b926e4
commit 6994f509a5
+21
View File
@@ -0,0 +1,21 @@
import { createContext, useContext, useState, useEffect, type ReactNode } from 'react';
interface ThemeCtx { isDark: boolean; toggle: () => void; }
const ThemeContext = createContext<ThemeCtx>({ isDark: true, toggle: () => {} });
export function ThemeProvider({ children }: { children: ReactNode }) {
const [isDark, setIsDark] = useState(false);
useEffect(() => {
document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
}, [isDark]);
return (
<ThemeContext.Provider value={{ isDark, toggle: () => setIsDark(d => !d) }}>
{children}
</ThemeContext.Provider>
);
}
export const useTheme = () => useContext(ThemeContext);