UNPKG

react-easy-otp

Version:

A lightweight and customizable OTP input component built with React and no dependencies.

55 lines (40 loc) โ€ข 1.53 kB
# React Easy OTP A lightweight, dependency-free OTP (One-Time Password) input component built with React and Parcel. ## โœ… Features - ๐Ÿ”ข Configurable number of input boxes - ๐Ÿš€ Auto focus and move to next input - โฑ Auto submit when all fields are filled - โŒ Backspace support to focus previous - ๐Ÿงช Regex validation per input - ๐ŸŽจ Custom separators and styling - ๐ŸŸข Success/Error styling --- ## ๐Ÿ“ Folder Structure ## ๐Ÿ›  Setup Instructions ### 1. Clone and install dependencies ```bash npm install react-easy-otp ``` | Prop | Type | Description | | ------------ | -------- | ------------------------------------ | | `numInputs` | `number` | Number of OTP boxes (default: 4) | | `autoSubmit` | `bool` | Auto trigger when all fields filled | | `type` | `string` | Input type (`text` or `number`) | | `separator` | `string` | Separator between inputs (e.g., `-`) | | `onChange` | `func` | Callback with full OTP string | | `inputClass` | `string` | Custom className for inputs | | `regex` | `RegExp` | Validation regex for each input box | | `success` | `bool` | If true, green border | | `error` | `bool` | If true, red border | # ๐Ÿงช Example Usage (App.js) ```bash <OtpInput numInputs={6} autoSubmit={false} type="number" separator="-" onChange={(val) => console.log("OTP:", val)} /> ``` ## ๐Ÿงผ License MIT