import type { CheckboxField } from '@payloadcms/plugin-form-builder/types' import type { FieldErrorsImpl, FieldValues, UseFormRegister } from 'react-hook-form' import { useFormContext } from 'react-hook-form' import { Checkbox as CheckboxUi } from '@/components/ui/checkbox' import { Label } from '@/components/ui/label' import React from 'react' import { Error } from '../Error' import { Width } from '../Width' export const Checkbox: React.FC< CheckboxField & { errors: Partial register: UseFormRegister } > = ({ name, defaultValue, errors, label, register, required, width }) => { const props = register(name, { required: required }) const { setValue } = useFormContext() return (
{ setValue(props.name, checked) }} />
{errors[name] && }
) }