Overview
Pengrafic uses next-themes for seamless dark mode support. The theme system is configured at the application level and supports both light and dark color schemes.Theme Configuration
The theme system is initialized in theThemeProvider component, which wraps your entire application.
Provider Setup
The theme provider is configured insrc/app/providers.tsx:
src/app/providers.tsx
Provider Options
| Option | Value | Description |
|---|---|---|
attribute | "class" | Uses class-based theme switching (adds dark class to <html>) |
enableSystem | false | Disables automatic system preference detection |
defaultTheme | "dark" | Sets dark mode as the default theme |
The theme provider must be a client component (
"use client") because it uses React context and browser APIs.Tailwind Configuration
Dark mode is configured intailwind.config.js using the class strategy:
tailwind.config.js
Customizing Theme Behavior
Change Default Theme
To set light mode as default, update thedefaultTheme prop:
Enable System Preference
To respect user’s system dark mode preference:src/app/providers.tsx
Theme Toggle Component
Implement a theme switcher using theuseTheme hook:
components/ThemeToggle.tsx
Preventing Flash of Unstyled Content
The template includessuppressHydrationWarning on the <html> element to prevent warnings during theme initialization:
src/app/layout.tsx
This is necessary because next-themes modifies the HTML element before React hydration completes.
Best Practices
- Always use dark mode variants: When styling components, always provide both light and dark mode styles
- Test both themes: Ensure your UI looks good in both light and dark modes
- Use semantic colors: Prefer using the defined color tokens like
body-colorinstead of hardcoded values - Client components only: The
useThemehook only works in client components
Related
- Colors - Learn about the color system
- Typography - Configure fonts and text styles