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-auth-code-input

v3.2.1

Published

One-time password (OTP) React input component, uncontrolled, zero dependencies, fully tested.

Downloads

212,100

Readme

image

React Auth Code Input

One-time password (OTP) React component, zero dependencies, fully tested.

NPM JavaScript Style Guide Software License npm npm GitHub actions state

Demo

Demo

Install

npm install --save react-auth-code-input

or

yarn add react-auth-code-input

Version 3+

Basic Usage

import React, { useState } from 'react';
import AuthCode from 'react-auth-code-input';

const App = () => {
  const [result, setResult] = useState();
  const handleOnChange = (res: string) => {
    setResult(res);
  };

  return <AuthCode onChange={handleOnChange} />;
};

Mode

By default you can type numbers and letters in the inputs as the allowedCharacters prop is defaulted to alphanumeric but you can also choose between allowing only letters or only numbers by setting the prop to alpha or numeric respectively.

import React, { useState } from 'react';
import AuthCode from 'react-auth-code-input';

const App = () => {
  const [result, setResult] = useState();
  const handleOnChange = (res: string) => {
    setResult(res);
  };

  return <AuthCode allowedCharacters='numeric' onChange={handleOnChange} />;
};

Focus

By default the first input is focused when the component is mounted, you can opt-out from this by setting the autoFocus prop to false, and then you can handle the focus manually by passing a reference.

import React, { useRef, useState } from 'react';
import AuthCode, { AuthCodeRef } from 'react-auth-code-input';

const App = () => {
  const AuthInputRef = useRef<AuthCodeRef>(null);
  const [result, setResult] = useState();
  const handleOnChange = (res: string) => {
    setResult(res);
  };

  return (
    <>
      <AuthCode
        autoFocus={false}
        onChange={handleOnChange}
        ref={AuthInputRef}
      />
      <button onClick={() => AuthInputRef.current?.focus()}>Focus</button>
    </>
  );
};

Clear

You can clear all the inputs by passing a reference and then calling the clear method.

import React, { useRef, useState } from 'react';
import AuthCode, { AuthCodeRef } from 'react-auth-code-input';

const App = () => {
  const AuthInputRef = useRef<AuthCodeRef>(null);
  const [result, setResult] = useState();
  const handleOnChange = (res: string) => {
    setResult(res);
  };

  return (
    <>
      <AuthCode onChange={handleOnChange} ref={AuthInputRef} />
      <button onClick={() => AuthInputRef.current?.clear()}>Clear</button>
    </>
  );
};

SMS Autofill

This component supports autofill from SMS's received, tested on Safari and Chrome in iOS.

Props

| Prop | Type | Description | Default Value | Observations | | :------------------- | :---------------------- | :---------------------------------------------------------- | :------------- | :----------------------------------------------- | | allowedCharacters | String | Type of allowed characters for your code. | alphanumeric | Valid values: alpha, alphanumeric, numeric | | ariaLabel | String | Accessibility. | | | | autoFocus | Boolean | Wether the first input is focused on mount or not.. | true | Since version 3.1.0 | | length | Number | The number of inputs to display. | 6 | | | containerClassName | String | The styles to be applied to the container. | | | | inputClassName | String | The styles to be applied to each input. | | | | onChange | Function(value: String) | Callback function called every time an input value changes. | | Required | | isPassword | Boolean | Whether to display the inputs as passwords or not. | false | | | disabled | Boolean | Makes all the inputs disabled if true. | false | Since version 3.1.1 | | placeholder | String | Displays a placeholder in all the inputs. | | Since version 3.2.0 |

Changelog

3.2.1

  • Fix allowing non-numeric characters being introduced in numeric mode on Safari and Firefox.

3.2.0

  • Add placeholder prop.
  • Export component props.

3.1.0

  • Add disabled prop to disable all the inputs.
  • Make the backspace delete the previous character if the current is empty. Previously it just moved the focus making the user hit twice the backspace to delete the value.

3.1.0

  • Add autoFocus prop set to true by default to not break current usages.
  • Expose a focus method using references to handle the focus of the first input manually.
  • Expose a clear method using references to clear the input programmatically.
  • Add validations for when not using typescript.
  • Update React peerDependency to use any version 16+.

3.0.0

  • Change the way the allowed characters are handled by using 3 predefined modes: alpha, alphanumeric, and numeric, allowing to have more control when validating the values introduced in the inputs.
  • Improved logic.
  • Improved tests.
  • Improved types.

License

Licensed under the MIT License, Copyright © 2020-present Luis Guerrero drac94.

See LICENSE for more information.