1.0.4 • Published 4 years ago

react-pin-code-input-component v1.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

Agenda

I found many solution for pin code component but every of them has two problems.

  • The first problem is that they are not reusable. What a large number of libraries solves a specific problem. I have also written a large number of props (and continued). See example below.
  • Second problem they all use references but at 90% times they aren't use useRef instead of React.createRef (i found the better solution without it)

Instalation

npm i react-pin-code-input-component
or
yarn add react-pin-code-input-component

Peer dependecies

This library needs two additional libraries. Namely:

  • prop-types (temporarily, later will support the typscript)
  • classnames.

Available Props

Props NametypeDefault ValueWhat's doing
spacesAreAllowedbooleanfalseNot allow space's type and stick data on remove value event.
touchfunction() => (cb) => cb)Marks the given fields as "touched" to show errors.
untouchfunction() => (cb) => cb)Clears the "touched" flag for the given fields.
filterCharsarray"-", "."Filter characters.
filterKeyCodesarray189, 190Filter characters on key down.
valuestring""Default value which gonna be in input. By default is empty.
forceUppercasebooleanfalseSet true if you need only upper case chars.
fieldsnumber4Allowed amount of characters to enter.
disabledbooleanfalseWhen present, it specifies that the element should be disabled.
isValidbooleantrueReturns true if an input element contains valid data.
autoFocusbooleantrueSetup autofocus on the first input, true by default.
typetext, number, password, tel
onChangefunchandleChange(e)Function, which is called whenever there is a change of value in the input box.
namestring""Setting the name of component.
classNamestring""Add className to the root element.
styleobjectSetting the styles of container element.
inputStyleobjectSetting the styles of each input field.
inputStyleInvalidobjectSetting the styles of each input field if isValid prop is false.
patternstringThe pattern prop specifies a regular expression that the element's value is checked against.
inputModestringlatin, latin-name, latin-prose, etc.

Example of usage

import React from "react";
import PinCode from "react-pin-code-input-component";

import "./App.css";

function App() {
  return (
    <div className="App">
      <PinCode type="text" fields="7" value="noSpace" />
      />
    </div>
  );
}

export default App;

That code returns us pin code component with seven inputs which applyed any chars but cannot hold space inside.

1.0.2

4 years ago

1.0.1

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago