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

input-pincode

v1.0.5

Published

PINCODE Input WEB COMPONENT

Downloads

82

Readme

Input Pincode Web Component

input code image.

The input-pincode is a customizable web component designed to capture multi-character input such as a PIN code. It supports various customization options like length, only-numbers mode, initial focus, and error handling.

Keyboard Navigation

Backspace: Deletes the content of the current input and moves to the previous input. Arrow Keys: Navigate between the input fields. Enter: Triggers the onEnter event if the pincode is completed.

Pasting Functionality

You can paste a pincode (e.g., 1234) directly into the component, and the input fields will automatically be populated.

Props

| Prop | Type | Default | Description | |-----------------------|---------|---------|-----------------------------------------------------------------------------------------------| | length | Number | 4 | The number of input fields, i.e., the number of characters the PIN accepts. | | initializeInputFocus | Boolean | true | Automatically sets focus on the first input when the component is mounted. | | onlyNumbers | Boolean | true | Restricts the input fields to accept only numeric characters. | | disabled | Boolean | false | Disables the pincode input fields. | | hasError | Boolean | false | Indicates whether the pincode is in an error state; when true, it displays an error style. | | placeholder | String | '' | Placeholder character for each input field, displayed as a single character in each field. |

Installation

Install via npm or yarn:

npm install input-pincode

Or with yarn:

yarn add input-pincode

Usage

Include the web component in your HTML or React project:

HTML

<input-pincode length="4" only-numbers initialize-input-focus></input-pincode>

REACT

import { InputPincode } from 'input-pincode/react';

<InputPincode length={4} onlyNumbers={true} initializeInputFocus={true} />

Events

Change: Dispatched when the value of the pincode changes. The event details include the isCompleted and value properties:

Enter: Fired when the Enter key is pressed, dispatching the pincode value and its completion status.

element.addEventListener('Change', (e) => {
    const { isCompleted, value } = e.detail;
    console.log('Pincode is complete:', isCompleted);
    console.log('Pincode value:', value);
});

API

General CSS Customization

You can customize the appearance of the entire component by modifying the default variables. These variables affect the overall look of the pincode input fields, regardless of their state.

In addition to the default variables, you can customize the appearance of the component for specific states: valid, has-error, and disabled. Each state has a corresponding variable suffix, such as --valid, --has-error, or --disabled, allowing for more granular control over the styles.

List of CSS Variables

| Variable | Default Value | Description | |---------------------------------------------|-----------------------------|---------------------------------------------------------------| | --wc-input-pincode-container--gap | none | Gap between input fields. | | --wc-input-pincode-container--justify-content | space-between | Justify content setting for the input fields container. | | --wc-input-pincode--padding | 0 | Padding inside the pincode input field. | | --wc-input-pincode--margin | 0% | Margin around the pincode input field. | | --wc-input-pincode--font-weight | 600 | Font weight of the text inside the input. | | --wc-input-pincode--outline | 0px | Outline width of the input when focused. | | --wc-input-pincode--border-width | 1.5px | Width of the border surrounding the input. | | --wc-input-pincode--border-style | solid | Border style of the input. | | --wc-input-pincode--border-radius | 0.5rem | Border radius of the input field. | | --wc-input-pincode--border-color | #d9d9d9 | Border color of the input field. | | --wc-input-pincode--height | 3.81rem | Height of each pincode input field. | | --wc-input-pincode--width | 3.63rem | Width of each pincode input field. | | --wc-input-pincode--text-color | #21272a | Text color of the input content. | | --wc-input-pincode--background | transparent | Background color of the input field. | | --wc-input-pincode--font-size | 2rem | Font size of the text inside the input. | | --wc-input-pincode--font-family | 'Montserrat', sans-serif | Font family of the text inside the input. | | --wc-input-pincode--line-height | 2.5rem | Line height of the text inside the input. |

State-Specific Variables

Valid State (--valid)

| Variable | Default Value | Description | |------------------------------------------------|-----------------------------|---------------------------------------------------------------| | --wc-input-pincode--border-color--valid | #0079c8 | Border color when the input is valid. | | --wc-input-pincode--padding--valid | Same as default | Padding inside the input field when valid. | | --wc-input-pincode--font-size--valid | Same as default | Font size when the input is valid. | ... etc

Error State (--has-error)

| Variable | Default Value | Description | |------------------------------------------------|-----------------------------|---------------------------------------------------------------| | --wc-input-pincode--border-color--has-error | #d60023 | Border color when the input is in error state. | | --wc-input-pincode--padding--has-error | Same as default | Padding inside the input field when there is an error. | | --wc-input-pincode--background--has-error | Same as default | Background color when the input is in error state. | ...etc

Disabled State (--disabled)

| Variable | Default Value | Description | |------------------------------------------------|-----------------------------|---------------------------------------------------------------| | --wc-input-pincode--border-color--disabled | #d9d9d9 | Border color when the input is disabled. | | --wc-input-pincode--background--disabled | #f8f8f8 | Background color when the input is disabled. | ...etc

Usage Example

Default Customization

input-pincode {
    --wc-input-pincode--border-color: #0000ff;
    --wc-input-pincode--font-size: 1.5rem;
}

State-Specific Customization

input-pincode {
    --wc-input-pincode--border-color--valid: #00ff00;
    --wc-input-pincode--border-color--has-error: #ff0000;
}

With these options, you can fully customize the appearance and behavior of the input-pincode component based on its state (valid, error, disabled), or modify the default styles for a more consistent look.