Theme

Theme

Utilities
Foundation

Theme provider and utilities for managing color schemes, presets, and appearance settings across the application.

Preview

Theme preset selector

Current preset: default

Dark Mode

System and manual dark mode support

Dark mode is controlled via the dark class on the document element.

Theme Presets

Available color presets

Default

Indigo primary with teal secondary. Professional and modern.

Aurora

Violet primary with fuchsia secondary. Vibrant and creative.

Earth

Mocha primary with sage secondary. Natural and warm.

Midnight

Slate primary with cyan secondary. Cool and sophisticated.

ThemeContext API

Hook and provider API

PropTypeDefaultDescription
currentPresetThemePresetId—Currently active theme preset
setPreset(preset: ThemePresetId) => void—Change the active preset
isDarkModeboolean—Whether dark mode is active
toggleDarkMode() => void—Toggle dark mode on/off

Usage

Import and implementation examples

import { useTheme } from '@/contexts/ThemeContext'
function ThemeToggle() {
const { currentPreset, setPreset, isDarkMode, toggleDarkMode } = useTheme()
return (
<div>
{/* Dark mode toggle */}
<button aria-label={isDarkMode ? 'Switch to light mode' : 'Switch to dark mode'} onClick={toggleDarkMode}>
{isDarkMode ? <Sun /> : <Moon />}
</button>
{/* Preset selector */}
<select
value={currentPreset}
onChange={(e) => setPreset(e.target.value)}
>
<option value="default">Default</option>
<option value="aurora">Aurora</option>
<option value="earth">Earth</option>
<option value="midnight">Midnight</option>
</select>
</div>
)
}
// Theme provider wrapping the app
// (Already configured in layout.tsx)
import { ThemeProvider } from '@/contexts/ThemeContext'
function App() {
return (
<ThemeProvider>
<YourApp />
</ThemeProvider>
)
}

CSS Variables

Theme variables applied to :root

/* Theme presets apply CSS custom properties */
:root {
/* Primary colors */
--color-primary-50: ...;
--color-primary-500: ...;
--color-primary-600: ...;
/* Secondary colors */
--color-secondary-50: ...;
--color-secondary-500: ...;
/* Semantic colors */
--color-success: ...;
--color-warning: ...;
--color-error: ...;
}
/* Dark mode overrides */
.dark {
--color-background: ...;
--color-foreground: ...;
}

Features

Built-in functionality

  • Multiple presets: Four built-in color schemes
  • System preference: Respects prefers-color-scheme
  • Persistence: Theme saved to localStorage
  • CSS variables: Customizable via CSS custom properties
  • SSR safe: No hydration mismatch
  • React context: Easy access via useTheme hook

Accessibility

Accessibility considerations

ARIA Attributes

Theme changes do not affect focus or reading orderAll color combinations maintain WCAG contrast ratiosDark mode reduces eye strain in low-light conditions

Keyboard Navigation

KeyAction
User preferenceRespects system-level settings

Notes

  • All presets are designed with accessibility in mind
  • Color is never the only indicator of meaning
  • Test your application in both light and dark modes

Related Components