Theme Switch
A flexible and accessible theme mode switcher component
Loading...
Installation
npx shadcn@latest add @scrollxui/theme-switch Usage
import { ThemeSwitch } from '@/components/ui/theme-switch';
import { Sun, Moon, Laptop } from 'lucide-react';<ThemeSwitch
modes={['light', 'dark', 'system']}
icons={[
<Sun key='sun-icon' size={16} />,
<Moon key='moon-icon' size={16} />,
<Laptop key='laptop-icon' size={16} />,
]}
showInactiveIcons='all'
/>Examples
Hide Inactive
Loading...
Show Only Next
Loading...
Three Mode Show Only Next
Loading...
Three Mode with any Icon Click
Loading...
Single Centred with Two modes
Loading...
Single Centred wit Three modes
Loading...
API Reference
ThemeSwitch
A flexible and accessible theme mode switcher component for Next.js projects using next-themes. Supports multiple modes (e.g., light, dark, system), custom icons, and various display options.
Props
Behavior
- Clicking the switch cycles to the next mode in the
modesarray. - Icons are displayed according to
showActiveIconOnlyandshowInactiveIconsprops. - Animated indicator highlights the current mode.
- Accessible: Uses button-like semantics and focus styles.
Changelog
2025-06-02 ThemeSwitch - icon-click Variant
Added a new variant="icon-click" prop to the ThemeSwitch component that
allows users to directly select a theme by clicking on its corresponding icon.
This provides a more intuitive UX compared to the default sequential toggle.
Use this variant when you want users to set the theme directly instead of cycling through options.
Add the variant prop as shown below:
ThemeSwitch.tsx
<ThemeSwitch
variant='icon-click'
modes={['light', 'dark', 'system']}
icons={[
<Sun key='sun-icon' size={16} />,
<Moon key='moon-icon' size={16} />,
<Laptop key='laptop-icon' size={16} />,
]}
showInactiveIcons='all'
/>