├── .eslintrc
├── .gitignore
├── .npmrc
├── .travis.yml
├── CHANGES.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── demo
└── src
│ ├── index.js
│ └── style.css
├── nwb.config.js
├── package.json
├── src
└── index.js
└── tests
└── index-test.js
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "extends": ["standard", "standard-react"],
3 | "rules": {
4 | "brace-style": [2, "stroustrup", {"allowSingleLine": true}],
5 | "eqeqeq": [2, "smart"],
6 | "jsx-quotes": [2, "prefer-double"],
7 | "react/prop-types": 0,
8 | "react/self-closing-comp": 0,
9 | "react/wrap-multilines": 0,
10 | "space-before-function-paren": 0
11 | },
12 | "parser": "babel-eslint"
13 | }
14 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /coverage
2 | /demo/dist
3 | /es
4 | /lib
5 | /node_modules
6 | /umd
7 | npm-debug.log*
8 | package-lock.json
9 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | save=false
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - 4
4 | - 6
5 | script: npm test
6 |
--------------------------------------------------------------------------------
/CHANGES.md:
--------------------------------------------------------------------------------
1 | ## 4.0.0 / 2017-07-04
2 |
3 | * Potential breaking change as the `peerDependencies` range has been changed from `"0.14.x || 15.x"` to `"^0.14.9 || ^15.3.0"`.
4 |
5 | * Use `React.Component` instead of `React.createClass` and the `prop-types` package instead of `React.PropTypes` to silence deprecation warnings [[#94](https://github.com/insin/react-maskedinput/pull/94)] [[krvital][krvital]]
6 |
7 | * Update nwb to 0.17.x:
8 | * `module` config replaces `jsnext:main` in `package.json` to specify the location of the ES6 modules build.
9 | * `prop-types` is bundled with the UMD development build and stripped from the production build, along with usage of `propTypes`.
10 |
11 | ## 3.3.4 / 2016-12-15
12 |
13 | * Silence React 15.4 invalid property warnings [[#80](https://github.com/insin/react-maskedinput/pull/80)] [[nathanstitt][nathanstitt]]
14 |
15 | ## 3.3.2 / 2016-12-01
16 |
17 | * Fix for both Android and MS Edge input entering
18 |
19 | ## 3.2.0 / 2016-05-24
20 |
21 | * Allow dynamic pattern updating [[martyphee][martyphee]]
22 |
23 | ## 3.1.3 / 2016-05-02
24 |
25 | * Don’t call `onChange` function if undefined.
26 | * Update nwb to 0.9.x
27 |
28 | ## 3.1.2 / 2016-04-11
29 |
30 | * Support for React 15.x.x
31 |
32 | ## 3.1.1 / 2016-03-09
33 |
34 | * Convert tooling to use [nwb](https://github.com/insin/nwb/) [[bpugh]][[bpugh]]
35 | * Publish `dist` files
36 |
37 | ## 3.1.0 / 2016-02-11
38 |
39 | * Added support for `value` behaving as a controlled component.
40 |
41 | ## 3.0.0 / 2015-10-23
42 |
43 | **Breaking change:** Now uses a `mask` prop to define the input mask instead of `pattern`, to avoid preventing use of the the HTML5 `pattern` attribute in conjunction with the input mask.
44 |
45 | **Breaking change:** React >= 0.14 is now required.
46 |
47 | React 0.14 compatibility. [[jquense][jquense]]
48 |
49 | Updated to [inputmask-core@2.1.1](https://github.com/insin/inputmask-core/blob/master/CHANGES.md#211--2015-09-11)
50 |
51 | Updates based on [inputmask-core@2.1.0](https://github.com/insin/inputmask-core/blob/master/CHANGES.md#210--2015-07-15):
52 |
53 | * Added `placeholderChar` prop to configure the placeholder character.
54 | * The mask's pattern is now changed if the `pattern` prop changes - the user's input so far is replayed with the new pattern (with mixed results - TBD).
55 |
56 | UMD build is now available via npm in `dist/`. [[muffinresearch][muffinresearch]]
57 |
58 | ## 2.0.0 / 2015-04-07
59 |
60 | **Breaking change:** [inputmask-core@2.0.0](https://github.com/insin/inputmask-core/blob/master/CHANGES.md#200--2015-04-03) is now required.
61 |
62 | Added undo/redo when Ctrl/Command + Z/Y are used.
63 |
64 | ## 1.1.0 / 2015-03-26
65 |
66 | Updated to [inputmask-core@1.2.0](https://github.com/insin/inputmask-core/blob/master/CHANGES.md#120--2015-03-26)
67 |
68 | A `formatCharacters` prop can now be passed to configure input mask format characters.
69 |
70 | ## 1.0.0 / 2015-03-25
71 |
72 | Initial release features:
73 |
74 | * Based on [inputmask-core@1.1.0](https://github.com/insin/inputmask-core/blob/master/CHANGES.md#110--2015-03-25)
75 | * Basic editing works:
76 | * Typing, backspacing, pasting, cutting and deleting
77 | * Invalid content will be ignored if typed or pasted
78 | * Static parts of the mask can't be modfied
79 | * Editing operations can handle text selections
80 | * Tested in latest versions of Firefox, Chrome, Opera and IE
81 | * Placeholder generation and display when the mask has no user input
82 |
83 | [jquense]: https://github.com/jquense
84 | [krvital]: https://github.com/krvital
85 | [muffinresearch]: https://github.com/muffinresearch
86 | [martyphee]: https://github.com/martyphee
87 | [nathanstitt]: https://github.com/nathanstitt
88 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ## Prerequisites
2 |
3 | [Node.js](http://nodejs.org/) must be installed.
4 |
5 | ## Installation
6 |
7 | * Running `npm install` in the components's root directory will install everything you need for development.
8 |
9 | ## Demo Development Server
10 |
11 | * `npm start` will run a development server with the component's demo app at [http://localhost:3000](http://localhost:3000) with hot module reloading.
12 |
13 | ## Running Tests
14 |
15 | * `npm test` will run the tests once.
16 | * `npm run test:watch` will run the tests on every change.
17 |
18 | ## Building
19 |
20 | * `npm run build` will build the component for publishing to npm and also bundle the demo app.
21 |
22 | * `npm run clean` will delete built resources.
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Jonny Buchanan
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy of
4 | this software and associated documentation files (the "Software"), to deal in
5 | the Software without restriction, including without limitation the rights to
6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7 | the Software, and to permit persons to whom the Software is furnished to do so,
8 | subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # `MaskedInput`
2 |
3 | A [React](http://facebook.github.io/react/) component for `` masking, built on top of [inputmask-core](https://github.com/insin/inputmask-core).
4 |
5 | 
6 |
7 | ## [Live Demo](http://insin.github.io/react-maskedinput/)
8 |
9 | ## Install
10 |
11 | ### npm
12 |
13 | `MaskedInput` can be used on the server, or bundled for the client using an npm-compatible packaging system such as [Browserify](http://browserify.org/) or [webpack](http://webpack.github.io/).
14 |
15 | ```
16 | npm install react-maskedinput --save
17 | ```
18 |
19 | ### Browser bundle
20 |
21 | The browser bundle exposes a global `MaskedInput` variable and expects to find a global `React` (>= 0.14.0) variable to work with.
22 |
23 | * [react-maskedinput.js](https://unpkg.com/react-maskedinput/umd/react-maskedinput.js) (development version)
24 | * [react-maskedinput.min.js](https://unpkg.com/react-maskedinput/umd/react-maskedinput.min.js) (compressed production version)
25 |
26 | ## Usage
27 |
28 | Give `MaskedInput` a [`mask`](#mask-string) and an `onChange` callback:
29 |
30 | ```javascript
31 | var React = require('react')
32 | var MaskedInput = require('react-maskedinput')
33 |
34 | var CreditCardDetails = React.createClass({
35 | state: {
36 | card: '',
37 | expiry: '',
38 | ccv: ''
39 | },
40 |
41 | _onChange(e) {
42 | var stateChange = {}
43 | stateChange[e.target.name] = e.target.value
44 | this.setState(stateChange)
45 | },
46 |
47 | render() {
48 | return
49 |
53 |
57 |
61 |
62 | }
63 | })
64 | ```
65 |
66 | Create some wrapper components if you have a masking configuration which will be reused:
67 |
68 | ```javascript
69 | var CustomInput = React.createClass({
70 | render() {
71 | return
83 | }
84 | })
85 | ```
86 |
87 | ## Props
88 |
89 | ### `mask` : `string`
90 |
91 | The masking pattern to be applied to the ``.
92 |
93 | See the [inputmask-core docs](https://github.com/insin/inputmask-core#pattern) for supported formatting characters.
94 |
95 | ### `onChange` : `(event: SyntheticEvent) => any`
96 |
97 | A callback which will be called any time the mask's value changes.
98 |
99 | This will be passed a `SyntheticEvent` with the input accessible via `event.target` as usual.
100 |
101 | **Note:** this component currently calls `onChange` directly, it does not generate an `onChange` event which will bubble up like a regular `` component, so you *must* pass an `onChange` if you want to get a value back out.
102 |
103 | ### `formatCharacters`: `Object`
104 |
105 | Customised format character definitions for use in the pattern.
106 |
107 | See the [inputmask-core docs](https://github.com/insin/inputmask-core#formatcharacters) for details of the structure of this object.
108 |
109 | ### `placeholderChar`: `string`
110 |
111 | Customised placeholder character used to fill in editable parts of the pattern.
112 |
113 | See the [inputmask-core docs](https://github.com/insin/inputmask-core#placeholderchar--string) for details.
114 |
115 | ### `value` : `string`
116 |
117 | A default value for the mask.
118 |
119 | ### `placeholder` : `string`
120 |
121 | A default `placeholder` will be generated from the mask's pattern, but you can pass a `placeholder` prop to provide your own.
122 |
123 | ### `size` : `number | string`
124 |
125 | By default, the rendered ``'s `size` will be the length of the pattern, but you can pass a `size` prop to override this.
126 |
127 | ### Other props
128 |
129 | Any other props passed in will be passed as props to the rendered ``, except for the following, which are managed by the component:
130 |
131 | * `maxLength` - will always be equal to the pattern's `.length`
132 | * `onKeyDown`, `onKeyPress` & `onPaste` - will each trigger a call to `onChange` when necessary
133 |
134 | ## MIT Licensed
135 |
--------------------------------------------------------------------------------
/demo/src/index.js:
--------------------------------------------------------------------------------
1 | import './style.css'
2 |
3 | import React from 'react'
4 | import {render} from 'react-dom'
5 |
6 | import MaskedInput from '../../src'
7 |
8 | const PATTERNS = [
9 | '1111 1111',
10 | '111 111',
11 | '11 11',
12 | '1 1',
13 | ]
14 |
15 | class App extends React.Component {
16 | state = {
17 | card: '',
18 | expiry: '',
19 | ccv: '',
20 | plate: '',
21 | escaped: '',
22 | leading: '',
23 | custom: '',
24 | changing: '',
25 | pattern: '1111 1111',
26 | cardPattern: '1111 1111 1111 1111',
27 | }
28 |
29 | _onChange = (e) => {
30 | const stateChange = {}
31 | stateChange[e.target.name] = e.target.value
32 | this.setState(stateChange)
33 | }
34 |
35 | _changePattern = (e) => {
36 | this.setState({pattern: e.target.value})
37 | }
38 |
39 | _onCardChange = (e) => {
40 | if (/^3[47]/.test(e.target.value)) {
41 | this.setState({cardPattern: '1111 111111 11111'})
42 | }
43 | else {
44 | this.setState({cardPattern: '1111 1111 1111 1111'})
45 | }
46 | }
47 |
48 | render() {
49 | return