mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 10:42:51 +02:00
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:
@@ -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} />;
|
||||
}
|
||||
Reference in New Issue
Block a user