import { useEffect, type InputHTMLAttributes, type RefObject } from "preact/compat"; interface FormTextBoxProps extends Omit, "onChange" | "onBlur" | "value"> { id?: string; currentValue?: string; onChange?(newValue: string, validity: ValidityState): void; onBlur?(newValue: string): void; inputRef?: RefObject; } export default function FormTextBox({ inputRef, className, type, currentValue, onChange, onBlur, autoFocus, ...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); } } useEffect(() => { if (autoFocus) { inputRef?.current?.focus(); } }, []); return ( { const target = e.currentTarget; onChange?.(target.value, target.validity); })} onBlur={onBlur && (e => { const target = e.currentTarget; onBlur(target.value); })} {...rest} /> ); } export function FormTextBoxWithUnit(props: FormTextBoxProps & { unit: string }) { return ( ) }