Basic Usage
Positioned
Demo Example
Fromdemo/demo/demo.py:56:
In Navigation Bar
In Settings Page
Props Reference
CSS classes for positioning and additional styling
Color Modes
The theme switcher provides three modes:- System: Matches the user’s operating system preference
- Light: Forces light color mode
- Dark: Forces dark color mode
Visual States
Each button has distinct states:- Active: Shows with background highlight and shadow
- Inactive: Muted color that brightens on hover
- Hover: Secondary color on inactive buttons
Styling
From source code atreflex_ui/components/base/theme_switcher.py:12-37:
- Container: Horizontal flex layout with secondary background
- Buttons: Small squares (1.5rem) with rounded corners
- Active button: White/secondary background with small shadow
- Inactive buttons: Muted color with hover effect
- Icons: Consistent 14px size
- Spacing: Small padding between buttons
Accessibility
- Each button has an
aria-labeldescribing its function - Keyboard accessible with Tab and Enter/Space
- Visual focus indicators
- Clear active state indication
Icons
From source code atreflex_ui/components/base/theme_switcher.py:12-24:
- System: Computer icon
- Light: Sun icon
- Dark: Moon icon
Implementation Details
From source code atreflex_ui/components/base/theme_switcher.py:27-43:
- Uses Reflex’s built-in
color_modeandset_color_modeutilities - Conditionally renders active state based on current mode
- Memoized for optimal performance
- Each button triggers
set_color_modewith the corresponding mode - Smooth color transitions between states