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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-web-otp

v1.0.4

Published

The react-web-otp is designed to enhance user authentication experiences in React applications by providing a flexible and customizable one-time password (OTP) input field. This component supports various input types including "number", "text", and "passw

Downloads

17

Readme

React Web OTP

A Customizable OTP Input Component for React

React Web OTP is a customizable OTP (One-Time Password) input component for React applications, designed to enhance user authentication experiences.

Features

  • Supports various input types: number, text, and password
  • Customizable input fields
  • Auto-focus and auto-tab between inputs
  • Clipboard paste handling with validation
  • Custom styles for input fields

And of course, React Web OTP itself is open source with a public repository on GitHub.

Installation

React Web OTP requires Node.js v10+ to run.

Install the package via npm:

npm install react-web-otp

Or via yarn:

yarn add react-web-otp

Usage

Here's an example of how to use the OTPInput component in your React application:

import React from 'react';
import OTPInput from 'react-web-otp';

const App = () => {
  const handleSubmit = (otp) => {
    console.log('Submitted OTP:', otp);
  };

   const customSeperator = (props) => {
    return <span {...props}>#</span>;
  };

  return (
    <div>
      <h1>Enter your OTP</h1>
      <span>With Prefix</span>
      <br />
      <OTPInput
        length={6}
        onSubmit={handleSubmit}
        autoFocus
        otpType="number"
        customStyle={{ border: "1px solid #ccc", borderRadius: "4px" }}
        includePrefix
        prefix={"H"}
        seperator={"-"}
        separatorInterval={2}
      />

      <br />
      <span>Prefix with seperator</span>
      <br />
      <OTPInput
        length={6}
        onSubmit={handleSubmit}
        autoFocus
        otpType="number"
        customStyle={{ border: "1px solid #ccc", borderRadius: "4px" }}
        includePrefix
        prefix={"H"}
        seperator={"-"}
        separatorInterval={[0, 2]}
      />

      <br />
      <span>With out Prefix</span>
      <br />
      <OTPInput
        length={6}
        onSubmit={handleSubmit}
        seperator={customSeperator}
        separatorInterval={[2, 3]}
      />
    </div>
  );
};

export default App;

Props API

The OTPInput component accepts the following props: Prop Name| Type| Default| Description


| Prop Name | Type | Default | Description | | ----------------- | --------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | length | number | 4 | The number of OTP input fields. | | onSubmit | func | (otp) => console.log({ otp }, "Please send the onSubmit props to OTPInput to handle the otp") | Function to handle the OTP submission. | | autoFocus | bool | false | If true, the first input field will be focused automatically. | | otpType | string | text | The type of OTP input, can be one of "number", "text", "password". | | renderInput | func | ({ key, ...restProps }) => <input key={key} {...restProps} /> | Custom render function for the input fields. | | customStyle | object | {} | Custom styles to apply to each input field. | | includePrefix | boolean | false | If the includePrefix is true then the otp returned from the onSubmit function will include the prefix | | prefix | string | "" | The prefix length should not exceed 1 if it exceed more than 1 then the last value is taken if prefix = 'HG' then the prefix will be G | | seperator | string or react component | "" | if the type of seperator is string then the length should be 1 if it exceeded by 1 then then the last character of the string will be used as a seperator. we can also send the seperator as a react component (props) => { return <span {...props}>@123</span>} | | separatorInterval | number or number[] | "" | the seperatorInterval can be either string or array of strings. If separatorInterval is number then the seperator will render with that interval and if the separatorInterval is array of numbers then the seperator will render by each number in the array |

Development

React Web OTP uses a simple React setup for development. Make changes in your file and instantaneously see your updates!

Open your favorite Terminal and run these commands.

npm start

License

ISC