BT-07ButtonsUpdated, October 16, 2026
Switch Button
Light and dark theme toggle whose sun folds into a moon while the new theme spreads from the button as a circle.
no extra packages
Usage
With no props, the button toggles the dark class on <html>, which is what Tailwind's class-based dark: variant reads. It does not save the choice.
The new theme spreads out from the button as a circle, using the View Transitions API. In browsers without it, or with reduced motion turned on, the theme switches instantly.
If a theme provider already owns the theme, pass the applied theme and a setter instead. With next-themes:
"use client";
import { useTheme } from "next-themes";
import SwitchButton from "@/components/kokonutui/switch-button";
export function ThemeSwitch() {
const { resolvedTheme, setTheme } = useTheme();
return (
<SwitchButton
onThemeChange={setTheme}
theme={resolvedTheme === "dark" ? "dark" : "light"}
/>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
theme | "light" | "dark" | — | The applied theme, when a provider owns it. Without it the button toggles the dark class itself. |
onThemeChange | (theme: "light" | "dark") => void | — | Called with the theme to switch to. |
reveal | boolean | true | Spreads the new theme from the button as a circle. Set false to switch instantly. |
size | "sm" | "default" | "lg" | "default" | Button size. |
showLabel | boolean | true | Shows "Light" or "Dark" next to the icon. |
