├── .browserslistrc
├── .editorconfig
├── .eslintrc.js
├── .gitignore
├── README.md
├── babel.config.js
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
├── favicon.ico
└── index.html
├── publish.sh
└── src
├── App.vue
├── assets
└── logo.png
├── components
├── OtpInput.vue
├── SingleOtpInput.vue
└── index.js
└── main.js
/.browserslistrc:
--------------------------------------------------------------------------------
1 | > 1%
2 | last 2 versions
3 | not ie <= 8
4 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.{js,jsx,ts,tsx,vue}]
2 | indent_style = space
3 | indent_size = 2
4 | end_of_line = lf
5 | trim_trailing_whitespace = true
6 | insert_final_newline = true
7 | max_line_length = 100
8 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: {
4 | node: true,
5 | },
6 | extends: [
7 | 'plugin:vue/essential',
8 | '@vue/airbnb',
9 | ],
10 | rules: {
11 | 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
12 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
13 | },
14 | parserOptions: {
15 | parser: 'babel-eslint',
16 | },
17 | };
18 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | /dist
4 |
5 | # local env files
6 | .env.local
7 | .env.*.local
8 |
9 | # Log files
10 | npm-debug.log*
11 | yarn-debug.log*
12 | yarn-error.log*
13 |
14 | # Editor directories and files
15 | .idea
16 | .vscode
17 | *.suo
18 | *.ntvs*
19 | *.njsproj
20 | *.sln
21 | *.sw*
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # vue-otp-input
2 |
3 | > A fully customizable, OTP(one-time password) input component built with Vue 2.x.
4 |
5 | 
6 |
7 | [Live Demo](https://zlx025mxpp.codesandbox.io/)
8 |
9 | ## Installation
10 |
11 | To install the latest stable version:
12 |
13 | ```
14 | npm install --save @bachdgvn/vue-otp-input
15 | ```
16 |
17 | Import to main.js:
18 |
19 | ```javascript
20 | import OtpInput from "@bachdgvn/vue-otp-input";
21 |
22 | Vue.component("v-otp-input", OtpInput);
23 | ```
24 |
25 |
26 | Code example:
27 |
28 | ```javascript
29 |
30 |
31 |
41 |
42 |
43 |
44 |
45 |
46 |
63 |
64 |
84 | ```
85 |
86 | ## Props
87 |
88 |
89 |
90 | Name
|
91 | Type |
92 | Required |
93 | Default |
94 | Description |
95 |
96 |
97 | | num-inputs |
98 | number |
99 | true |
100 | 4 |
101 | Number of OTP inputs to be rendered. |
102 |
103 |
104 | | separator |
105 | component
|
106 | false |
107 | |
108 | Provide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input |
109 |
110 |
111 | | input-classes |
112 | className (string) |
113 | false |
114 | none |
115 | Style applied or class passed to each input. |
116 |
117 |
118 | | input-type |
119 | string |
120 | false |
121 | "tel" |
122 | Input type. Optional value: "password", "number", "tel". |
123 |
124 |
125 | | input-mode |
126 | string |
127 | false |
128 | "text" |
129 | Input type. Optional value: "text", "numeric", "decimal", "none". |
130 |
131 |
132 | | should-auto-focus |
133 | boolean |
134 | false |
135 | false |
136 | Auto focuses input on initial page load. |
137 |
138 |
139 |
140 | ## Methods
141 |
142 |
143 |
144 | Name
|
145 | Description |
146 |
147 |
148 | | clearInput() |
149 | Use with $refs for clearing all otp inputs, see code example section. |
150 |
151 |
152 |
153 | ## Events
154 |
155 |
156 |
157 | Name
|
158 | Description |
159 |
160 |
161 | | on-change |
162 | Return OTP code was changing when we made a change in inputs. |
163 |
164 |
165 | | on-complete |
166 | Return OTP code typed in inputs. |
167 |
168 |
169 |
170 | ## Changelog
171 | * **v1.0.8** - Fix #30: Support input type: "password"
172 | * **v1.0.7** - Fix #23: Not accepting numbers from numeric keypad in external keyboard
173 | * **v1.0.6** - Add feature to disallow certain characters like "." or "e".
174 | * **v1.0.5** - Support clearInput() methods for clearing all otp inputs.
175 | * **v1.0.4** - Support @on-change event and fix bug for firing @on-complete every time we press keyboard.
176 | * **v1.0.3** - Fix first and last character not being modified and pasting OTP codes.
177 | * **v1.0.2** - Update first stable version.
178 |
--------------------------------------------------------------------------------
/babel.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | presets: [
3 | '@vue/app',
4 | ],
5 | };
6 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@bachdgvn/vue-otp-input",
3 | "version": "1.0.8",
4 | "description": "A fully customizable, one-time password input component for the web built with Vue 2.x.",
5 | "author": "Bach Duong ",
6 | "repository": "https://github.com/bachdgvn/vue-otp-input",
7 | "keywords": [
8 | "vueotpinput",
9 | "vue",
10 | "otp",
11 | "input",
12 | "otpinput"
13 | ],
14 | "license": "MIT",
15 | "scripts": {
16 | "serve": "vue-cli-service serve",
17 | "build": "vue-cli-service build",
18 | "build-bundle": "vue-cli-service build --target lib --name vueOtpInput ./src/components/index.js",
19 | "lint": "vue-cli-service lint"
20 | },
21 | "main": "./dist/vueOtpInput.common.js",
22 | "unpkg": "./dist/vueOtpInput.umd.min.js",
23 | "files": [
24 | "dist/*",
25 | "src/*",
26 | "public/*",
27 | "*.json",
28 | "*.js"
29 | ],
30 | "dependencies": {
31 | "vue": "^2.5.22"
32 | },
33 | "devDependencies": {
34 | "@vue/cli-plugin-babel": "^3.4.0",
35 | "@vue/cli-plugin-eslint": "^3.4.0",
36 | "@vue/cli-service": "^3.4.0",
37 | "@vue/eslint-config-airbnb": "^4.0.0",
38 | "babel-eslint": "^10.0.1",
39 | "eslint": "^5.8.0",
40 | "eslint-plugin-vue": "^5.0.0",
41 | "less": "^3.0.4",
42 | "less-loader": "^4.1.0",
43 | "vue-template-compiler": "^2.5.21"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/postcss.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | plugins: {
3 | autoprefixer: {},
4 | },
5 | };
6 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bachdgvn/vue-otp-input/685b3d165ec5faa3950f54880b434ba40b9078c6/public/favicon.ico
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | vue-otp-input
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/publish.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | npm run build-bundle && npm publish --access public
3 |
4 | echo "Publish finished!";
5 | read -n1 -r -p "Press space to continue..." key
6 |
--------------------------------------------------------------------------------
/src/App.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Input type default = "tel"
4 |
5 |
14 |
15 |
16 |
17 |
Input type = "number"
18 |
19 |
29 |
30 |
31 |
32 |
Input type = "password"
33 |
34 |
44 |
45 |
46 |
47 |
48 |
49 |
70 |
71 |
91 |
--------------------------------------------------------------------------------
/src/assets/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bachdgvn/vue-otp-input/685b3d165ec5faa3950f54880b434ba40b9078c6/src/assets/logo.png
--------------------------------------------------------------------------------
/src/components/OtpInput.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
26 |
27 |
28 |
29 |
169 |
--------------------------------------------------------------------------------
/src/components/SingleOtpInput.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
120 |
--------------------------------------------------------------------------------
/src/components/index.js:
--------------------------------------------------------------------------------
1 | import OtpInput from './OtpInput.vue';
2 |
3 | export default OtpInput;
4 |
--------------------------------------------------------------------------------
/src/main.js:
--------------------------------------------------------------------------------
1 | import Vue from 'vue';
2 | import App from './App.vue';
3 |
4 | Vue.config.productionTip = false;
5 |
6 | new Vue({
7 | render: h => h(App),
8 | }).$mount('#app');
9 |
--------------------------------------------------------------------------------