Theme Switch
A flexible and accessible theme mode switcher component
Installation
npx shadcn@latest add https://scrollx-ui.vercel.app/registry/theme-switch.json
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
Show Only Next
Three Mode Show Only Next
Three Mode with any Icon Click
Single Centred with Two modes
Single Centred wit Three modes
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
modes
array. - Icons are displayed according to
showActiveIconOnly
andshowInactiveIcons
props. - 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"
/>