ThemeCustomizer component is the primary interface for customizing themes in Theme Gen. It provides interactive color buttons, lock functionality, contrast checking, and smart color generation features.
Features
- Interactive color selection for key theme properties
- Lock/unlock individual colors to preserve them during generation
- Real-time contrast ratio checking and accessibility validation
- Smart shuffle that generates accessible color palettes
- Light/dark mode toggling with adaptive color adjustment
- Undo/redo functionality
- Export themes to various formats
- Save and load custom themes
- Responsive layout that adapts to viewport size
Usage
Component Structure
The ThemeCustomizer is a complex component with no props. It internally manages:Color Buttons
The component displays 5 primary color buttons:- Text - Main text color (7:1 contrast target with Background)
- Background - Main background color
- Primary - Primary brand color (3:1 contrast target with Background)
- Container - Container/card background (4.5:1 contrast target with Text)
- Accent - Accent/highlight color (3:1 contrast target with Container)
- The current color value
- A contrast check indicator (pass/warn/fail badge)
- A lock/unlock button for preserving the color
- The color name label
State Management
The component uses theuseTheme hook from ThemeContext to access and update the global theme state.
Internal state includes:
src/components/ThemeCustomizer.tsx:186-190
Automatic Color Derivation
When you change certain colors, related colors update automatically:- Border - Derived from Text and Background (82% mix)
- Muted - Derived from Text and Background (55% mix)
- onPrimary - Automatic contrast color for Primary
- onContainer - Automatic contrast color for Container
- onAccent - Automatic contrast color for Accent
- onSuccess - Automatic contrast color for Success
- onError - Automatic contrast color for Error
- onWarning - Automatic contrast color for Warning
src/components/ThemeCustomizer.tsx:230-252
Smart Shuffle Algorithm
The smart shuffle feature generates new color palettes while:- Preserving all locked colors
- Using the selected harmony mode (complementary, triadic, analogous, etc.)
- Attempting up to 24 iterations to find an accessible palette
- Validating contrast ratios against WCAG targets
src/components/ThemeCustomizer.tsx:267-307
Contrast Validation
The component validates these contrast pairs:| Pair | Target Ratio | Required |
|---|---|---|
| Text on Background | 7:1 | Yes |
| Primary on Background | 3:1 | Yes |
| Text on Container | 4.5:1 | Yes |
| Accent on Container | 3:1 | Yes |
| Accent on Background | 3:1 | Yes |
src/components/ThemeCustomizer.tsx:117-158
Responsive Behavior
The toolbar automatically switches between horizontal and compact (vertical) layouts based on viewport width:- Horizontal mode - Fixed position at bottom-center, all buttons in a row
- Compact mode - Fixed position at bottom, spans full width, buttons stacked
ResizeObserver to measure toolbar width and switches modes when needed.
Source: src/components/ThemeCustomizer.tsx:336-365
Keyboard and Mouse Interactions
- Click color button - Opens color picker popover
- Click lock button - Toggles color lock state
- Click outside - Closes color picker popover
- Smart Shuffle button - Generates new accessible palette
- Theme toggle button - Switches between light/dark mode
- Export button - Opens export modal
- Saved themes button - Opens saved themes panel
- Undo/Redo buttons - Navigate theme history
Related Components
The ThemeCustomizer uses these child components:- ColorPickerPopover - Color selection interface
- ExportModal - Theme export dialog
- SavedThemesPanel - Saved themes browser
- ToolbarButtons - Action buttons in the toolbar
- ColorButton - Individual color selection button (internal)
Internal Types
ColorButtonData
src/components/theme-customizer-types.ts:53-61
ColorButtonProps
src/components/ThemeCustomizer.tsx:26-38
Theme Context Integration
The component relies on theThemeContext provider and uses these context methods:
theme- Current theme objectupdateThemeProperty- Update a single theme propertythemeName- Current theme mode (‘light’ or ‘dark’)setTheme- Set entire theme at onceundo/redo- History navigationcanUndo/canRedo- History statepushHistory- Save current state to historysavedThemes- Array of saved custom themes
src/components/ThemeCustomizer.tsx:181