A React Component for inputting Auth Codes inspired in Apple Two-Factor Authentication UI. You can type, paste and move backwards using the backspace.
npm install --save react-auth-code-input
or
yarn add react-auth-code-input
import React, { useState } from 'react';
import AuthCode from 'react-auth-code-input';
const App = () => {
const [result, setResult] = useState('');
const handleOnChange = (res: string) => {
setResult(res);
};
return (
<AuthCode
characters={5}
onChange={handleOnChange}
containerClassName='container'
inputClassName='input'
/>
);
};
Prop | Type | Description | Default Value | Observations |
---|---|---|---|---|
allowedCharacters |
String | Regex for allowed characters | ^[A-Za-z0-9] |
|
characters |
Number | The number of inputs to display | 6 | |
containerClassName |
String | The styles to be applied to the container | ||
inputClassName |
String | The styles to be applied to each input | ||
inputType |
String | The type of the inputs | text | text, number or password |
onChange |
Function(value: String) | Callback function called every time an input value changes | ||
password |
Boolean | If present changes the type of the input to password, by default is set to text | false | deprecated since version 2.0.0 |
inputStyle |
Object | The styles to be applied to each input | deprecated since version 1.2.0 | |
containerStyle |
Object | The styles to be applied to the container | deprecated since version 1.2.0 |
- Remove
inputStyle
prop in favor ofinputClassName
. - Remove
containerStyle
prop in favor ofcontainerClassName
. - Remove
password
prop in favor ofinputType
which accepts text, password or number value.
- Add missing dist files.
- Add
inputClassName
andcontainerClassName
props. - Deprecate
inputStyle
andcontainerStyle
. - Make
onChange
prop mandatory.
- Typescript support.
- Initial Version.
Licensed under the MIT License, Copyright © 2020-present Luis Guerrero drac94.
See LICENSE for more information.