Giter VIP home page Giter VIP logo

input-mask-react's Introduction

๐Ÿ”ฅ input-mask-react

In an extremely simple way, apply input masks to your React project.


๐Ÿš€ About

input-mask-react is a package for react that was created with the purpose of facilitating software development. Applying input masks is a common and often repetitive task, come to think of it, input-mask-react makes this process simpler for you.

๐Ÿ›  Get Started

install the input-mask-react

npm install input-mask-react

Import the package

import { InputMask } from 'input-mask-react'

Example of use

The example below shows how to create a Brazilian phone mask. See that for the mask to be applied, inform the index and which character you want to add, and that's it, now you have an input mask!

function App() {
  const inputRef = useRef(null)

  return (
    <InputMask
      ref={inputRef}
      maxLength={19}
      placeholder='+55 (12) 98765-4321'
      cb={(event) => console.log(event)}
      masks={[
        { index: 0, character: '+' },
        { index: 3, character: ' ' },
        { index: 4, character: '(' },
        { index: 7, character: ')' },
        { index: 8, character: ' ' },
        { index: 14, character: '-' },
      ]}
    />
  )
}

export default App

Description of properties

Prop Required Type Description
ref true HTMLInputElement Ref of the input that gives freedom to manipulate the input if necessary.
maxLength true Number Determine the maximum length of the input value. Characters added by the mask are also summed.
cb false Function Receive event via callback function on input change.
masks true { index: number; character: string; }[] An array of objects where the index represents the position of the string you want to assign a character to.

Note: The character field only accepts characters, and only one per index.


input-mask-react's People

Contributors

pabloferrari027 avatar

Watchers

 avatar

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.