Theme Switcher
Basic Usage
<neura::theme-switcher />
Variants
Dropdown (Default)
<neura::theme-switcher variant="dropdown" />
Stacked
<neura::theme-switcher variant="stacked" />
Inline
<neura::theme-switcher variant="inline" />
PullCord
<neura::theme-switcher variant="pullcord" />
Custom Icons
<neura::theme-switcher
variant="dropdown"
lightIcon="sun"
darkIcon="moon"
systemIcon="computer-desktop"
/>
Icon Variant
iconVariant
prop:
Mini
Micro
Outline
Solid
<neura::theme-switcher iconVariant="mini" />
<neura::theme-switcher iconVariant="micro" />
<neura::theme-switcher iconVariant="outline" />
<neura::theme-switcher iconVariant="solid" />
Theme Modes
Light Mode
Forces light theme regardless of system preferences.
Dark Mode
Forces dark theme regardless of system preferences.
System Mode
Follows the system's color scheme preference. Automatically switches between light and dark based on the user's OS settings.
Persistence
localStorage
and persists across page reloads:
Your theme preference is saved automatically. Refresh the page to see it persist.
Use Cases
Navigation Bar
Settings Panel
Appearance
Compact Header
Switch Animation
View Transition API
for a smooth reveal (circle expand by default). Pass animation
to pick an effect — unsupported browsers and prefers-reduced-motion
fall back to an instant switch.
<neura::theme-switcher variant="inline" animation="circle" />
<neura::theme-switcher variant="inline" animation="blur-circle" />
<neura::theme-switcher variant="inline" animation="qr-scan" />
<neura::theme-switcher variant="inline" animation="polygon" />
<neura::theme-switcher variant="inline" animation="polygon-gradient" />
<neura::theme-switcher variant="inline" animation="none" />
<div x-data x-init="$theme.configure({ animationType: 'blur-circle', duration: 900 })">
<button type="button" x-on:click="$theme.toggle($event)">Toggle</button>
</div>
Alpine.js Integration
$theme
for theme management.
Pass $event
so the animation originates from the clicked control:
Stored: · Resolved:
<div x-data>
<p>Stored: <span x-text="$theme.stored"></span></p>
<button x-on:click="$theme.setLight($event)">Set Light</button>
<button x-on:click="$theme.setDark($event)">Set Dark</button>
<button x-on:click="$theme.toggle($event)">Toggle</button>
</div>
Best Practices
Do
- Place the theme switcher in an easily accessible location (header/navbar)
- Use the dropdown variant for better UX with system mode option
- Use the inline variant for minimal UI where space is limited
- Pass
$eventto theme methods so the reveal expands from the control - Respect user preferences stored in localStorage
Don't
- Hide the theme switcher in hard-to-find locations
- Force a specific theme without user control
- Forget to handle system theme changes
- Use too many different theme switcher variants on the same page
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| variant | string | 'dropdown' | Theme switcher style: 'dropdown', 'stacked', 'inline', or 'pullcord' |
| animation | string | 'circle' | View Transition effect: circle, blur-circle, qr-scan, polygon, polygon-gradient, gif, or none |
| lightIcon | string | 'sun' | Icon name for light theme |
| darkIcon | string | 'moon' | Icon name for dark theme |
| systemIcon | string | 'computer-desktop' | Icon name for system theme |
| iconVariant | string | 'mini' | Icon size variant: 'mini', 'micro', 'outline', or 'solid' |