1.5.0 • Published 5 years ago
react-fmt-input v1.5.0
This is a test task from a job interview, which was allocated 30 minutes of live coding. Maybe this example will be useful for someone to start a more advanced component or you can use it as is.

Component API
interface FormattedInputProps {
label: string;
value: string;
mask: string;
placeholder: string;
errorMessage: string;
parser?: (str: string | null | undefined) => string;
formatter?: (str: string, mask: string) => string;
onChange: (str: string) => void;
}Mask format
^ - upercase character
_ - lowercase character
# - numberExample:
import {useState} from 'react';
import {defaultParser, defaultFormatter, FormattedInput} from 'react-fmt-input';
const Demo = () => {
const [phone, setPhone] = useState<string>("");
return (
<FormattedInput
label="Phone"
value={phone}
mask="+# (###) ###-##-##"
placeholder="+7 (999) 123-45-67"
errorMessage="Invalid number"
onChange={setPhone}
parser={defaultParser} // optional
formatter={defaultFormatter} // optional
/>
)
};Demo project
https://github.com/kobzarvs/formatted-input-demo
Vercel demo
1.5.0
5 years ago
1.4.0
5 years ago
1.3.0
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
5 years ago
1.1.3
5 years ago
1.1.2
5 years ago
1.1.1
5 years ago
1.1.0
5 years ago
1.0.12
5 years ago
1.0.11
5 years ago
1.0.10
5 years ago
1.0.9
5 years ago
1.0.8
5 years ago
1.0.7
5 years ago
1.0.6
5 years ago
1.0.5
5 years ago
1.0.4
5 years ago
1.0.3
5 years ago
1.0.2
5 years ago
1.0.1
5 years ago
1.0.0
5 years ago