35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import * as React from 'react';
|
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
import { Check, Minus } from 'lucide-react';
|
|
import { cn } from '../lib/cn';
|
|
|
|
const Checkbox = React.forwardRef<
|
|
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
|
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
|
|
>(({ className, ...props }, ref) => (
|
|
<CheckboxPrimitive.Root
|
|
ref={ref}
|
|
className={cn(
|
|
'peer size-4 shrink-0 rounded-[5px] border border-border bg-card shadow-xs transition-colors',
|
|
'hover:border-border/80',
|
|
'focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/40',
|
|
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
'data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground data-[state=checked]:border-primary',
|
|
'data-[state=indeterminate]:bg-primary data-[state=indeterminate]:text-primary-foreground data-[state=indeterminate]:border-primary',
|
|
className,
|
|
)}
|
|
{...props}
|
|
>
|
|
<CheckboxPrimitive.Indicator className="flex items-center justify-center text-current">
|
|
{props.checked === 'indeterminate' ? (
|
|
<Minus className="size-3" />
|
|
) : (
|
|
<Check className="size-3" />
|
|
)}
|
|
</CheckboxPrimitive.Indicator>
|
|
</CheckboxPrimitive.Root>
|
|
));
|
|
Checkbox.displayName = 'Checkbox';
|
|
|
|
export { Checkbox };
|