Switch

A setting that applies at once.

$ npx shadcn@latest add https://mahrdesign.faizintifada.com/r/switch.json

Setting rows

Label + description on the left, switch at the row end. The change saves at once; show a toast only if the result is not visible.

States

Track 52 × 32 · knob 24 · off --placeholder · on --primary (blue = on; green is a status colour) · disabled 60 %. Reduced motion: the knob moves at once.

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

DoName the setting, not the action"Kirim slip otomatis": on means the thing happens.
Don'tA 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.

terminal
bunx --bun shadcn@latest add https://mahrdesign.faizintifada.com/r/switch.json

API

import { Switch } from "@/components/ui/switch"
PropTypeDefaultDescription
checked · defaultChecked · onCheckedChangeboolean · (checked) => void–Save the setting in onCheckedChange.
disabled · name · requiredBase UI Switch.Root props–
aria-label | id + <label htmlFor>string–Always name the switch.