Componentform0.79 KB gzipZero dependencies
Switch
Two-state toggle switch with sliding thumb.
Preview
Live Preview
Installation
Tokens guide →Add to your project via CLI (zero dependencies, code you own):
npx bigbullui add switchOr install the full npm package:
npm install bigbulluiUsage
tsx3 lines
import { Switch } from "@/components/ui/switch"; <Switch defaultChecked aria-label="Notifications" />Source code
switch.tsx + 2 helpersZero third-party dependencies (3 local files shown in tabs below).
tsxswitch.tsx102 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils";import { mergeRefs } from "./lib/react-compat"; export type SwitchProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange" | "value"> & { checked?: boolean; defaultChecked?: boolean; onCheckedChange?: (checked: boolean) => void; name?: string; value?: string; required?: boolean;}; const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>( ( {Props
Interactive Prop Playground
Tweak parsed AST props below to generate ready-to-paste JSX.
tsx3 lines
import { Switch } from "@/components/ui/switch"; <Switch />| Prop | Type | Description |
|---|---|---|
| checked | boolean | Controlled on state. |
| defaultChecked | boolean | Uncontrolled initial state (default false). |
| onCheckedChange | (checked: boolean) => void | Called when the state changes. |
| name | string | Form field name submitted during form serialization. |
| value | string | Controlled value. (Default: "on") |
| required | boolean | Marks the input as required for native form validation. |