1.0.5 • Published 4 years ago

@onefifteen-z/react-input-otp v1.0.5

Weekly downloads
156
License
MIT
Repository
github
Last release
4 years ago

react-input-otp

NPM JavaScript Style Guide

Install

npm install --save @onefifteen-z/react-input-otp

Usage

Example

import React, { Component } from 'react';

import InputOtp from '@onefifteen-z/react-input-otp';

export default class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      otpCode: '',
    };
  }

  render () {
    const handleChange = otpCode => {
      this.setState({ otpCode });
    };

    return (
      <InputOtp onChange={handleChange} value={this.state.otpCode} />
    )
  }
};

Properties

NameTypeDefaultDescription
otpLengthnumber6Number of OTP length
numberOnlyboolfalseRestrict to digit only (only valid when pattern is null)
typestring'tel'type property of <input> eg. password
patternRegExpnullPattern of characters available to the inputs
disabledboolfalseDisable all the inputs
errorboolfalseWhether has error in OTP inputted
errorMessagestringnullError messaged showed when error is true
onChangefunc() => {}Return OTP value
autoFocusboolfalseAuto focus on the first OTP input
valuestring''Default value
wrapperClassstringstyles.otpWrapperClass appended to the whole wrapper
inputWrapperClassstringstyles.otpInputWrapperClass appended to the wrapper of inputs
inputClassstringstyles.otpInputClass appended to the inputs
errorMessageClassstringstyles.errorMessageClass appended to the error message

Development

To run the development server:

npm start # runs rollup with watch flag

To run the example:

cd example
npm start

Contributing

Feel free to open issues and pull requests.

License

NPM

MIT © onefifteen-z