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

redux-form-input-masks

v2.0.2

Published

Input masking with redux-form made easy

Downloads

23,685

Readme

redux-form-input-masks

Documentation and examples

Migration guide

Getting started

redux-form-input-masks is a library that works with redux-form to easily add masking to Fields.

Motivation

Redux is awesome and so are input masks: they help standardizing inputs and improves the UX of the application. redux-form has support for input formatting, parseing and normalizing, but it can get pretty tricky to implement a mask with these functions. redux-form-input-masks offer simple APIs to create these masks so you don't need to worry about it!

Also, the value of the Fields in any application should be agnostic of how the Fields themselves are presented to the user. For example, if there's a currency field in a form, it makes more sense to store the value as a number. Storing Field values in a way that makes more sense for the application makes it easier to integrate form data with backend services and to create validations for it. With redux-form-input-masks you can also choose how the value of a formatted Field will be stored in the application's store.

Under the hood

redux-form-input-masks returns objects implementing redux-form's Value Lifecycle Hooks and also some Global Event Handlers to manage the caret position.

Installation

npm install --save redux-form-input-masks

or

yarn add redux-form-input-masks

Features

  • simple to setup: works with redux-form out of the box, you just need to install redux-form-input-masks and you're good to go;
  • simple to use: import a mask creator and apply it... and that's it. There's no need to change the component you're already using;
  • flexible: lets you choose how you want the input mask to behave;
  • dependency compatible: redux-form-input-masks works with basically all combinations of versions of react, react-dom, react-redux, redux and redux-form;
  • browser compatible: works on all major browsers (Chrome, Firefox, Safari, Edge, Opera, Opera Mini and Internet Explorer >= 10);
  • lightweight: not a single dependency is added to redux-form-input-masks;
  • compatible with component libraries like material-ui and redux-form-material-ui's wrappers, for both v0-stable and v1-beta versions.

Available masks

| Name | Description | API Reference | Demo | | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | ----------------------------------------------------- | | Number Mask | Ideal for currency, percentage or any other numeric input. Supports prefix, suffix, locale number formatting and even more options. You can also choose wether the value is stored as number or string. | createNumberMask | codesandbox.io | | Text Mask | Flexible string mask. Lets you specify the pattern, inputtable characters and much more. | createTextMask | codesandbox.io |

Usage

It's super simple to apply a mask using this library. You just need to import your mask creator from redux-form-input-masks, specify the parameters and pass it to the Field using spread attributes. Yep, it's that easy.

You can find several examples including demos on our documentation.

Here's a simple snippet that uses createNumberMask and createTextMask and applies them to Fields:

import { createNumberMask, createTextMask } from 'redux-form-input-masks';

(...)

const currencyMask = createNumberMask({
  prefix: 'US$ ',
  suffix: ' per item',
  decimalPlaces: 2,
  locale: 'en-US',
})

const phoneMask = createTextMask({
  pattern: '(999) 999-9999',
});

(...)

<Field
  name="amount"
  component="input"
  type="tel"
  {...currencyMask}
/>

<Field
  name="phone"
  component="input"
  type="tel"
  {...phoneMask}
/>