Giter VIP home page Giter VIP logo

react-otp-input's Introduction

react-otp-input

npm version npm npm All Contributors

A fully customizable, one-time password input component for the web built with React.

see here

Live Demo

CodeSandbox

Installation

NPM

To install the latest stable version:

npm install --save react-otp-input

Basic usage:

import React, { Component } from 'react';
import OtpInput from 'react-otp-input';

export default class App extends Component {
  state = { otp: '' };

  handleChange = (otp) => this.setState({ otp });

  render() {
    return (
      <OtpInput
        value={this.state.otp}
        onChange={this.handleChange}
        numInputs={6}
        separator={<span>-</span>}
      />
    );
  }
}

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.
value string / number true '' The value of the OTP passed into the component.
placeholder string false none Specify an expected value of each input. The length of this string should be equal to numInputs.
separator component
false none 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.
hasErrored 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 initial page load.
isInputNum boolean false false Restrict input to only numbers.
isInputSecure boolean false false Masks input characters.
data-cy string false - Test attribute passed to the inputs.
data-testid string false - Test attribute passed to the inputs.

Breaking changes when porting to v1.0.0

react-otp-input is now a controlled component to facilitate functionalities that weren't possible before from the application using it, such as clearing or pre-assigning values. For v1.0.0 and above, a value prop needs to be passed in the component for it to function as expected.

Development

To run the development server:

npm run dev

Checklist

PRs Welcome Open Source Love

  • Add flowtypes
  • Add ESLint, Prettier for code quality
  • Add styling support for states including focus/disabled
  • Write tests

Contributing

GitHub issues GitHub pull requests

Feel free to open issues and pull requests!

License

NPM

Contributors โœจ

Thanks goes to these wonderful people (emoji key):


Abhishek Warokar

๐Ÿ’ป ๐ŸŽจ ๐Ÿšง ๐Ÿค” ๐Ÿ‘€

Aj

๐Ÿ’ป ๐ŸŽจ ๐Ÿค”

Aromal Anil

๐Ÿ’ป ๐Ÿ”ง

Gabriele Corti

๐Ÿ’ป ๏ธ๏ธ๏ธ๏ธโ™ฟ๏ธ

Anoop

๐Ÿ’ป

Dewansh Rawat

๐Ÿ›

Ishan Chhabra

๐Ÿ’ป

yaojie

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

react-otp-input's People

Contributors

ajayns avatar apollonian avatar dependabot[bot] avatar aromalanil avatar allcontributors[bot] avatar vinitshahdeo avatar ishan-chhabra avatar parikshit-hooda avatar borntofrappe avatar utkarsh22garg avatar binu42 avatar ferdox2 avatar blenderskool avatar nikhilgupta30 avatar ctrlaltdylan avatar dhruvmisra avatar akashnimare avatar causztic avatar nestoralonso avatar mon53r avatar vishalpolley avatar vishalpolley-sureify avatar surajv311 avatar shubhankarkg avatar saisrinivaspaila avatar robintom avatar rishabh510 avatar pratik-276 avatar nirmalhk7 avatar michizhou avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.