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
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import * as React from 'react';
|
|
import { IMaskInput } from 'react-imask';
|
|
import FormControl from '@mui/joy/FormControl';
|
|
import FormLabel from '@mui/joy/FormLabel';
|
|
import Input from '@mui/joy/Input';
|
|
|
|
interface CustomProps {
|
|
onChange: (event: { target: { name: string; value: string } }) => void;
|
|
name: string;
|
|
}
|
|
|
|
const TextMaskAdapter = React.forwardRef<HTMLInputElement, CustomProps>(
|
|
function TextMaskAdapter(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 InputReactImask() {
|
|
const [value, setValue] = React.useState('(100) 000-0000');
|
|
return (
|
|
<FormControl>
|
|
<FormLabel>Label</FormLabel>
|
|
<Input
|
|
value={value}
|
|
onChange={(event) => setValue(event.target.value)}
|
|
placeholder="Placeholder"
|
|
slotProps={{ input: { component: TextMaskAdapter } }}
|
|
/>
|
|
</FormControl>
|
|
);
|
|
}
|