├── .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 | ![Gifphy](https://media.giphy.com/media/W4RTzsjgQF447EfNPX/giphy.gif) 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 | 45 | 46 | 63 | 64 | 84 | ``` 85 | 86 | ## Props 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 |
Name
TypeRequiredDefaultDescription
num-inputsnumbertrue4Number of OTP inputs to be rendered.
separatorcomponent
falseProvide a custom separator between inputs by passing a component. For instance, <span>-</span> would add - between each input
input-classesclassName (string)falsenoneStyle applied or class passed to each input.
input-typestringfalse"tel"Input type. Optional value: "password", "number", "tel".
input-modestringfalse"text"Input type. Optional value: "text", "numeric", "decimal", "none".
should-auto-focusbooleanfalsefalseAuto focuses input on initial page load.
139 | 140 | ## Methods 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 |
Name
Description
clearInput()Use with $refs for clearing all otp inputs, see code example section.
152 | 153 | ## Events 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 |
Name
Description
on-changeReturn OTP code was changing when we made a change in inputs.
on-completeReturn OTP code typed in inputs.
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 | 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 | 28 | 29 | 169 | -------------------------------------------------------------------------------- /src/components/SingleOtpInput.vue: -------------------------------------------------------------------------------- 1 | 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 | --------------------------------------------------------------------------------