Skip to Content
Kokonut UI

BT-07Buttons

Switch Button

Light and dark theme toggle whose sun folds into a moon while the new theme spreads from the button as a circle.

Install with
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"}
    />
  );
}

PROPay Button and more like it are in Kokonut UI Pro

Installation

Switch Button is a free, open-source React component in the Kokonut UI Buttons collection. Add it with the shadcn CLI, which copies the source into components/kokonutui/switch-button.tsx, so the code is yours to change.

npx shadcn@latest add @kokonutui/switch-button

Props

size
"sm" | "default" | "lg"Default "default"
showLabel
booleanDefault true

Shows "Light" or "Dark" next to the icon.

theme
Theme

The applied theme, when a theme provider owns it (for next-themes, its resolvedTheme). Pair it with onThemeChange. Without it the button toggles the dark class on <html> itself.

onThemeChange
(theme: Theme) => void

Called with the theme to switch to.

reveal
booleanDefault true

Spreads the new theme from the button as a circle. false switches instantly.

Also takes every prop of React.ButtonHTMLAttributes<HTMLButtonElement>.

Theme

type Theme = "light" | "dark";

Dependencies

NeedsVersionComes from
cn from lib/utils.tsshadcn init
React19Your app
Tailwind CSS4Your app

No provider, font or global CSS to set up: the file works as soon as it lands.