πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
DemoInstallSign in
Socket

react-verification-input

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-verification-input

Customizable, masked input, which can be used for all sorts of codes.

0.1.3
Source
npm
Version published
Weekly downloads
40K
0.2%
Maintainers
1
Weekly downloads
Β 
Created
Source

react-verification-input

NPM version HitCount

react-verification-input is a customizable, masked input, which can be used to enter all sorts of codes e.g. security codes when two-factor authenticating. Also I'm sure you can think of many more creative use cases. This component is fully compatible with Redux Form πŸŽ‰

react-verification-input

Installation

Install it by running

npm install react-verification-input --save

or

yarn add react-verification-input

in your terminal.

Usage

Import the React component as follows:

import VerificationInput from 'react-verification-input'

Inside the render method write:

<VerificationInput />

ThatΒ΄s it! You now have a basic verification input with default configuration rendered on your page. πŸŽ‰πŸ˜ƒ

Of course the input can be configured manually. For a complete API overview see here.

Note: In order for it to work properly, make sure you have the <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no user-scalable=no"> tag in the head of your page. Otherwise it might zoom in to the left side of the screen on mobile devices. This is the case because mobile devices zoom in on inputs and there is an input field outside of the viewport.

API documentation

All of these props are optional and thus come with a default value. However it's recommended to use at least the length, validChars and placeholder props.

OptionTypeDefaultDescription
lengthNumber6Define, how many characters the input should allow.
validCharsString'A-Za-z0-9'Define, which characters should be allowed. The string is inserted into a regexp character set ( /[]/ ) for input validating.
placeholderString'Β·' (U+00B7)Define, which character should be displayed as placeholder in empty fields. In order to use the blank character as placeholder specify this option as ' ' or ''.
autoFocusBooleanfalseThis will make the input focus automatically as soon as it rendered.
removeDefaultStylesBooleanfalseThe default styling might get annoying when applying you own styles. Use this option to completely remove all styles, that are not required in order for the component to work properly.
debugBooleanfalseThis will reveal, what's going on behind the scenes, which might come in handy when trying to better understand the component. Obviously you don't want to use this in production. πŸ˜„
containerObject{}Define the props of the container div. All props except for className are passed directly to the div element. Use { className: 'your-class' } to style the input. These options are available on every element. For more details on how to apply your custom styling see here.
inputFieldObject{}Define the props of the input element. See container for more details.
charactersObject{}Define the props of the characters div. See container for more details.
characterObject{}Define the props of the character divs. See container for more details.

Custom styling

Style the input by passing it your custom class names like so:

<VerificationInput
  container={{
    className: 'container',
  }}
  characters={{
    className: 'characters',
  }}
  character={{
    className: 'character',
    classNameInactive: 'character--inactive',
    classNameSelected: 'character--selected',
  }}
/>

There is also the inputField prop, which will attach styles to the actual input element, but you probably don't want to use this as it's outside the viewport and thus not visible.

Have a look at these two examples:

Example 1

.container {
  max-width: 350px;
}

.character {
  background-color: rgba(255, 255, 255, 0.2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: white;
  margin-left: 8px;
}

.character--inactive {
  background-color: rgba(255, 255, 255, 0.1);
  box-shadow: none;
}

.character--selected {
  border: 1px solid white;
}

react-verification-input_style2

Example 2

.container {
  max-width: 350px;
}

.character {
  background-color: rgba(255, 255, 255, 0.8);
  border: none;
  border-radius: 8px;
  color: black;
  margin-left: 8px;
  box-shadow: inset 0 0 2px black;
  
  &:nth-child(4) {
    margin-left: 24px;
  }
}

.character--inactive {
  background-color: rgba(0, 0, 0, 0.5);
  box-shadow: none;
}

.character--selected {
  color: black;
  outline: red 2px;
  background-color: white;
}

react-verification-input_style1

Contributing

If you want to contribute, feel free to do so. I'd very much appreciate that.❀️ Just keep it consistent and I'm very happy to review your PR.

FAQs

Package last updated on 01 Jul 2018

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