Dark mode has been successfully implemented for the Phoenix Precision Agency website using next-themes package with system preference detection and local storage persistence.
next-themes@0.4.6- Theme management with SSR support@radix-ui/react-dropdown-menu- For the theme toggle dropdown UI
- Wraps the entire application in
app/layout.tsx - Configured with:
attribute="class"- Adds theme class to HTML elementdefaultTheme="system"- Respects browser preferencesenableSystem- Enables system preference detectiondisableTransitionOnChange- Prevents flash during theme switch
- Simple theme switcher with dropdown menu
- Options: Light, Dark, System
- Added to Navigation component (desktop and mobile views)
- Uses localStorage for persistence
- Enhanced version that syncs with API (optional)
- Useful for authenticated users to sync preferences across devices
- Falls back gracefully if API is unavailable
GET /api/user/preferences- Fetches user theme preferencePATCH /api/user/preferences- Updates user theme preference- Works with Clerk authentication and Upstash Redis
Dark mode styles are already defined in app/globals.css:
.darkclass with complete color palette- Smooth transitions between themes
- Consistent aerospace-inspired color scheme
- Updated
app/layout.tsxwithsuppressHydrationWarningon html tag - Added ThemeToggle to Navigation component
- All existing components automatically support dark mode through CSS variables
- Click the theme toggle button in the navigation
- Select Light, Dark, or System preference
- Theme persists across sessions via localStorage
// Use theme in components
import { useTheme } from 'next-themes'
function MyComponent() {
const { theme, setTheme } = useTheme()
// theme: 'light' | 'dark' | 'system'
}Visit /theme-demo to see all color variations and components in both light and dark modes.
- Test all existing components in dark mode
- Ensure proper contrast ratios for accessibility
- Add theme-aware images/graphics if needed
- Consider adding transition animations between themes