import React, { forwardRef, useId } from "react"; import FormField, { FormFieldProps } from "./form-field"; import { cn } from "~/lib/utils"; import { Controller, FieldValues, Path } from "react-hook-form"; import { useFormReturn } from "~/hooks/useForm"; export type CheckboxItem = { label: string; value: string; }; type BaseCheckboxProps = React.ComponentPropsWithoutRef<"input"> & FormFieldProps & { inputClassName?: string; items?: CheckboxItem[] | null; }; const BaseCheckbox = forwardRef( (props, ref) => { const { className, label, error, inputClassName, items, ...restProps } = props; const id = useId(); const input = ( ); if (error) { return ; } return input; } ); type CheckboxProps = Omit< BaseCheckboxProps, "form" | "name" > & { form?: useFormReturn; name?: Path; }; const Checkbox = (props: CheckboxProps) => { const { form, ...restProps } = props; if (form && props.name) { return ( ( )} /> ); } return ; }; export default Checkbox;