├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── toggle-btn.vue └── toggle_btn.gif /.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-toggle-btn 2 | ## A Highly Customizable, easy-to-use elegant toggle/switch button component 3 | 4 | ![MIT License](https://badgen.net/badge/license/MIT/blue "MIT License") 5 | [![view on npm](http://img.shields.io/npm/v/vue-toggle-btn.svg?colorB=red)](https://www.npmjs.org/package/vue-toggle-btn) 6 | 7 | ###### Demo 8 | ![toggle-btn](https://github.com/JonathanDn/vue-toggle-btn/blob/master/toggle_btn.gif "Vue Toggle Btn") 9 | 10 | # Usage 11 | Install via NPM ```npm i vue-toggle-btn``` 12 | 13 | Then require in your project: 14 | ```js 15 | var VueToggleBtn = require('vue-toggle-btn'); 16 | ``` 17 | or ES6 syntax: 18 | ```js 19 | import VueToggleBtn from 'vue-toggle-btn'; 20 | ``` 21 | Then you can register the component globally: 22 | ```js 23 | Vue.component('vue-toggle-btn', VueToggleBtn); 24 | ``` 25 | Or in your Vue component: 26 | ```js 27 | components: { 28 | ToggleBtn 29 | } 30 | ``` 31 | You can then use the following selector anywhere in your project: 32 | * To get up and running quick the package now supports rendering just the selector with default values 33 | ```html 34 | 35 | ``` 36 | ## Properties 37 | ```options``` is a full configuration object holding the toggle-button building blocks which are ```handle```, ```track``` and ```isActive``` 38 | 39 | | property | Type | Description | 40 | | --- | --- | --- | 41 | | options | object | holds all toggle button style configurations | 42 | | isActive | false | holds the current boolean state of the button - can be `false` or `true` | 43 | | handle | object | holds all handle style configurations | 44 | | track | object | holds all track style configurations | 45 | 46 | 47 | ### handle 48 | | property | Type | Default | Description | 49 | | --- | --- | --- | --- | 50 | | diameter | number | 30 | Sets the handle diameter (the round button moving) | 51 | | color | string | ```#fff``` | Sets the handle color | 52 | | borderRadius | string | ```50%``` | Sets the handle border radius | 53 | 54 | ### track 55 | | property | Type | Default | Description | 56 | | --- | --- | --- | --- | 57 | | width | number | 70 | Sets the track width | 58 | | height | number | 30 | Sets the track height | 59 | | color | string | ```#ccc``` | Sets the default track color | 60 | | activeColor | string | ```#2196F3``` | Sets the active status track color(after toggled) | 61 | | borderWidth | number | 0 | Sets the track border width | 62 | | borderRadius | string | ```34px``` | Sets the track border radius | 63 | 64 | ### events 65 | | Event Name | Returns | Description | 66 | | --- | --- | --- | 67 | | **setIsActive** | `isActive` | Clicking the toggle button emits an its current `isActive` boolean state | 68 | 69 | Listening to the event e.g: 70 | ```html 71 | 72 | ``` 73 | 74 | Feedback would be much appreciated, questions, suggestions, issues are more than welcome. 75 | 76 | --- 77 | 👨‍💻 Follow me on [Twitter](https://twitter.com/jodoron). 78 | 79 | ### Donation 80 | If this project helped you reduce development time, you can buy me a cup of coffee :) 81 | 82 | * Paypal - yonidn7@gmail.com 83 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-toggle-btn", 3 | "version": "0.1.2", 4 | "private": false, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "peerDependencies": { 11 | "vue": "^2.5.17" 12 | }, 13 | "devDependencies": { 14 | "@vue/cli-plugin-babel": "^3.0.3", 15 | "@vue/cli-service": "^3.0.3", 16 | "node-sass": "4.9.3", 17 | "sass-loader": "7.1.0", 18 | "vue-template-compiler": "^2.5.17" 19 | }, 20 | "postcss": { 21 | "plugins": { 22 | "autoprefixer": {} 23 | } 24 | }, 25 | "browserslist": [ 26 | "> 1%", 27 | "last 2 versions", 28 | "not ie <= 8" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /toggle-btn.vue: -------------------------------------------------------------------------------- 1 | 12 | 13 | 120 | 121 | 166 | -------------------------------------------------------------------------------- /toggle_btn.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JonathanDn/vue-toggle-btn/b9ee4a17301295c131a7cdf05458636e294edd49/toggle_btn.gif --------------------------------------------------------------------------------