react-easy-otp
Version:
A lightweight and customizable OTP input component built with React and no dependencies.
55 lines (40 loc) โข 1.53 kB
Markdown
# 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