1.5.0 • Published 3 years ago

react-fmt-input v1.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

demo

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
# - number

Example:

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

https://react-formatted-input.vercel.app/

1.5.0

3 years ago

1.4.0

3 years ago

1.3.0

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago