'use client' import { forwardRef } from 'react' import { Checkbox as AriaCheckbox } from 'react-aria-components' import { type RegisterOptions, useController, useFormContext, } from 'react-hook-form' import styles from './checkbox.module.css' import { MaterialIcon } from '../../Icons/MaterialIcon' import { ErrorMessage } from '../ErrorMessage' interface CheckboxProps extends React.InputHTMLAttributes { name: string registerOptions?: RegisterOptions hideError?: boolean topAlign?: boolean errorCodeMessages?: Record } const CheckboxComponent = forwardRef< HTMLInputElement, React.PropsWithChildren >(function Checkbox( { className = '', name, children, registerOptions, hideError, topAlign = false, errorCodeMessages, }, ref ) { const { control } = useFormContext() const { field, fieldState, formState } = useController({ control, name, rules: registerOptions, }) return ( {({ isSelected }) => ( <> {isSelected && ( )} {children} {fieldState.error && !hideError ? ( ) : null} )} ) }) const Checkbox = CheckboxComponent as React.ForwardRefExoticComponent< React.PropsWithChildren & React.RefAttributes > export default Checkbox