push rasad front on new repo
This commit is contained in:
40
src/components/number-format-custom/NumberFormatCustom.js
Normal file
40
src/components/number-format-custom/NumberFormatCustom.js
Normal file
@@ -0,0 +1,40 @@
|
||||
import React from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { NumberFormatBase, useNumericFormat } from "react-number-format";
|
||||
import { TextField } from "@mui/material";
|
||||
|
||||
export const NumberInput = (props) => {
|
||||
const { format, removeFormatting, ...rest } = useNumericFormat(props);
|
||||
const _format = (val) => {
|
||||
const _val = format(val);
|
||||
return _val;
|
||||
};
|
||||
|
||||
delete rest.onChange;
|
||||
|
||||
const _removeFormatting = (val) => {
|
||||
const _val = val.toLowerCase().replace(/[ ,]/g, "");
|
||||
return removeFormatting(_val);
|
||||
};
|
||||
return (
|
||||
<NumberFormatBase
|
||||
customInput={TextField}
|
||||
removeFormatting={_removeFormatting}
|
||||
format={_format}
|
||||
{...rest}
|
||||
onValueChange={(values) => {
|
||||
props.onChange({
|
||||
target: {
|
||||
name: props.id,
|
||||
value: values.floatValue,
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
NumberInput.propTypes = {
|
||||
id: PropTypes.any.isRequired,
|
||||
onChange: PropTypes.func.isRequired,
|
||||
};
|
||||
Reference in New Issue
Block a user