npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-otp-input-pro

v1.0.0

Published

Reusable OTP input component for React

Readme

React OTP Input Pro

A reusable, customizable, and easy-to-use OTP (One-Time Password) input component for React.
Supports numeric, text, or alphanumeric inputs, input shapes, custom focus/error styles, auto-resend timer, and validation.


Features

  • Dynamic OTP length (default 6)
  • Custom input type: number, text, alphanumeric
  • Custom shapes: square, rounded, circle or custom borderRadius
  • Focus and error styling
  • Auto-clear on resend
  • Resend timer button (editable inputs while timer runs)
  • Disabled mode

Installation

npm install react-otp-input-pro

Development/Local Linking

For local development using npm link:

  1. In the package directory:

    npm run build
    npm link
  2. In your consuming project:

    npm link react-otp-input-pro
  3. Important: If you're using Vite in your consuming project, add this to your vite.config.js to prevent build errors:

    import { defineConfig } from 'vite';
    import react from '@vitejs/plugin-react';
    
    export default defineConfig({
      plugins: [react()],
      optimizeDeps: {
        exclude: ['react-otp-input-pro']
      },
      resolve: {
        dedupe: ['react', 'react-dom']
      }
    });

    This prevents Vite from trying to process the linked package and resolves React version conflicts.

Usage Example

import React, { useState } from "react";
import OtpInput from "react-otp-input-pro";

function App() {
  const [otp, setOtp] = useState("");
  const [isWrong, setIsWrong] = useState(false);

  const handleResend = () => {
    alert("OTP resent!");
    setOtp(""); // Clear OTP input
  };

  return (
    <div>
      <h2>Reusable OTP Component</h2>
      <OtpInput
        length={6}
        type="number"
        shape="rounded"
        cornerRadius="50%"
        value={otp}
        onChangeOtp={setOtp}
        hasError={isWrong}
        focusColor="#007bff"
        errorColor="red"
        disabled={false}
        resendTime={30}
        onResend={handleResend}
      />
      <h3>Real OTP: {otp}</h3>
    </div>
  );
}

export default App;


##Validation Rules

Number: Only digits 0-9

Text: Only letters a-zA-Z

Alphanumeric: Letters and numbers only a-zA-Z0-9

Invalid characters are automatically ignored.


###Resend Timer Behavior

Resend button is disabled for resendTime seconds after clicking.
OTP input boxes remain editable while the timer runs.
You can reset OTP manually in the onResend callback using onChangeOtp("").

###Customization
Input Shape: via shape (square/rounded/circle) or cornerRadius ("50%", "8px", etc.)
Focus Color: via focusColor prop
Error Color: via errorColor prop
Disabled State: via disabled prop

## Props Reference

| Prop          | Type             | Default     | Description |
|---------------|-----------------|------------|------------|
| `length`      | `number`         | `6`        | Number of OTP input boxes. |
| `type`        | `string`         | `"number"` | Type of input: `"number"`, `"text"`, or `"alphanumeric"`. |
| `shape`       | `string`         | `"square"` | Shape of input boxes: `"square"`, `"rounded"`, `"circle"`. |
| `cornerRadius`| `string`/`number`| -          | Custom border-radius (overrides `shape`). Accepts pixels (`"8px"`) or percentage (`"50%"`). |
| `focusColor`  | `string`         | `"#000"`   | Border color when input is focused. |
| `errorColor`  | `string`         | `"red"`    | Border color when `hasError` is true. |
| `value`       | `string`         | `""`       | Current OTP value. |
| `onChangeOtp` | `function`       | -          | Callback fired on OTP change. Receives the updated OTP as an argument. |
| `hasError`    | `boolean`        | `false`    | If `true`, shows error styling on inputs. |
| `disabled`    | `boolean`        | `false`    | Disables the OTP inputs when `true`. |
| `resendTime`  | `number`         | `0`        | Duration in seconds for which the resend button is disabled. |
| `onResend`    | `function`       | -          | Callback fired when the resend button is clicked. |


##Example
<OtpInput
  length={4}
  type="alphanumeric"
  shape="circle"
  focusColor="#28a745"
  errorColor="#dc3545"
  value={otp}
  onChangeOtp={setOtp}
  hasError={false}
  resendTime={15}
  onResend={() => console.log("OTP Resent!")}
/>


## License

MIT © Deepak Pradhan

This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.