import { CheckboxItem } from '@/core/interfaces'; import { FieldProps } from '@/core/types'; import { useTailwind } from '@/hooks'; import { useCallback, useMemo } from 'react'; import { Text, View, ViewProps } from 'react-native'; import { Style } from 'twrnc/dist/esm/types'; import Checkbox from '../touchable/Checkbox'; export interface CheckboxesProps extends Omit { data: CheckboxItem[]; containerStyle?: Style; checkboxStyle?: Style; itemStyle?: Style; } // eslint-disable-next-line @typescript-eslint/no-explicit-any export default function Checkboxes({ name, label, data, containerStyle, checkboxStyle, itemStyle, _fieldProps, ...props }: FieldProps>) { const tw = useTailwind(); const { field, fieldState } = _fieldProps!; const value = useMemo(() => field.value || [], [field]); const onPress = useCallback( (itemValue: T) => () => { const isChecked = value.includes(itemValue); const currentValue = isChecked ? value.filter((v: T) => v !== itemValue) : [...value, itemValue]; field.onChange(currentValue.isEmpty ? undefined : currentValue); }, [field, value], ); return ( {!!label && {label}} {data.map(item => ( ))} {!!fieldState.error?.message && ( {fieldState.error.message} )} ); }