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

otp-grid

v1.0.1

Published

A lightweight and customizable **React OTP input component** for building verification flows such as **login OTP, email verification, and 2FA**.

Readme

otp grid

A lightweight and customizable React OTP input component for building verification flows such as login OTP, email verification, and 2FA.

otp-grid provides a simple, controlled OTP input with features like auto focus navigation, paste support, and keyboard handling while allowing developers full control over state.


✨ Features

  • 🔢 Numeric OTP input validation
  • ⌨️ Smart keyboard navigation
  • ⬅️ Backspace moves to previous input
  • 📋 Paste full OTP support
  • 🎯 Auto focus to next input
  • 🎨 Customizable styling
  • ⚡ Lightweight and dependency-free
  • 🧩 Fully controlled component

📦 Installation

npm install otp-grid

🚀 Basic Usage

"use client";
import { useState } from "react";
import OtpBox from "otp-grid";

export default function Example() {
  const [otp, setOtp] = useState(Array(6).fill(""));

  return (
    <div>
      <OtpBox length={6} otp={otp} setOtp={setOtp} />

      <button onClick={() => console.log(otp.join(""))}>
        Verify OTP
      </button>
    </div>
  );
}

⚙️ Props

| Prop | Type | Default | Description | | -------- | ------------------------------------ | -------- | ---------------------------------------- | | length | number | 6 | Number of OTP input fields | | theme | string | "gray" | Custom Tailwind or CSS class for styling | | otp | string[] | required | OTP state array | | setOtp | Dispatch<SetStateAction<string[]>> | required | State setter for updating OTP |


🎨 Styling

You can customize the input appearance using the theme prop.

Example with Tailwind:

<OtpBox
  length={4}
  theme="border-amber-500 focus:ring-amber-500"
  otp={otp}
  setOtp={setOtp}
/>

Default input styles:

  • Center aligned text
  • Fixed width and height
  • Focus ring support

📋 Paste Support

Users can paste the full OTP directly into the first input.

Example:

123456

The component will automatically distribute the digits across all input fields.


⌨️ Keyboard Behavior

| Key | Behavior | | ----------- | ---------------------------------------- | | Number keys | Fill current input | | Backspace | Clears input and moves to previous field | | Paste | Automatically fills OTP inputs |


🧠 Controlled Component Pattern

otp-grid is a controlled component, meaning the OTP state is managed by your application.

Example:

const [otp, setOtp] = useState(Array(6).fill(""));

To retrieve the OTP:

const finalOtp = otp.join("");

📂 Example UI

Typical OTP layout:

[ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ]

Used commonly for:

  • Login verification
  • Phone number verification
  • Two-factor authentication (2FA)
  • Email confirmation

🛠 Example with Enter Submit

useEffect(() => {
  const handleKey = (e: KeyboardEvent) => {
    if (e.key === "Enter") {
      console.log(otp.join(""));
    }
  };

  window.addEventListener("keydown", handleKey);

  return () => window.removeEventListener("keydown", handleKey);
}, [otp]);

🧩 Built With

  • React
  • TypeScript
  • Tailwind CSS compatible

📄 License

MIT


⭐ Contributing

Contributions, issues, and feature requests are welcome!

If you like this package, consider starring the repository


👨‍💻 Author

Created by Someswar Gorai