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" />
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
Alpine.js Integration
$theme for theme management:
Current theme:
Resolved theme:
<div x-data>
<p x-text="'Current: ' + $theme.get().stored"></p>
<button x-on:click="$theme.setLight()">Set Light</button>
<button x-on:click="$theme.setDark()">Set Dark</button>
<button x-on:click="$theme.toggle()">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
- Provide visual feedback when theme changes
- 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', or 'inline' |
| 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' |