GithubHelp home page GithubHelp logo

sirajalam049 / react-code-input Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 40818419/react-code-input

1.0 1.0 1.0 9.51 MB

React component for entering and validating PIN code.

License: MIT License

JavaScript 95.79% HTML 3.19% CSS 1.03%

react-code-input's Introduction

react-code-input

React component for entering and validating PIN code.

CircleCI npm version codecov

Live example here

Installation

npm i --save react-code-input

Usage

Numeric input:

Numeric input

...
<ReactCodeInput type='number' fields={6} />
...

Text input:

Text input

...
<ReactCodeInput type='text' fields={6} />
...

Password input:

Password input

...
<ReactCodeInput type='password' fields={6} />
...

Numeric input with options:

Numeric input with options

import { reactCodeInput } from 'CodeInputField.scss'
...
const props = {
  className: reactCodeInput,
  inputStyle: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'lightskyblue',
    border: '1px solid lightskyblue'
  },
  inputStyleInvalid: {
    fontFamily: 'monospace',
    margin:  '4px',
    MozAppearance: 'textfield',
    width: '15px',
    borderRadius: '3px',
    fontSize: '14px',
    height: '26px',
    paddingLeft: '7px',
    backgroundColor: 'black',
    color: 'red',
    border: '1px solid red'
  }
}
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Usage with next.js

import dynamic from 'next/dynamic';

const ReactCodeInput = dynamic(import('react-code-input'));
...
<ReactCodeInput type='number' fields={6} {...props}/>
...

Props:

Property  Type Description
type string Only types like: text, number, password and tel are accepted.
fields number Allowed amount of characters to enter.
value string Setting the initial value of code input field.
name string Setting the name of component. 
onChange func Function, which is called whenever there is a change of value in the input box.
touch func Marks the given fields as "touched" to show errors. 
untouch func Clears the "touched" flag for the given fields. 
className string Add classname to the root element.
style object Setting the styles of container element.
inputStyle object Setting the styles of each input field.
inputStyleInvalid object Setting the styles of each input field if isValid prop is false.
isValid bool Returns true if an input element contains valid data. 
disabled bool When present, it specifies that the element should be disabled. 
autoFocus bool Setup autofocus on the first input, true by default. 
filterKeyCodes array Filter characters on key down.
filterChars array Filter characters.
pattern string The pattern prop specifies a regular expression that the element's value is checked against.
inputMode string The inputMode prop tells the browser on devices with dynamic keyboards which keyboard to display.

Compatible with

redux-form from erikras

next.js from zeit

License

MIT

react-code-input's People

Contributors

40818419 avatar a-tokyo avatar apastuhov avatar avdeev avatar chitezh avatar eugeniakaramanou avatar julia-lavrova avatar lmulvey avatar maxkramerbcgdv avatar rm-hull avatar roberthodgen avatar thmsmontana avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

underlostxyz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.