improve forms by adding select and float inputs

performance fix
This commit is contained in:
2023-06-01 01:24:42 +02:00
parent ebb2408a68
commit fcd3afa3f2
21 changed files with 872 additions and 345 deletions

View File

@@ -0,0 +1,30 @@
import { useCallback, useState } from "react";
import { z } from "zod";
type FloatInputProps = {
value: number;
onChange: (value: number) => void;
id: string;
};
const FloatInput: React.FC<FloatInputProps> = ({ value, onChange, id }) => {
const [inputValue, setInputValue] = useState<string>(value.toString());
const handleInputChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
const val = e.target.value.replace(",", ".");
setInputValue(val);
const nextValue = z.coerce.number().min(-9999).max(9999).safeParse(val);
if (nextValue.success) {
onChange(nextValue.data);
}
},
[setInputValue, onChange]
);
return <input id={id} onChange={handleInputChange} value={inputValue} />;
};
export default FloatInput;