input-masked-react
A fully customizable masked input component for the web built with React. Inspired by devfolioco/react-otp-input
Installation
yarn add input-masked-react
Basic usage:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = />
With styles applied to each input:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = />
When inputs are disabled:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = />
Force inputs to be numeric:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = />
Add styles when inputs are focused:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = />
With placeholder for each input:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = ='Y' />
With group separation:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = ='Y' = = />
With individual input props:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = = = />
With error:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = />
With defaultValues:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = />
With valueEnteredStyle:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = = />
Use cases
For Date Of Birth:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = = = />
For OTP:
import React from 'react';import MaskedInput from 'input-masked-react'; const App = <MaskedInput = = = = = />
API
Name |
Type | Required | Default | Description |
---|---|---|---|---|
numInputs | number | true | 4 | Number of OTP inputs to be rendered. |
onChange | function | true | console.log | Returns OTP code typed in inputs. |
separator | component |
false | [space] | Provide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input |
containerStyle | style (object) / className (string) | false | none | Style applied or class passed to container of inputs. |
inputStyle | style (object) / className (string) | false | none | Style applied or class passed to each input. |
focusStyle | style (object) / className (string) | false | none | Style applied or class passed to inputs on focus. |
isDisabled | boolean | false | false | Disables all the inputs. |
disabledStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when disabled. |
error | boolean | false | false | Indicates there is an error in the inputs. |
errorStyle | style (object) / className (string) | false | none | Style applied or class passed to each input when errored. |
shouldAutoFocus | boolean | false | false | Auto focuses input on inital page load. |
isInputNum | boolean | false | false | Restrict input to only numbers. |
placeholder | string | false | none | Placeholder for each input |
errorText | ReactNode | false | none | Error message to show |
groupSeparator | ReactNode | false | none | React element to show at groupSeparatorPositions |
groupSeparatorPositions | Object | false | {} | Positions when to show groupSeparator |
inputPropsMap | Object | false | {} | An object with props specifically for individual inputs |
defaultValues | Array | false | [] | An array of default values for inputs |
valueEnteredStyle | Object | false | {} | Styles applied on value-entered inputs |