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

@choice-ui/otp-input

v0.0.2

Published

A one-time password input component with customizable slots and separators

Readme

OTP Input

A one-time password input component for verification codes. Built on top of input-otp library with custom styling and compound component pattern.

Import

import { OtpInput } from "@choice-ui/react"

Features

  • Compound component pattern for flexible layout
  • Multiple visual variants (default, light, dark)
  • Disabled and invalid states
  • Customizable separators
  • Input pattern validation (numbers, alphanumeric)
  • Animated caret indicator
  • Keyboard and screen-reader friendly

Usage

Basic

<OtpInput maxLength={6}>
  <OtpInput.Group>
    <OtpInput.Slot index={0} />
    <OtpInput.Slot index={1} />
    <OtpInput.Slot index={2} />
  </OtpInput.Group>
  <OtpInput.Separator />
  <OtpInput.Group>
    <OtpInput.Slot index={3} />
    <OtpInput.Slot index={4} />
    <OtpInput.Slot index={5} />
  </OtpInput.Group>
</OtpInput>

Controlled

const [value, setValue] = useState("")

<OtpInput
  maxLength={6}
  value={value}
  onChange={setValue}
  onComplete={(code) => console.log("Complete:", code)}
>
  <OtpInput.Group>
    <OtpInput.Slot index={0} />
    <OtpInput.Slot index={1} />
    <OtpInput.Slot index={2} />
    <OtpInput.Slot index={3} />
    <OtpInput.Slot index={4} />
    <OtpInput.Slot index={5} />
  </OtpInput.Group>
</OtpInput>

Variants

<OtpInput variant="default" maxLength={4}>...</OtpInput>
<OtpInput variant="light" maxLength={4}>...</OtpInput>
<OtpInput variant="dark" maxLength={4}>...</OtpInput>

States

<OtpInput disabled maxLength={4}>...</OtpInput>
<OtpInput isInvalid maxLength={4}>...</OtpInput>

Input patterns

// Numbers only (default)
<OtpInput maxLength={6} inputMode="numeric" pattern={REGEXP_ONLY_DIGITS}>
  ...
</OtpInput>

// Alphanumeric
<OtpInput maxLength={6} inputMode="text" pattern={REGEXP_ONLY_CHARS}>
  ...
</OtpInput>

Custom separator

<OtpInput maxLength={6}>
  <OtpInput.Group>
    <OtpInput.Slot index={0} />
    <OtpInput.Slot index={1} />
    <OtpInput.Slot index={2} />
  </OtpInput.Group>
  <OtpInput.Separator>
    <span>•</span>
  </OtpInput.Separator>
  <OtpInput.Group>
    <OtpInput.Slot index={3} />
    <OtpInput.Slot index={4} />
    <OtpInput.Slot index={5} />
  </OtpInput.Group>
</OtpInput>

Props

OtpInput (Root)

interface OTPInputRootProps {
  /** Maximum number of characters */
  maxLength: number

  /** Current value */
  value?: string

  /** Callback when value changes */
  onChange?: (value: string) => void

  /** Callback when all slots are filled */
  onComplete?: (value: string) => void

  /** Visual style variant */
  variant?: "default" | "light" | "dark"

  /** Whether the input is disabled */
  disabled?: boolean

  /** Whether the input is in invalid state */
  isInvalid?: boolean

  /** Additional class for the container */
  className?: string

  /** Additional class for the hidden input */
  inputClassName?: string

  /** Input pattern for validation */
  pattern?: string

  /** Input mode for keyboard */
  inputMode?: "numeric" | "text"

  /** Children (groups, slots, separators) */
  children: ReactNode
}

OtpInput.Group

interface OTPInputGroupProps extends ComponentProps<"div"> {}

OtpInput.Slot

interface OTPInputSlotProps extends ComponentProps<"div"> {
  /** Index of this slot (0-based) */
  index: number
}

OtpInput.Separator

interface OTPInputSeparatorProps extends ComponentProps<"div"> {
  /** Custom separator content (default: "-") */
  children?: ReactNode
}

Styling

  • Uses Tailwind CSS via tailwind-variants in tv.ts
  • Customize using the className prop on each sub-component
  • Caret animation is bundled via CSS Module

Accessibility

  • Built on input-otp library with accessibility features
  • Proper keyboard navigation between slots
  • Screen reader compatible
  • Supports paste from clipboard

Best practices

  • Use appropriate inputMode for the expected input type
  • Provide visual feedback for invalid states
  • Use onComplete callback to trigger verification
  • Consider showing remaining attempts for verification codes