Switch
A setting that applies at once.
$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/switch.jsonSetting rows
States
When to use
- A setting that applies AT ONCE, with no Simpan button: Notifikasi, Kirim slip otomatis.
When not to use
- A choice inside a Sheet or Dialog form that waits for Simpan → Checkbox.
- Pick one of several values → SegmentedControl / RadioGroup.
Do and don't
Name the setting, not the action"Kirim slip otomatis": on means the thing happens.
A Switch in a formInside "Tambah jenis cuti" the value is saved only with Simpan, so it must be a Checkbox.
Installation
Add Switch with the shadcn CLI (your project needs a components.json and the MaHR theme: https://mahrdesign.faizintifada.com/r/theme.json), or copy the files by hand.
API
import { Switch } from "@/components/ui/switch"| Prop | Type | Default | Description |
|---|---|---|---|
checked · defaultChecked · onCheckedChange | boolean · (checked) => void | – | Save the setting in onCheckedChange. |
disabled · name · required | Base UI Switch.Root props | – | |
aria-label | id + <label htmlFor> | string | – | Always name the switch. |