@@ -4,69 +4,97 @@ A lightweight and dependency free input facade created specific for Vue
44
55## [ Docs and Demo] ( https://ronaldjerez.github.io/vue-input-facade )
66
7- ## Install
7+ ## Installing
88
99```
10- yarn add vue-input-facade
11- or
1210npm i vue-input-facade
11+ or
12+ yarn add vue-input-facade
1313```
1414
15- ## Usage (two flavors)
15+ ## Importing
1616
17- ### Global
17+ ### Globally
18+
19+ installs the component, directive and filter for your entire application.
1820
1921``` javascript
2022import InputFacade from ' vue-input-facade'
2123Vue .use (InputFacade)
2224```
2325
24- ### Local (inside the component)
26+ ### Locally
2527
2628``` javascript
27- import { InputFacade } from ' vue-input-facade'
29+ import { InputFacade , facade , masker } from ' vue-input-facade'
2830export default {
29- components: { InputFacade }
31+ components: { InputFacade },
32+ directives: { facade },
33+ filters: { facade: masker }
3034}
3135```
3236
33- ### Local (as directive)
37+ ## Usage
3438
35- ``` javascript
36- import { facade } from ' vue-input-facade '
37- export default {
38- directives : { facade }
39- }
39+ ### Component
40+
41+ ``` html
42+ < label >Phone Number</ label >
43+ < input-facade mask = " (###) ###-#### " name = " phoneNumber " type = " tel " masked />
4044```
4145
42- ### Local (as filter)
46+ ### Directive
4347
44- ``` javascript
45- import { masker } from ' vue-input-facade'
46- export default {
47- filters: { facade: masker }
48- }
48+ ``` html
49+ <label >Date</label >
50+ <input type =" text" v-facade =" '##/##/##'" />
4951```
5052
51- ## Tokens
53+ See [ demo page] ( https://ronaldjerez.github.io/vue-input-facade ) for more usage example
54+
55+ ## Default Tokens
56+
57+ + ` S ` = alpha characters
58+ + ` # ` = numerical characters
59+ + ` X ` = alpha numerical characters
60+ + ` A ` = alpha characters, forced to uppercase
61+ + ` a ` = alpha characters, forced to lowercase
62+ + ` \ ` = escape any of the above characters
63+
64+ See the [ token source file] ( src/tokens.js ) for definition signature
65+
66+ ## Component Properties
67+
68+ Inherits from [ HTMLInputElement] ( https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement ) , plus adds these additional properties:
69+
70+ | Property | Required | Type | Default | Description |
71+ | ----------- | -------- | ------------- | ----------------------- | ------------------------------------------ |
72+ | mask | false | String, Array | | Mask pattern |
73+ | masked | false | Boolean | false | emit value with mask chars, default is raw |
74+ | tokens | false | Object | [ tokens] ( src/tokens.js ) | Custom tokens for mask |
75+
76+ ## Migrating Existing Project
77+
78+ If you are migrating an existing project to vue-input-facade from another plugin and dont want to touch the whole codebase. You may pass options during plugin installation to override the default tokens or directive name.
5279
5380``` javascript
54- ' #' : {pattern: / \d / },
55- ' X' : {pattern: / [0-9a-zA-Z ] / },
56- ' S' : {pattern: / [a-zA-Z ] / },
57- ' A' : {pattern: / [a-zA-Z ] / , transform : v => v .toLocaleUpperCase ()},
58- ' a' : {pattern: / [a-zA-Z ] / , transform : v => v .toLocaleLowerCase ()},
59- ' !' : {escape: true }
60- ```
81+ import InputFacade from ' vue-input-facade'
6182
62- ## Properties
83+ // migrating from v-mask
84+ // the directive will now be v-mask instead of v-facade
85+ // and all the tokens will be replaced globally by the following
86+ const options = {
87+ name: ' mask' ,
88+ tokens: {
89+ ' #' : { pattern: / \d / },
90+ ' A' : { pattern: / [a-zA-Z ] / },
91+ ' N' : { pattern: / [0-9a-zA-Z ] / },
92+ ' X' : { pattern: / . / }
93+ }
94+ }
6395
64- | Property | Required | Type | Default | Description |
65- | ----------- | -------- | ------------- | ----------------- | ------------------------------------------ |
66- | value | false | String | | Input value or v-model |
67- | mask | false | String, Array | | Mask pattern |
68- | masked | false | Boolean | false | emit value with mask chars, default is raw |
69- | tokens | false | Object | [ tokens] ( #tokens ) | Custom tokens for mask |
96+ Vue .use (InputFacade, options)
97+ ```
7098
7199## Thanks
72100
0 commit comments