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

mask-field

v1.0.5

Published

Mask field for react inputs

Downloads

2

Readme

React mask-field

React input mask with simply interface and just customisation

Features

  • colorizes mask
  • works with different mask
  • takes different validators
  • can works with copy/paste events
  • supports dynamic changed masks
  • supports all major browsers
  • no external dependencies

demo

Setup

Install the package npm i mask-field --save

Use

React Mask exports default MaskInput component

import MaskField from "mask-field"
import "mask-field/lib/index.css"

importing styles are require for correct work

MaskInput has interface look like simple native input with two addition props (mask, separators)

mask is showing how transform value separators are array of symbols who must be a skipped

We just should need paste MaskInput in yours component and hand over needs props

<MaskField
  value={value}
  mask={mask}
  separators={separators}
  onChange={onChange}
  placeholder="placeholder"
  modifiers={modifiers}
/>

Props

| Prop | Required | Type | Description | Example | | :--- | :---: | :---: | :---: | ---: | | mask | true | string | pattern | "xxx (xx) xxx xx xx" | | separators | true | string[] | to skipping symbols | [" ", "(", ")"] | | value | true | string | input value | - | | onChange | true | func | on change cb | - | | validators | false | func[] | list of validators who will call by chain. (default [isNumber]) (value: string): string | undefined | [isNumber] | | placeholder | false | string | showing with empty input | - | | modifiers | false | string | setting custom styles | - | | modifiersErrors | false | string | setting custom styles for errors container | - | | type | false | string | input type (default tel), don't have to use number | string | | withErrors | false | bool | trigger for visible errors block (default false) | true | | errors | false | string[] | array of errors | ["Value is not a number"] | | disabled | false | bool | flag for disabling input | true | | readOnly | false | bool | flag for set readOnly in input | true |

Advance

If you want using custom react input component, mask exports additional wrapper.

import { MaskWrapper } from "mask-field"
import "mask-field/lib/index.css"

You should wrap your custom input and hand over props

example:

<MaskWrapper
  value={value}
  mask={mask}
  errors={errors}
  separators={[" "]}
  onChange={onChange}
  modifiers={modifiers}
>
  {({
    maskInputStyle,
    maskInputWrapperStyle,
    inputRef,
    value,
    handleMaskChange,
  }) => (
      <Input
        type="tel"
        wrapperModifiers={maskInputWrapperStyle}
        modifiers={joinClasses("input", maskInputStyle)}
        value={value}
        required={required}
        onChange={handleMaskChange}
        name={name}
        readOnly={readOnly}
        disabled={isDisabled}
        tabIndex={tabIndex}
        onBlur={onBlur}
        inputRef={inputRef}
      />
    )
  }
</MaskWrapper>

In children MaskWrapper returns props who needed hand over to custom input

Mask utils

If you want using simply function to transform value to custom mask or cut all separators You can import prepareValueFromMask, prepareValueToMask

import { prepareValueFromMask, prepareValueToMask } from "mask-field""

example:

const value = "375292222222"
const mask = "xxx (xx) xxx xx xx"
const separators = [" ", "(", ")"]

prepareValueToMask(value, mask, [" "])
  .toBe("375 (29) 222 22 22")
prepareValueFromMask("12/01/2000", ["/"]))
  .toBe("12012000")