import { Checkbox } from '@ariakit/react'; import { FormControl, useControl } from '@websolutespa/bom-mixer-forms'; import { useLabel } from '@websolutespa/bom-mixer-hooks'; import { ChangeEvent, FocusEvent, useId, useState } from 'react'; import { Field, FieldProps, Label } from '../forms'; import { FieldError } from './field-error'; type FieldCheckboxProps = { control: FormControl; }; export function FieldCheckbox({ control, ...props }: FieldCheckboxProps & FieldProps) { const uid = useId(); const label = useLabel(); const uniqueName = `${control.name}-${uid}`; const [state, setValue, setTouched] = useControl(control); const onChange = (event: ChangeEvent) => { // console.log('onChange', event.target.checked); setValue(event.target.checked); }; const [focus, setFocus] = useState(false); const onBlur = (_: FocusEvent) => { setTouched(); setFocus(false); }; const onFocus = (_: FocusEvent) => { setFocus(true); }; const controlLabel = control.label && label(control.label); return ( state.flags.hidden ? ( ) : ( {/* type={(state.flags.invalid && state.flags.touched) ? 'error' : 'default'} */} ) ); } // {JSON.stringify(props.control.errors[key])}