Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import * as React from 'react';
|
|
import { IMaskInput } from 'react-imask';
|
|
import { NumericFormat } from 'react-number-format';
|
|
import Stack from '@mui/material/Stack';
|
|
import Input from '@mui/material/Input';
|
|
import InputLabel from '@mui/material/InputLabel';
|
|
import TextField from '@mui/material/TextField';
|
|
import FormControl from '@mui/material/FormControl';
|
|
|
|
interface CustomProps {
|
|
onChange: (event: { target: { name: string; value: string } }) => void;
|
|
name: string;
|
|
}
|
|
|
|
const TextMaskCustom = React.forwardRef<HTMLInputElement, CustomProps>(
|
|
function TextMaskCustom(props, ref) {
|
|
const { onChange, ...other } = props;
|
|
return (
|
|
<IMaskInput
|
|
{...other}
|
|
mask="(#00) 000-0000"
|
|
definitions={{
|
|
'#': /[1-9]/,
|
|
}}
|
|
inputRef={ref}
|
|
onAccept={(value: any) => onChange({ target: { name: props.name, value } })}
|
|
overwrite
|
|
/>
|
|
);
|
|
},
|
|
);
|
|
|
|
export default function FormattedInputs() {
|
|
const [values, setValues] = React.useState({
|
|
textmask: '(100) 000-0000',
|
|
numberformat: '1320',
|
|
});
|
|
|
|
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
setValues({
|
|
...values,
|
|
[event.target.name]: event.target.value,
|
|
});
|
|
};
|
|
|
|
return (
|
|
<Stack direction="row" spacing={2}>
|
|
<FormControl variant="standard">
|
|
<InputLabel htmlFor="formatted-text-mask-input">react-imask</InputLabel>
|
|
<Input
|
|
value={values.textmask}
|
|
onChange={handleChange}
|
|
name="textmask"
|
|
id="formatted-text-mask-input"
|
|
inputComponent={TextMaskCustom as any}
|
|
/>
|
|
</FormControl>
|
|
<NumericFormat
|
|
value={values.numberformat}
|
|
onChange={handleChange}
|
|
customInput={TextField}
|
|
thousandSeparator
|
|
valueIsNumericString
|
|
prefix="$"
|
|
variant="standard"
|
|
label="react-number-format"
|
|
/>
|
|
</Stack>
|
|
);
|
|
}
|