Components
An accessible toggle switch built on Base UI's Switch primitive. Animated thumb with a springy press/scale interaction, two sizes (default and sm), controlled or uncontrolled usage via checked / defaultChecked, disabled state, and easy accent recoloring through the data-checked:* utilities. Re-exports SwitchPrimitive for advanced composition.
npx @21st-dev/cli add cnippet.dev/cnippet-switchLoading preview...
import { Switch } from "@/components/ui/cnippet-switch";
export default function SwitchDisabled() {
return (
<div className="flex flex-col items-start gap-3">
<div className="flex items-center gap-2">
<Switch disabled id="sw-disabled-off" />
<label
className="font-medium text-muted-foreground text-sm"
htmlFor="sw-disabled-off"
>
Disabled
</label>
</div>
<div className="flex items-center gap-2">
<Switch defaultChecked disabled id="sw-disabled-on" />
<label
className="font-medium text-muted-foreground text-sm"
htmlFor="sw-disabled-on"
>
Disabled
</label>
</div>
</div>
);
}
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...
Loading preview...