shadcn.io is an independent project built on shadcn/ui
Three switches sit on bordered rows under Notification Settings. Email and desktop start on, and push starts off. Each row has a label and a one-line description.
Use it for settings that take effect on their own, with no required choice. A must-accept term is a Checkbox. In React, Ark UI does not save the switches. The form does.
Installation
Usage
<form className="w-full max-w-md" onSubmit={form.handleSubmit(onSubmit)}>
<FieldGroup>
<FieldSet>
<FieldLegend>Notification Settings</FieldLegend>
<FieldGroup className="gap-4">
{notifications.map((notification) => (
<Controller
control={form.control}
key={notification.name}
name={notification.name}
render={({ field }) => (
<Field
className="rounded-lg border p-4"
orientation="horizontal"
>
<FieldContent>
<FieldLabel>{notification.label}</FieldLabel>
<FieldDescription>
{notification.description}
</FieldDescription>
</FieldContent>
<Switch
checked={field.value}
name={field.name}
onCheckedChange={({ checked }) => field.onChange(checked)}
/>
</Field>
)}
/>
))}
</FieldGroup>
{/* The rest of the file is under Installation. */}FAQ
How is each switch connected to the form?
The rows come from one notifications array mapped to a Controller each. Switch takes checked={field.value}, and onCheckedChange passes checked to field.onChange.
Which switches start on?
defaultValues sets emailNotifications and desktopNotifications to true and pushNotifications to false.
How is each row arranged?
Each row is Field orientation="horizontal" with rounded-lg border p-4: FieldContent with the FieldLabel and FieldDescription first, then the Switch. The rows sit in a FieldGroup inside a FieldSet whose FieldLegend is Notification Settings.
What do the three descriptions say?
Email Notifications: "Receive notifications via email." Push Notifications: "Receive push notifications on your device." Desktop Notifications: "Receive notifications on your desktop."
API Reference
Field
Sets orientation="horizontal". The rest is on the Field page.
Switch
Sets checked={field.value}, name={field.name}, onCheckedChange and checked. The rest is on the Switch page.
Button
Sets type="submit". The rest is on the Button page.





