Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zag-js/pin-input

Package Overview
Dependencies
Maintainers
1
Versions
1041
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zag-js/pin-input

Core logic for the pin-input widget implemented as a state machine

  • 0.0.0-dev-20240708161145
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
137K
increased by5.7%
Maintainers
1
Weekly downloads
 
Created

What is @zag-js/pin-input?

@zag-js/pin-input is a package that provides a set of utilities to create accessible and customizable pin input components. It is part of the Zag.js library, which focuses on building state machines for UI components. This package allows developers to easily implement pin input fields with features like validation, focus management, and more.

What are @zag-js/pin-input's main functionalities?

Basic Pin Input Setup

This code demonstrates how to set up a basic pin input component using the @zag-js/pin-input package. It uses the `usePinInput` hook to manage the state and behavior of the pin input fields. The `getInputProps` function is used to spread the necessary props onto each input element, ensuring they are correctly managed.

import { usePinInput } from '@zag-js/pin-input';

const PinInputComponent = () => {
  const { inputProps, getInputProps } = usePinInput({
    id: 'pin-input',
    onComplete: (value) => console.log('Pin complete:', value),
  });

  return (
    <div>
      <input {...getInputProps({ index: 0 })} />
      <input {...getInputProps({ index: 1 })} />
      <input {...getInputProps({ index: 2 })} />
      <input {...getInputProps({ index: 3 })} />
    </div>
  );
};

Custom Validation

This example shows how to implement custom validation logic in a pin input component. The `validate` function checks if the entered pin is exactly 4 digits long and consists only of numbers. The `onComplete` callback is triggered when a valid pin is entered.

import { usePinInput } from '@zag-js/pin-input';

const PinInputWithValidation = () => {
  const { inputProps, getInputProps } = usePinInput({
    id: 'pin-input',
    validate: (value) => value.length === 4 && !isNaN(Number(value)),
    onComplete: (value) => console.log('Valid pin:', value),
  });

  return (
    <div>
      <input {...getInputProps({ index: 0 })} />
      <input {...getInputProps({ index: 1 })} />
      <input {...getInputProps({ index: 2 })} />
      <input {...getInputProps({ index: 3 })} />
    </div>
  );
};

Other packages similar to @zag-js/pin-input

Keywords

FAQs

Package last updated on 08 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc