Make a new InputComponent that can be re-used everywhere to make all text accept the same kind of input

This commit is contained in:
Olivier Gagnon
2022-05-27 20:41:14 -04:00
parent 605dd87e90
commit b8750d1058
2 changed files with 25 additions and 12 deletions
+19
View File
@@ -0,0 +1,19 @@
import { TextField, StandardTextFieldProps } from "@mui/material";
import React from "react";
import { numeralWrapper } from "../numeralFormat";
interface IProps extends Omit<StandardTextFieldProps, "onChange"> {
onChange: (v: number) => void;
}
export function NumberInput(props: IProps): React.ReactElement {
const textProps = {
...props,
onChange: (event: React.ChangeEvent<HTMLInputElement>) => {
const amt = numeralWrapper.parseMoney(event.target.value);
if (event.target.value === "" || isNaN(amt)) props.onChange(NaN);
else props.onChange(amt);
},
};
return <TextField {...textProps} />;
}