New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

input-masked-react

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

input-masked-react

A fully customizable masked input component for the web built with React

latest
Source
npmnpm
Version
0.4.8
Version published
Weekly downloads
73
-9.88%
Maintainers
1
Weekly downloads
 
Created
Source

input-masked-react

A fully customizable masked input component for the web built with React. Inspired by devfolioco/react-otp-input

Date-Of-Birth

OTP

Installation

yarn add input-masked-react

Basic usage:

import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    separator={<span>&nbsp;&nbsp;</span>}
  />

Edit on CodeSandbox

With styles applied to each input:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
  />

Edit on CodeSandbox

When inputs are disabled:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    isDisabled
    disabledStyle={{
      background: 'red'
    }}
  />

Edit on CodeSandbox

Force inputs to be numeric:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    isNumeric
  />

Edit on CodeSandbox

Add styles when inputs are focused:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    focusStyle={{
      outline: 0
    }}
  />

Edit on CodeSandbox

With placeholder for each input:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    placeholder='Y'
  />

Edit on CodeSandbox

With group separation:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={8}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    placeholder='Y'
    groupSeparatorPositions={[1, 3]}
    groupSeparator={<div style={{ width: 15 }} />}
  />

Edit on CodeSandbox

With individual input props:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={8}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    inputPropsMap={{
      0: { placeholder: "D", style: { width: 30 } },
      1: { placeholder: "D" },
      2: { placeholder: "M" },
      3: { placeholder: "M" },
      4: { placeholder: "Y" },
      5: { placeholder: "Y" },
      6: { placeholder: "Y" },
      7: { placeholder: "Y" },
    }}
    groupSeparatorPositions={[1, 3]}
    groupSeparator={<div style={{ width: 15 }} />}
  />

Edit on CodeSandbox

With error:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    error
    errorText={
      <div style={{ color: "red", marginTop: 10 }}>
        An error has occured!
      </div>
    }
  />

Edit on CodeSandbox

With defaultValues:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    defaultValues={'1000'.split('')}
  />

Edit on CodeSandbox

With valueEnteredStyle:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    onChange={otp => console.log(otp)}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    valueEnteredStyle={{
      borderBottom: '2px solid blue'
    }}
    focusStyle={{
      outline: 0
    }}
  />

Edit on CodeSandbox

Use cases

For Date Of Birth:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={8}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    inputPropsMap={{
      0: { placeholder: "D" },
      1: { placeholder: "D" },
      2: { placeholder: "M" },
      3: { placeholder: "M" },
      4: { placeholder: "Y" },
      5: { placeholder: "Y" },
      6: { placeholder: "Y" },
      7: { placeholder: "Y" }
    }}
    groupSeparatorPositions={[1, 3]}
    groupSeparator={<div style={{ width: 15 }} />}
    onChange={data => console.log(data)}
  />

Edit on CodeSandbox

For OTP:
import React from 'react';
import MaskedInput from 'input-masked-react';

const App = props => 
  <MaskedInput
    numInputs={4}
    inputStyle={{
      border: 0,
      borderBottom: "1px solid #DFE0E3",
      width: 20,
      height: 30
    }}
    separator={<span>&nbsp;&nbsp;&nbsp;</span>}
    placeholder={"•"}
    onChange={data => console.log(data)}
  />

Edit on CodeSandbox

API

Name
TypeRequiredDefaultDescription
numInputsnumbertrue4Number of OTP inputs to be rendered.
onChangefunctiontrueconsole.logReturns OTP code typed in inputs.
separatorcomponent
false[space]Provide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input
containerStylestyle (object) / className (string)falsenoneStyle applied or class passed to container of inputs.
inputStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input.
focusStylestyle (object) / className (string)falsenoneStyle applied or class passed to inputs on focus.
isDisabledbooleanfalsefalseDisables all the inputs.
disabledStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input when disabled.
errorbooleanfalsefalseIndicates there is an error in the inputs.
errorStylestyle (object) / className (string)falsenoneStyle applied or class passed to each input when errored.
shouldAutoFocusbooleanfalsefalseAuto focuses input on inital page load.
isInputNumbooleanfalsefalseRestrict input to only numbers.
placeholderstringfalsenonePlaceholder for each input
errorTextReactNodefalsenoneError message to show
groupSeparatorReactNodefalsenoneReact element to show at groupSeparatorPositions
groupSeparatorPositionsObjectfalse{}Positions when to show groupSeparator
inputPropsMapObjectfalse{}An object with props specifically for individual inputs
defaultValuesArrayfalse[]An array of default values for inputs
valueEnteredStyleObjectfalse{}Styles applied on value-entered inputs

Keywords

masking

FAQs

Package last updated on 27 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts