feat: implement navigation and dark/light theme system

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>
This commit is contained in:
valknarness
2025-11-07 11:35:05 +01:00
parent 94ea87ca83
commit 75bfecee4d
5 changed files with 195 additions and 5 deletions

View File

@@ -2,6 +2,7 @@ import type { Metadata } from 'next';
import { Inter } from 'next/font/google';
import './globals.css';
import { Providers } from '@/components/providers/Providers';
import { Navbar } from '@/components/layout/Navbar';
const inter = Inter({ subsets: ['latin'] });
@@ -19,7 +20,10 @@ export default function RootLayout({
return (
<html lang="en" suppressHydrationWarning>
<body className={inter.className}>
<Providers>{children}</Providers>
<Providers>
<Navbar />
{children}
</Providers>
</body>
</html>
);

View File

@@ -0,0 +1,77 @@
'use client';
import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { ThemeToggle } from './ThemeToggle';
import { cn } from '@/lib/utils/cn';
import { Palette } from 'lucide-react';
const navigation = [
{ name: 'Home', href: '/' },
{ name: 'Playground', href: '/playground' },
{ name: 'Palettes', href: '/palettes' },
{ name: 'Accessibility', href: '/accessibility' },
{ name: 'Named Colors', href: '/names' },
{ name: 'Batch', href: '/batch' },
];
export function Navbar() {
const pathname = usePathname();
return (
<nav className="sticky top-0 z-50 w-full border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
<div className="container mx-auto px-4">
<div className="flex h-16 items-center justify-between">
{/* Logo */}
<Link href="/" className="flex items-center space-x-2 font-bold text-xl">
<Palette className="h-6 w-6 text-primary" />
<span className="bg-gradient-to-r from-pink-500 via-purple-500 to-blue-500 bg-clip-text text-transparent">
Pastel UI
</span>
</Link>
{/* Desktop Navigation */}
<div className="hidden md:flex items-center space-x-1">
{navigation.map((item) => (
<Link
key={item.href}
href={item.href}
className={cn(
'px-3 py-2 rounded-md text-sm font-medium transition-colors',
pathname === item.href
? 'bg-accent text-accent-foreground'
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
)}
>
{item.name}
</Link>
))}
</div>
{/* Right side */}
<div className="flex items-center space-x-2">
<ThemeToggle />
</div>
</div>
{/* Mobile Navigation */}
<div className="md:hidden pb-3 space-y-1">
{navigation.map((item) => (
<Link
key={item.href}
href={item.href}
className={cn(
'block px-3 py-2 rounded-md text-sm font-medium transition-colors',
pathname === item.href
? 'bg-accent text-accent-foreground'
: 'text-muted-foreground hover:bg-accent hover:text-accent-foreground'
)}
>
{item.name}
</Link>
))}
</div>
</div>
</nav>
);
}

View File

@@ -0,0 +1,28 @@
'use client';
import { Moon, Sun } from 'lucide-react';
import { useTheme } from '@/components/providers/ThemeProvider';
import { Button } from '@/components/ui/button';
export function ThemeToggle() {
const { theme, setTheme, resolvedTheme } = useTheme();
const toggleTheme = () => {
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark');
};
return (
<Button
variant="ghost"
size="icon"
onClick={toggleTheme}
aria-label={`Switch to ${resolvedTheme === 'dark' ? 'light' : 'dark'} mode`}
>
{resolvedTheme === 'dark' ? (
<Sun className="h-5 w-5" />
) : (
<Moon className="h-5 w-5" />
)}
</Button>
);
}

View File

@@ -3,6 +3,7 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { Toaster } from 'sonner';
import { useState } from 'react';
import { ThemeProvider } from './ThemeProvider';
export function Providers({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(
@@ -18,9 +19,11 @@ export function Providers({ children }: { children: React.ReactNode }) {
);
return (
<ThemeProvider>
<QueryClientProvider client={queryClient}>
{children}
<Toaster position="top-right" richColors />
</QueryClientProvider>
</ThemeProvider>
);
}

View File

@@ -0,0 +1,78 @@
'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;
}