Components / Interface
Theme Toggle
One button that cycles system, light and dark, fading the page between themes where the browser supports view transitions.
Click to cycle system, light and dark
Installation
npx shadcn@latest add https://jiaweing.com/r/theme-toggle.jsonWith the @jiaweing namespace set up, use @jiaweing/theme-toggle in place of the URL.
Usage
tsx
import { ThemeToggle } from "@/components/theme-toggle";tsx
<ThemeToggle />- Needs next-themes. Wrap your app in <ThemeProvider attribute="class" defaultTheme="system" enableSystem>.
Props
ThemeToggle
| Prop | Type | Default | Description |
|---|---|---|---|
| labels | { system?, light?, dark? } | - | Theme names for screen readers. |
| viewTransition | boolean | true | Fade between themes where the browser supports it. |
| onThemeChange | (theme: "system" | "light" | "dark") => void | - | Called after the theme changes. |
| className | string | - | Extra classes, merged with cn. |
MIT licensed. Copy it, change it, ship it.