Switch

A toggle with a spring-driven thumb and press feedback.

Preview

"use client";

import { useState } from "react";
import { Switch } from "@/components/motion/switch";

export function SwitchPreview() {
  const [on, setOn] = useState(true);
  return (
    <div className="flex flex-col gap-3">
      <Switch sound checked={on} onCheckedChange={setOn} label="Enable notifications" />
      <Switch sound checked={false} onCheckedChange={() => {}} label="Off" />
      <Switch checked disabled onCheckedChange={() => {}} label="Disabled" />
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/switch

API Reference

checked
boolean

Whether the switch is on.

onCheckedChange
(checked: boolean) => void

Called with the new state when the switch is toggled.

disabled?
boolean

Dims the switch and stops it from toggling.

label?
string

Visible text beside the switch, also its accessible name.

ariaLabel?
string

Accessible name when there is no visible `label`.

sound?
boolean

Play a rising blip on, a falling one off. Off by default; a `SoundProvider` can mute it app-wide.

Defaultfalse
className?
string

Classes merged onto the root element.

Also on React Native. A weighty thumb that squishes and stretches.

Updated