import { useCallback } from 'react'; import cx from 'classnames'; import Checkbox, { ICheckboxProps, ICheckboxEvent } from '../../checkbox'; import { IFormComponentProps } from '../shared'; import { FormField, IFormFieldChildProps } from '../Field'; import { $MergeParams } from '../utils'; import { useEventCallbackRef } from '../../utils/hooks/useEventCallbackRef'; export type IFormCheckboxFieldProps = IFormComponentProps< boolean, Omit, 'checked'> >; function CheckboxField({ childProps, props, }: { childProps: IFormFieldChildProps; props: IFormCheckboxFieldProps; }) { const { value, ...passedProps } = childProps; const onChangeRef = useEventCallbackRef(childProps.onChange); const onChange = useCallback( (e: ICheckboxEvent) => { onChangeRef.current?.(e.target.checked); }, [onChangeRef] ); return ( ); } export function FormCheckboxField( props: IFormCheckboxFieldProps ) { const { className, ...rest } = props; return ( >).defaultValue || false } > {childProps => } ); }