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 🙏

© 2025 – Pkg Stats / Ryan Hefner

react-custom-passcode

v1.0.0

Published

Fully flexible and customisable passcode fields for one-time passcodes.

Downloads

3

Readme

React Custom Passcode

Fully flexible and customisable passcode fields for one-time passcodes.

Installation

npm install react-custom-passcode

Usage

To start off with an example of a basic passcode component that renders 4 separate character passcode fields:

import { Passcode } from 'react-custom-passcode'

const PasscodeScreen = () => {
  return (
    <Passcode fields={4} />
  )
}

Documentation

The available props are outlined below:

| Prop | Usage | Description |--|--|--| | fields | number or array: [{ name: string, id: string }] | Required | | defaultValue | string | Autofills the passcode fields | | name | string | Prefix with custom name, [<index>] will be appended, e.g. field[0] | id | string | Similar behaviour as name, but for the id attribute. Appends -<index>, e.g. field-0 | renderer | JSX component | See below usage on custom styling | type | text, numeric, alphanumeric | Restricts the type of characters to be inserted in the fields | autoFocus | boolean | Defaults to false. If set to true, then the first field will be auto-focused. | autoTab | boolean | Defaults to true. Automatically tabs to the next field when the previous one was filled. | required | boolean | Defaults to true. Sets the field required attribute. | onUpdate | Function | Custom callback function. See below usage on the callback

Custom styling

Since the fields on basic level, come unstyled and are just returned with pure input fields, you may want to introduce some custom wrapping of elements and styling. You can do that by passing a custom renderer prop. Example:

const CustomInput = ({ index, ...inputProps }: FieldPropsWithIndex) => {
  return (
    <div class="field-wrapper">
      <div className="field-wrapper-inner">
        {/* you should spread in the props that are controlled by the package to avoid losing functionality */}
        <input {...inputProps} className="passcode-field" />
      </div>
    </div>
  )
}

const PasscodeScreen = () => {
  return (
    <Passcode fields={4} renderer={CustomInput} />
  )
}

Passcode update callback

Whenever the passcode fields are updated, or if a paste occurred. The onUpdate callback will be invoked with these arguments:

  • code - string - The current passcode as it is
  • index - number or undefined - The index of the field that was updated. This will be undefined when a paste was done.

Example:

const PasscodeScreen = () => {
  return (
    <Passcode fields={4} onUpdate={(code, index) => {
      console.log('Current passcode', code)
    }} />
  )
}

Custom event handlers

The passcode fields have their onChange, onBlur and onPasteCapture handled by the library, if you need to pass in custom event handlers, you can pass in your own handlers. If you do not invoke the original handlers, then you will lose the controlled functionality. Example:

const CustomInput = ({ index, ...inputProps }: FieldPropsWithIndex) => {
  return (
    <input {...inputProps} onChange={event => {
      // your own handling
      console.log('onChange was fired')
     
      // Invoke the original onChange handler
      inputProps.onChange(event)
    }} />
  )
}

const PasscodeScreen = () => {
  return (
    <Passcode fields={4} renderer={CustomInput} />
  )
}