Components
Checkbox
An animated checkbox with check and indeterminate states, SVG stroke animation, and primary/neutral color variants.
Installation
bunx @happlyui/cli@latest add checkbox
Dependencies
npm packages
@radix-ui/react-checkbox
Registry dependencies
These are automatically installed when you add this component.
form-field-contextuse-form-field-bindinghapply-ui-utils
Usage
import * as Checkbox from "@/components/ui/checkbox"
<Checkbox.Root />
Examples
Demo
Default checkbox.
<Checkbox.Root />
Variants
Primary and neutral color variants in unchecked, checked, and indeterminate states.
Primary
Neutral
<Checkbox.Root variant="primary" defaultChecked />
<Checkbox.Root variant="neutral" defaultChecked />
Disabled
Disabled checkbox in unchecked, checked, and indeterminate states.
<Checkbox.Root disabled />
<Checkbox.Root disabled checked />
<Checkbox.Root disabled checked="indeterminate" />
With Label
Checkboxes paired with Label component for form usage.
<div className="flex items-center gap-2">
<Checkbox.Root id="c1" />
<Label.Root htmlFor="c1">SMS Verification</Label.Root>
</div>
With Label Extended
Checkboxes with labels, sublabels, badges, descriptions, and link buttons.
<div className="flex items-center gap-2">
<Checkbox.Root id="c1" />
<Label.Root htmlFor="c1">
Label
<Label.Sub>(Sublabel)</Label.Sub>
<Badge.Root>NEW</Badge.Root>
</Label.Root>
</div>
With Form Field
Checkbox group composed with FormField for consistent label and hint.
Choose how you want to be notified.
<FormField.Root label="Notifications" hint="Choose how you want to be notified.">
<div className="flex flex-col gap-3">
<div className="flex items-center gap-2">
<Checkbox.Root id="email" defaultChecked />
<Label.Root htmlFor="email" className="text-paragraph-sm">
Email notifications
</Label.Root>
</div>
<div className="flex items-center gap-2">
<Checkbox.Root id="sms" />
<Label.Root htmlFor="sms" className="text-paragraph-sm">
SMS notifications
</Label.Root>
</div>
<div className="flex items-center gap-2">
<Checkbox.Root id="push" />
<Label.Root htmlFor="push" className="text-paragraph-sm">
Push notifications
</Label.Root>
</div>
</div>
</FormField.Root>
API Reference
Checkbox.Root
The checkbox component with animated SVG check/indeterminate indicators.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'neutral' | 'primary' | The color variant for the checked state |
checked | boolean | 'indeterminate' | - | Controlled checked state |
defaultChecked | boolean | - | Default checked state for uncontrolled usage |
disabled | boolean | false | Disable the checkbox |
onCheckedChange | (checked: boolean | 'indeterminate') => void | - | Callback when checked state changes |