Context
μ¬λ¬ νλͺ©μ μμ΄ν
μ μ ννκΈ° μν΄μ Checkbox μ»΄ν¬λνΈλ₯Ό ꡬννκ² λμλ€. shadcnμμ μ 곡νλ checkbox μ»΄ν¬λνΈλ₯Ό μ¬μ©νκΈ° μν΄ μ΄λ₯Ό λΆμνκ³ μ νλ€.
Agenda
β’
shadcnμ Checkbox μ»΄ν¬λνΈλ₯Ό λΆμνκ³ μ΄λ₯Ό μ΄ν΄νλ κ²μ λͺ©νλ‘ ν¨
Contents
Checkbox
import { CheckIcon } from 'lucide-react';
import { Checkbox as CheckboxPrimitive } from 'radix-ui';
import { cn } from '@/ui/lib/utils';
const Checkbox = ({
className,
...props
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) => {
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] aria-invalid:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
{...props}
>
<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 };
TypeScript
볡μ¬
Checkbox μ»΄ν¬λνΈμ λ΄μ©μ΄λ€. Checkbox μ»΄ν¬λνΈλ shadcnμ CheckboxPrimitiveμ μμλ₯Ό κ°μΈλ Wrapper ννλ‘ κ΅¬ν λμ΄μλ€. CheckboxPrimitiveμ Rootμμ μ¬μ©νλ νλΌλ―Έν°λ€μ κ·Έλλ‘ μ¬μ©ν μ μκ² λ겨μ€λ€.