'use client' import { Check } from 'lucide-react' import { FieldWrapper, InputLabel } from './shared' export type CheckboxOption = { label: string value: string | number } type CheckboxItemProps = Omit, 'name'> & { name: string label?: string error?: string info?: string description?: string className?: string textSize?: 'sm' | 'md' } export type CheckboxProps = Omit, 'name' | 'onChange' | 'value'> & { name: string label?: string error?: string info?: string description?: string className?: string options: CheckboxOption[] value?: (string | number)[] onChange?: (value: (string | number)[]) => void textSize?: 'sm' | 'md' } export default function Checkbox(props: CheckboxProps) { const { options, onChange, value, label, description, error, info, name, className, textSize = 'sm', ...rest } = props const selectedValues = Array.isArray(value) ? value : [] return (
{options.map((option) => ( { if (!onChange) return const isChecked = e.target.checked let newValues = [...selectedValues] if (isChecked) { newValues.push(option.value) } else { newValues = newValues.filter((v) => v !== option.value) } onChange(newValues) }} className='mb-0' /> ))}
) } function CheckboxItem(props: CheckboxItemProps) { const { name, label, error, ...inputProps } = props const id = inputProps.value ? `${name}-${inputProps.value}` : name return (
{label && ( )}
) }