'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 Caption from '../../Caption' interface CheckboxProps extends React.InputHTMLAttributes { name: string registerOptions?: RegisterOptions hideError?: boolean topAlign?: boolean errorCodeMessages?: Record } const Checkbox = forwardRef< HTMLInputElement, React.PropsWithChildren >(function Checkbox( { className = '', name, children, registerOptions, hideError, topAlign = false, errorCodeMessages, }, ref ) { const { control } = useFormContext() const { field, fieldState } = useController({ control, name, rules: registerOptions, }) return ( {({ isSelected }) => ( <> {isSelected && ( )} {children} {fieldState.error && !hideError ? ( {(fieldState.error.message && errorCodeMessages?.[fieldState.error.message]) || fieldState.error.message} ) : null} )} ) }) export default Checkbox