Loading component…
Loading component…
On or off for things that apply right away
To reuse this local React demo, copy all files from the Code tab into the same folder, then import Switch from ./switch.
import { useState } from "react";
import { Switch } from "@/components/ui/switch";
export function DigestSetting({ onSave }: { onSave: (on: boolean) => void }) {
const [on, setOn] = useState(true);
return (
<Switch
placement="end"
label="Daily digest"
description="Approvals waiting, runs that finished or failed"
checked={on}
onChange={(e) => {
setOn(e.target.checked);
onSave(e.target.checked);
}}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | Shown next to the switch; clicking it toggles | |
| description | ReactNode | A quiet second line under the label, linked with aria-describedby | |
| placement | "start" \| "end" | "start" | start: the switch before the text · end: the text first and the switch on the far right of the row |
| size | "sm" \| "md" | "md" | 26 × 16 or 32 × 20; bigger on touch screens |
| ...input props | ComponentProps<"input"> | checked, defaultChecked, onChange, name, disabled, aria-label, ref – everything goes to the real input |
Long labels wrap; the switch stays on the first line
Touch screens get a 40 × 24 switch, 15px text and a hit area larger than the track
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.