All components
Chewypixel component

Switch

A switch whose thumb springs across when toggled and stretches while pressed.

Installation

npx shadcn@latest add https://chewypixel.io/r/switch.json

Usage

import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";

export function NotificationsToggle() {
  return (
    <div className="flex items-center gap-2">
      <Switch id="notifications" defaultChecked />
      <Label htmlFor="notifications">Email notifications</Label>
    </div>
  );
}

Props

checked

The checked state, when controlled.

boolean

defaultChecked

The starting state, when uncontrolled.

boolean = false

onCheckedChange

Called when the checked state changes.

(checked: boolean) => void

Released under the MIT License.

More components

See them in a real app

These components come from Mochi, our admin dashboard template built with Next.js, shadcn/ui and Motion.