Componentform0.79 KB gzipZero dependencies

Switch

Two-state toggle switch with sliding thumb.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add switch

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { Switch } from "@/components/ui/switch"; <Switch defaultChecked aria-label="Notifications" />

Source code

switch.tsx + 2 helpers

Zero 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 />
PropTypeDescription
checkedbooleanControlled on state.
defaultCheckedbooleanUncontrolled initial state (default false).
onCheckedChange(checked: boolean) => voidCalled when the state changes.
namestringForm field name submitted during form serialization.
valuestringControlled value. (Default: "on")
requiredbooleanMarks the input as required for native form validation.