Switch Label
SwitchLabel puts a label and an optional description next to a switch. Click the label to toggle it. The weekly digest lines its description up with the text (alignDescription="label"). The others line it up with the control. Marketing emails is disabled.
@dentil/switch-labelOn this page
Send an email when a payment fails or a payout is paid.
A Monday summary of payments, aligned with the label.
Product updates and offers.
payment emails on, digest offcomponents/demos/switch-label-overview.tsx
'use client';
import { useState } from 'react';
import { SwitchLabel } from '@/components/dentil/switch-label/switch-label';
export function SwitchLabelOverviewDemo() {
const [emails, setEmails] = useState(true);
const [digest, setDigest] = useState(false);
return (
<div className="flex w-full max-w-md flex-col gap-4">
<SwitchLabel
label="Payment emails"
description="Send an email when a payment fails or a payout is paid."
checked={emails}
onCheckedChange={setEmails}
/>
<SwitchLabel
label="Weekly digest"
description="A Monday summary of payments, aligned with the label."
alignDescription="label"
checked={digest}
onCheckedChange={setDigest}
/>
<SwitchLabel label="Marketing emails" description="Product updates and offers." disabled />
<span className="text-muted-foreground text-sm">
Result: <code className="text-foreground">{emails ? 'payment emails on' : 'payment emails off'}</code>,{' '}
<code className="text-foreground">{digest ? 'digest on' : 'digest off'}</code>
</span>
</div>
);
}Installation
pnpm dlx shadcn@latest add @dentil/switch-labelnpx shadcn@latest add @dentil/switch-labelyarn dlx shadcn@latest add @dentil/switch-labelbunx --bun shadcn@latest add @dentil/switch-labelFiles land in components/dentil/switch-label/. Uses the stock shadcn switch and label.
API reference
SwitchLabel
| Prop | Type | Default | Description |
|---|---|---|---|
| label | ReactNode | — | Text beside the switch. Clicking it toggles the switch. |
| description | ReactNode | — | Muted line under the row. The switch points at it with aria-describedby. |
| alignDescription | 'switch' | 'label' | 'switch' | switch starts the description at the control. label starts it at the label text, including when size is sm. |
| className | string | — | Applied to the wrapper. |
| …props | ComponentProps<typeof Switch> | — | Other props (checked, onCheckedChange, disabled, id, name, aria-invalid…) are passed to the switch. An id you pass is used; otherwise one is generated. aria-describedby is merged with the description. |