import type { ChakraProps } from '@chakra-ui/react'; import { chakra, Checkbox } from '@chakra-ui/react'; import React from 'react'; import { useController, useFormContext, type FieldValues, type Path } from 'react-hook-form'; import type { FormFieldPropsBase } from './types'; interface Props< FormFields extends FieldValues, Name extends Path = Path, > extends Omit, 'size' | 'bgColor' | 'placeholder'> { label: string; } const FormFieldCheckbox = < FormFields extends FieldValues, Name extends Path = Path, >({ name, label, rules, onChange, isReadOnly, className, }: Props) => { const { control } = useFormContext(); const { field, formState } = useController({ control, name, rules, }); const isDisabled = formState.isSubmitting; const handleChange: typeof field.onChange = React.useCallback((...args) => { field.onChange(...args); onChange?.(); }, [ field, onChange ]); return ( { label } ); }; const WrappedFormFieldCheckbox = chakra(FormFieldCheckbox); export type WrappedComponent = < FormFields extends FieldValues, Name extends Path = Path, >(props: Props & ChakraProps) => React.JSX.Element; export default React.memo(WrappedFormFieldCheckbox) as WrappedComponent;