Toggle Switch

A switch whose knob springs across. role=switch, keyboard friendly.

no dependenciesMIT · free

Installation

npx shadcn@latest add https://ombakui.com/r/toggle-switch.json

Usage

import { ToggleSwitch } from "@/components/toggle-switch";

<ToggleSwitch checked={enabled} onChange={setEnabled}>Email notifications</ToggleSwitch>

Props

PropTypeDefaultDescription
checkedboolean–On/off (controlled).
defaultCheckedbooleanfalseStarting state when uncontrolled.
onChange(checked: boolean) => void–Called with the new state.
childrenReactNode–Visible label next to the switch.
labelstring–Accessible name when there's no visible label.
size"sm" | "md" | "lg""md"Switch size.
disabledboolean–
classNamestring–