Overview
Spectrum Switcher is a sophisticated dropdown component for selecting between different color palettes or themes. It features smooth animations, collapsible dropdown transitions, and visually appealing gradient previews that morph between states.Key features
- Animated dropdown with smooth expand/collapse transitions
- Color spectrum previews with gradient backgrounds
- Shared layout animations for spectrum boxes
- Blur and fade effects during state transitions
- Customizable spectrum definitions
- Dark mode support with separate gradient colors
When to use it
- Theme or color palette selection interfaces
- Style customization panels
- Design system showcases
- Any UI requiring elegant option selection with visual previews
Installation
Usage
Basic example
Custom spectrums
Props
Array of spectrum definitions. Each spectrum object must include:
id(string): Unique identifier for the spectrumname(string): Display name shown in the dropdowndescription(string): Subtitle text describing the palettecolor(string): Tailwind gradient classes for light modedarkColor(string): Tailwind gradient classes for dark modelayoutId(string): Unique Motion layout ID for animations
Types
Spectrum
SpectrumSwitcherProps
Examples
Default spectrums
The component ships with two built-in spectrum options:- Sunset Glow: Warm and bold ambience (rose, orange, yellow)
- Lavender Mist: Soft and dreamy palette (purple, pink, fuchsia)
Multiple custom palettes
Customization
Animation variants
The component uses custom Motion variants for different animations:Item variant (text content)
Divider variant
Layout animation
Spectrum boxes use shared layout animations with spring physics:Styling
Key styling areas you can customize:- Container: Modify border and padding at
components/forgeui/spectrum-switcher.tsx:88-93 - Header section: Adjust background gradients and rings at
components/forgeui/spectrum-switcher.tsx:94-100 - Icon container: Change shadow and ring effects at
components/forgeui/spectrum-switcher.tsx:106-113 - Dropdown items: Update hover states at
components/forgeui/spectrum-switcher.tsx:211
Icon customization
The component uses
GiFairyWand from react-icons/gi and MdKeyboardArrowDown from react-icons/md. You can replace these with your own icons by modifying the imports and JSX.Component details
State management
The component manages two internal states:isOpen: Controls dropdown visibilityselectedSpectrum: Tracks currently selected palette
Dropdown behavior
When closed, spectrum previews appear as small color boxes next to the toggle button. When opened, they expand into full-width selectable options with descriptions.Layout IDs
AnimatePresence modes
The component usesmode="wait" for the selected spectrum text to ensure smooth transitions between different selections without overlapping content.