import type { InputHTMLAttributes, RefObject } from "preact/compat"; interface FormTextBoxProps extends Omit, "onChange" | "value"> { id?: string; currentValue?: string; onChange?(newValue: string, validity: ValidityState): void; inputRef?: RefObject; } export default function FormTextBox({ inputRef, className, type, currentValue, onChange, ...rest}: FormTextBoxProps) { if (type === "number" && currentValue) { const { min, max } = rest; const currentValueNum = parseInt(currentValue, 10); if (min && currentValueNum < parseInt(String(min), 10)) { currentValue = String(min); } else if (max && currentValueNum > parseInt(String(max), 10)) { currentValue = String(max); } } return ( { const target = e.currentTarget; onChange?.(target.value, target.validity); }} {...rest} /> ); } export function FormTextBoxWithUnit(props: FormTextBoxProps & { unit: string }) { return ( ) }