- CSS custom properties design system with full light/dark themes - ThemeContext with localStorage persistence and system preference detection - Theme toggle button in nav (moon/sun icon) - Modern Inter font, card-based layout, sticky nav - All pages restyled with CSS classes instead of inline styles Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
31 lines
825 B
JavaScript
31 lines
825 B
JavaScript
import { createContext, useContext, useEffect, useState } from 'react';
|
|
|
|
const ThemeContext = createContext(null);
|
|
|
|
export function ThemeProvider({ children }) {
|
|
const [theme, setTheme] = useState(() => {
|
|
const stored = localStorage.getItem('theme');
|
|
if (stored === 'light' || stored === 'dark') return stored;
|
|
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
});
|
|
|
|
useEffect(() => {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
localStorage.setItem('theme', theme);
|
|
}, [theme]);
|
|
|
|
function toggle() {
|
|
setTheme(t => (t === 'dark' ? 'light' : 'dark'));
|
|
}
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, toggle }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useTheme() {
|
|
return useContext(ThemeContext);
|
|
}
|