Toggle
Labeled switch control for on/off settings, built on TogglePrimitive.
Overview
Toggle is the shared switch-style control for boolean on/off settings.
It wraps TogglePrimitive with:
- optional label text
- standard row layout
- size variants for standard and compact settings UIs
Use Toggle when the interaction is clearly a boolean state such as enabled/disabled, active/inactive, or show/hide.
Basic Usage
<Toggle
label="Add Meeting Link?"
checked={withMeetingLink}
onChange={setWithMeetingLink}
/>This is the common pattern used in forms and configuration panels.
Small Toggle
Use size="sm" inside denser panels and inline configuration rows.
<Toggle checked={isActive} onChange={onToggle} size="sm" />This is the pattern used in CancellationPanel.tsx.
With react-hook-form
<Controller
control={control}
name="showBackgroundImage"
render={({ field }) => (
<Toggle checked={field.value} onChange={field.onChange} />
)}
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Whether the switch is on. |
onChange | (checked: boolean) => void | — | Called when the switch changes. |
label | string | — | Optional label shown alongside the switch. |
className | string | — | Additional wrapper classes. |
disabled | boolean | — | Disables interaction. |
size | 'md' | 'sm' | 'md' | Switch size. |
Toggle Primitive
TogglePrimitive is the low-level switch behind Toggle.
Use it directly only when you need a custom layout that should not use the standard Toggle wrapper.
<div className="flex items-center gap-3">
<TogglePrimitive checked={enabled} onChange={setEnabled} />
<span>Enabled</span>
</div>Toggle composes:
TogglePrimitivefor switch behavior and accessibilityLabelfor optional text
For ordinary forms and settings panels, use Toggle instead of TogglePrimitive directly.
Primitive props:
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | — | Whether the switch is on. |
disabled | boolean | — | Disables interaction. |
onChange | (checked: boolean) => void | — | Called when the switch changes. |
size | 'sm' | 'md' | 'md' | Switch size. |
Brand Dashboard Usage
Representative usages:
| Pattern | Path | Notes |
|---|---|---|
| Workflow publishing state | fsai/apps/brand-dashboard/src/pages/Workflows/components/toolbar/WorkflowToolbar.tsx | Toggle used as a top-level state control. |
| Dense config-panel toggle | fsai/apps/brand-dashboard/src/pages/Workflows/components/config-panel/CancellationPanel.tsx | Compact inline toggle with size="sm". |
| Form-controlled boolean | fsai/apps/brand-dashboard/src/pages/PortalSignUpBuilder/PortalSignUpBuilder.components.tsx | Controller-driven toggle in a larger form. |
| Portal step boolean options | fsai/apps/brand-dashboard/src/pages/PortalEditor/ApplicantPortalEditor/PortalStepUpsert/components/ActionFieldsSwitcher/SignActionField.tsx | Multiple compact boolean toggles inside a feature panel. |
Choosing Between Toggle, Checkbox, And Radio
- Use
Togglefor a single on/off setting. - Use
Checkboxfor selection lists, permissions, or multi-select membership. - Use
Radiowhen the user must choose one option from a set.
Guidelines
- Do use
Togglefor immediate boolean settings - Do use
size="sm"in dense configuration UIs - Do wire it through
Controllerin react-hook-form when the value is form state - Do use
TogglePrimitiveonly when you need custom switch layout with the same semantics - Don't use
Togglefor mutually exclusive option groups - Don't use
Togglewhen a checkbox list communicates the intent more clearly