About
An accessible on/off toggle control built on a native checkbox, with support for labels, descriptions, sizes, validation errors and a read-only state, that works in forms like a regular checkbox.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Switch to your project and fits it to your theme.
Code
How Switch is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
import Switch from "@/components/ui/switch";
import { useState } from "react";
export default function Basic() {
const [notifications, setNotifications] = useState(true);
return (
<div className="space-y-4">
<Switch
checked={notifications}
label={`Notifications are ${notifications ? "on" : "off"}`}
onChange={(event) => setNotifications(event.target.checked)}
/>
<Switch defaultChecked label="Uncontrolled, on by default" name="beta" />
<Switch
description="Customers get a copy of every invoice by email."
label="Send invoices automatically"
name="autoSend"
/>
<Switch disabled label="Disabled" />
<Switch error="This setting is required." label="With an error" />
</div>
);
}















