All Projects → soywod → React Pin Field

soywod / React Pin Field

Licence: bsd-3-clause
📟 React component for entering PIN codes.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Pin Field

React Intl Tel Input
Rewrite International Telephone Input in React.js. (Looking for maintainers, and PRs & contributors are also welcomed!)
Stars: ✭ 212 (+236.51%)
Mutual labels:  component, input
Ngx Lite
📦 A collection of lightweight Angular libraries in a single mono repo
Stars: ✭ 125 (+98.41%)
Mutual labels:  component, input
React Native Input Spinner
An extensible input number spinner component for react-native highly customizable. This component enhance a text input for entering numeric values, with increase and decrease buttons.
Stars: ✭ 155 (+146.03%)
Mutual labels:  component, input
Nouislider
noUiSlider is a lightweight, ARIA-accessible JavaScript range slider with multi-touch and keyboard support. It is fully GPU animated: no reflows, so it is fast; even on older devices. It also fits wonderfully in responsive designs and has no dependencies.
Stars: ✭ 5,127 (+8038.1%)
Mutual labels:  component, input
Vue Img Inputer
🏞 A graceful image type inputer / uploader
Stars: ✭ 548 (+769.84%)
Mutual labels:  component, input
Vue Picture Input
Mobile-friendly picture file input Vue.js component with image preview, drag and drop, EXIF orientation, and more
Stars: ✭ 862 (+1268.25%)
Mutual labels:  component, input
React Input Tags
React component for tagging inputs.
Stars: ✭ 10 (-84.13%)
Mutual labels:  component, input
Stf Vue Select
stf vue select - most flexible and customized select
Stars: ✭ 61 (-3.17%)
Mutual labels:  component, input
Apprun
AppRun is a JavaScript library for developing high-performance and reliable web applications using the elm inspired architecture, events and components.
Stars: ✭ 1,087 (+1625.4%)
Mutual labels:  component
React Qmap
💡react腾讯地图开源组件
Stars: ✭ 60 (-4.76%)
Mutual labels:  component
Svelte Input Mask
Input masking component for Svelte with simple API and rich customization
Stars: ✭ 56 (-11.11%)
Mutual labels:  input
Pc Optimization Hub
collection of various resources devoted to performance and input lag optimization
Stars: ✭ 55 (-12.7%)
Mutual labels:  input
Customui
Library to create custom UI's in MCPE 1.2+
Stars: ✭ 60 (-4.76%)
Mutual labels:  input
Checkview
An animated toggling Plus/Check button for Android
Stars: ✭ 56 (-11.11%)
Mutual labels:  component
Dzhtmltext
Delphi and Lazarus HTML Label component
Stars: ✭ 60 (-4.76%)
Mutual labels:  component
Uxcore Table
Table Component based on React
Stars: ✭ 55 (-12.7%)
Mutual labels:  component
Vue Maze
A Vue.js component of a simple maze game.
Stars: ✭ 55 (-12.7%)
Mutual labels:  component
Selectivity
Modular and light-weight selection library
Stars: ✭ 1,113 (+1666.67%)
Mutual labels:  component
Aura.input
Tools to describe HTML form fields and values.
Stars: ✭ 60 (-4.76%)
Mutual labels:  input
Region Picker
A region picker based on Vue and ElementUI.
Stars: ✭ 59 (-6.35%)
Mutual labels:  component

📟 React PIN Field Build Status codecov npm

React component for entering PIN codes.

gif

Live demo at https://react-pin-field.soywod.me.

Installation

yarn add react-pin-field
# or
npm install react-pin-field

Usage

import PinField from "react-pin-field"

Props

type PinFieldProps = {
  ref?: React.Ref<HTMLInputElement[]>
  length?: number
  validate?: string | string[] | RegExp | ((key: string) => boolean)
  format?: (char: string) => string
  onResolveKey?: (key: string, ref?: HTMLInputElement) => any
  onRejectKey?: (key: string, ref?: HTMLInputElement) => any
  onChange?: (code: string) => void
  onComplete?: (code: string) => void
} & React.InputHTMLAttributes<HTMLInputElement>

const defaultProps = {
  ref: {current: []},
  length: 5,
  validate: /^[a-zA-Z0-9]$/,
  format: key => key,
  onResolveKey: () => {},
  onRejectKey: () => {},
  onChange: () => {},
  onComplete: () => {},
}

Ref

You can control each inputs with the PIN field ref:

<PinField ref={ref} />

// Reset all inputs
ref.current.forEach(input => (input.value = ""))

// Focus one particular input
ref.current[2].focus()

Style

React PIN Field can be styled either with className or style. You can also use pseudo-classes :nth-of-type, :focus, :hover, :valid, :invalid

The classes -{index}, -focus, -success and -error have been deprecated (and are not used anymore) since the v1.1.0.

Length

Length of the code (number of characters to type). Default: 5.

Validate

The validator prop can be:

  • A string of allowed characters: abcABC123
  • A list of allowed chars: ["a", "b", "c", "1", "2", "3"]
  • A RegExp: /^[a-zA-Z0-9]$/
  • A function: (char: string) => boolean

Format

Function called just before adding a new char to the code. For example, to set the code to upper case: (char: string) => char.toUpperCase()

Events

  • onResolveKey: called when a char passes successfully the validate function
  • onRejectKey: the opposite of onResolveKey
  • onChange: called when the code changes
  • onComplete: called when the code has been fully filled

Examples

See the live demo.

Development

git clone https://github.com/soywod/react-pin-field.git
cd react-pin-field
yarn install

To start the development server:

yarn start

To build the lib:

yarn build

To build the demo:

yarn build:demo

Tests

Unit tests

Unit tests are handled by Jest (.test files) and Enzyme (.spec files).

yarn test:unit

End-to-end tests

End-to-end tests are handled by Cypress (.e2e files).

yarn start
yarn test:e2e
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].