import { Controller, useFormContext, type FieldPath, type FieldValues, } from "react-hook-form"; import { TextField } from "@/Components/inputs"; interface FormNumberFieldProps extends Omit< React.ComponentProps, "name" | "error" | "helperText" | "type" > { name: FieldPath; emptyValue?: number; // what an empty input writes to the form; 0 keeps today's sentinel } export const FormNumberField = ({ name, emptyValue = 0, ...rest }: FormNumberFieldProps) => { const { control } = useFormContext(); return ( ( { const val = e.target.value; field.onChange(val === "" ? emptyValue : Number(val)); }} error={!!fieldState.error} helperText={fieldState.error?.message ?? ""} fullWidth {...rest} /> )} /> ); };