import * as React from "react"; import { Controller, type FieldPath, type FieldValues, useFormContext, } from "react-hook-form"; import { FormMessage } from "~/components/FormMessage"; interface InputGroupFormFieldProps { label: string; name: FieldPath; bottomText?: string; type: "checkbox" | "radio"; values: Array<{ label: string; value: string; }>; } export function InputGroupFormField({ label, name, bottomText, values, type, }: InputGroupFormFieldProps) { const methods = useFormContext(); return ( { const handleCheckboxChange = (name: string) => (newChecked: boolean) => { const newValue = newChecked ? [...(value || []), name] : value?.filter((v: string) => v !== name); onChange(newValue); }; const handleRadioChange = (name: string) => () => { onChange(name); }; return (
{label} {values.map((checkbox) => { const isChecked = value?.includes(checkbox.value); return ( {checkbox.label} ); })}
{error && ( {error.message as string} )} {bottomText && !error ? ( {bottomText} ) : null}
); }} /> ); } function GroupInput({ children, name, checked, onChange, type, }: { children: React.ReactNode; name: string; checked: boolean; onChange: (newChecked: boolean) => void; type: "checkbox" | "radio"; }) { const id = React.useId(); return (
onChange(e.target.checked)} />
); }