Add complete navigation and theming infrastructure:
**Theme System:**
- ThemeProvider component with React Context
- Supports light, dark, and system themes
- Persists preference to localStorage
- Auto-detects system theme preference
- Listens for system theme changes
- Smooth theme transitions
- ThemeToggle component
- Sun/Moon icon toggle button
- Accessible with ARIA labels
- Shows current theme state
- Keyboard accessible
**Navigation:**
- Navbar component with sticky header
- Gradient logo with Palette icon
- Desktop horizontal navigation
- Mobile responsive menu
- Active route highlighting
- Backdrop blur effect
- Links to all main sections:
- Home
- Playground
- Palettes
- Accessibility
- Named Colors
- Batch Operations
**Layout Updates:**
- Integrated Navbar into root layout
- Added ThemeProvider to Providers wrapper
- Proper HTML suppressHydrationWarning for theme
- Container-based responsive layout
**Features:**
- Theme persists across page reloads
- System theme preference detection
- Active navigation state
- Smooth hover transitions
- Mobile-first responsive design
- Accessible navigation with proper semantics
**Styling:**
- Gradient text logo (pink → purple → blue)
- Sticky top navbar with backdrop blur
- Border bottom for visual separation
- Consistent spacing and padding
- Mobile menu slides in smoothly
Build successful! Navigation and theming complete.
Next: Palette generation pages and additional features.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
79 lines
2.2 KiB
TypeScript
79 lines
2.2 KiB
TypeScript
'use client';
|
|
|
|
import { createContext, useContext, useEffect, useState } from 'react';
|
|
|
|
type Theme = 'light' | 'dark' | 'system';
|
|
|
|
interface ThemeContextType {
|
|
theme: Theme;
|
|
setTheme: (theme: Theme) => void;
|
|
resolvedTheme: 'light' | 'dark';
|
|
}
|
|
|
|
const ThemeContext = createContext<ThemeContextType | undefined>(undefined);
|
|
|
|
export function ThemeProvider({ children }: { children: React.ReactNode }) {
|
|
const [theme, setTheme] = useState<Theme>('system');
|
|
const [resolvedTheme, setResolvedTheme] = useState<'light' | 'dark'>('light');
|
|
|
|
useEffect(() => {
|
|
// Load theme from localStorage
|
|
const stored = localStorage.getItem('theme') as Theme | null;
|
|
if (stored) {
|
|
setTheme(stored);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
const root = window.document.documentElement;
|
|
|
|
// Remove previous theme classes
|
|
root.classList.remove('light', 'dark');
|
|
|
|
if (theme === 'system') {
|
|
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
|
? 'dark'
|
|
: 'light';
|
|
root.classList.add(systemTheme);
|
|
setResolvedTheme(systemTheme);
|
|
} else {
|
|
root.classList.add(theme);
|
|
setResolvedTheme(theme);
|
|
}
|
|
|
|
// Save to localStorage
|
|
localStorage.setItem('theme', theme);
|
|
}, [theme]);
|
|
|
|
// Listen for system theme changes
|
|
useEffect(() => {
|
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
const handleChange = () => {
|
|
if (theme === 'system') {
|
|
const systemTheme = mediaQuery.matches ? 'dark' : 'light';
|
|
setResolvedTheme(systemTheme);
|
|
window.document.documentElement.classList.remove('light', 'dark');
|
|
window.document.documentElement.classList.add(systemTheme);
|
|
}
|
|
};
|
|
|
|
mediaQuery.addEventListener('change', handleChange);
|
|
return () => mediaQuery.removeEventListener('change', handleChange);
|
|
}, [theme]);
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, setTheme, resolvedTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useTheme() {
|
|
const context = useContext(ThemeContext);
|
|
if (context === undefined) {
|
|
throw new Error('useTheme must be used within a ThemeProvider');
|
|
}
|
|
return context;
|
|
}
|