# 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 `npm`:

```bash
npx shadcn@latest add https://kokonutui.com/r/switch-button.json
```

## 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:

```javascript
"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"}
    />
  );
}
```

## Installation

Switch Button is a free, open-source React component in the Kokonut UI [Buttons collection](/content/docs/buttons/index.html). Add it with the shadcn CLI, which copies the source into `components/kokonutui/switch-button.tsx`, so the code is yours to change.

```bash
npx shadcn@latest add @kokonutui/switch-button
```

## Props

- `size`: "sm" | "default" | "lg" (Default: "default")
- `showLabel`: boolean (Default: true)  Shows "Light" or "Dark" next to the icon.
- `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`: boolean (Default: true) Spreads the new theme from the button as a circle. `false` switches instantly.

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

### Theme

```javascript
type Theme = "light" | "dark";
```

## Dependencies

| Needs | Version | Comes from |
| --- | --- | --- |
| `cn` from `lib/utils.ts` | | shadcn init |
| React | `19` | Your app |
| Tailwind CSS | `4` | Your app |

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

### Related Buttons

- [Command Button](/content/docs/buttons/command-button/index.html): A button with its shortcut drawn as keycaps that sink as you press the real keys.
- [Slide Text Button](/content/docs/buttons/slide-text-button/index.html): Animated link button with a vertical text slide on hover and default and ghost variants, built with React, Next.js Link, and Tailwind CSS.
