Checkbox is a reusable binary form control from @branditdev/ui.
Preview
Usage
import { Checkbox, Label } from '@branditdev/ui';
export function CheckboxDemo() {
return (
<div className='space-y-3'>
<div className='flex items-center gap-2'>
<Checkbox id='marketing' />
<Label htmlFor='marketing'>Email me product updates</Label>
</div>
<div className='flex items-center gap-2'>
<Checkbox id='sms' disabled />
<Label htmlFor='sms'>Text alerts (disabled)</Label>
</div>
</div>
);
}
API
Checkbox(
props):Element
Defined in: components/checkbox/checkbox.tsx:15
Checkbox primitive built on Radix Checkbox.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
| props | CheckboxProps & RefAttributes<HTMLButtonElement> | no | - | Checkbox element props. |
Returns
Element
A styled checkbox element.
Source
import { CheckIcon } from 'lucide-react';
import { Checkbox as CheckboxPrimitive } from 'radix-ui';
import * as React from 'react';
import { cn } from '@/lib/utils';
export type CheckboxProps = React.ComponentProps<typeof CheckboxPrimitive.Root>;
function Checkbox(props: CheckboxProps) {
const { className, ...rest } = props;
return (
<CheckboxPrimitive.Root
data-slot='checkbox'
className={cn(
'peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50',
className
)}
{...rest}
>
<CheckboxPrimitive.Indicator
data-slot='checkbox-indicator'
className='grid place-content-center text-current transition-none'
>
<CheckIcon className='size-3.5' />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
);
}
export { Checkbox };