├── .browserslistrc ├── .eslintrc.js ├── .gitignore ├── LICENSE.md ├── README.md ├── babel.config.js ├── package-lock.json ├── package.json ├── postcss.config.js ├── public ├── favicon.ico └── index.html └── src ├── App.vue ├── assets └── logo.png ├── components ├── Lightbulb.vue └── RockerSwitch.vue ├── main.js └── utils └── helpers.js /.browserslistrc: -------------------------------------------------------------------------------- 1 | > 1% 2 | last 2 versions 3 | not ie <= 8 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | env: { 4 | node: true 5 | }, 6 | 'extends': [ 7 | 'plugin:vue/essential', 8 | 'eslint:recommended' 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 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Danny Feliz. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vue-rocker-switch 2 | 3 | > A customizable rocker switch component for Vue.js. 4 | 5 | [](https://www.npmjs.com/package/vue-rocker-switch) 6 | [](https://www.npmjs.com/package/vue-rocker-switch) 7 | 8 | ![](https://i.imgur.com/SFobdvN.png) 9 | 10 | ## Installation 11 | 12 | ```sh 13 | npm install vue-rocker-switch --save 14 | ``` 15 | 16 | # Demo 17 | 18 | [![Edit vue-rocker-switch demo](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/qvw4o1k24) 19 | 20 | ## Usage example 21 | 22 | ```vue 23 | 26 | 27 | 40 | ``` 41 | 42 | ## Props 43 | 44 | | Prop | Description | Default value | Type | 45 | | ------------------ | ------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | ---------------- | 46 | | value | Boolean value attached to the rocker switcher. This will be used to initialize the component value too. | `false` | Boolean | 47 | | size | rocker switch size, it can be a string (`small`, `medium` and `large`) or a decimal number | `small` | String or Number | 48 | | labelOn | Text of the `On` label | `On` | String or Number | 49 | | labelOff | Text of the `Off` label | `Off` | String or Number | 50 | | activeColorLabel | Text color used when the `On` label is active | ![#fff](https://placehold.it/15/fff/000000?text=+) `#fff` | String | 51 | | inactiveColorLabel | Text color used when the `Off` label is inactive | ![#333](https://placehold.it/15/333/000000?text=+) `#333` | String | 52 | | backgroundColorOn | Background color of the `On` button | ![#0084d0](https://placehold.it/15/0084d0/000000?text=+) `#0084d0` | String | 53 | | backgroundColorOff | Background color of the `Off` button | ![#bd5757](https://placehold.it/15/bd5757/000000?text=+) `#bd5757` | String | 54 | | borderColor | Border color of the rocker switch | ![#eee](https://placehold.it/15/eee/000000?text=+) `#eee` | String | 55 | | toggle | Allow to the rocker switch to behave as a toggle switch | `true` | Boolean | 56 | 57 | ## Events 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
EventDescription
changeFires each time the rocker switch changes.
73 | 74 | ## Development setup 75 | 76 | ``` 77 | 78 | npm install 79 | 80 | ``` 81 | 82 | ### Compiles and hot-reloads for development 83 | 84 | ``` 85 | 86 | npm run serve 87 | 88 | ``` 89 | 90 | ### Compiles and minifies for production 91 | 92 | ``` 93 | 94 | npm run build 95 | 96 | ``` 97 | 98 | ### Lints and fixes files 99 | 100 | ``` 101 | 102 | npm run lint 103 | 104 | ``` 105 | 106 | ### Customize configuration 107 | 108 | See [Configuration Reference](https://cli.vuejs.org/config/). 109 | 110 | ## Contributing 111 | 112 | 1. Fork it () 113 | 2. Create your feature branch (`git checkout -b feature/fooBar`) 114 | 3. Commit your changes (`git commit -am 'Add some fooBar'`) 115 | 4. Push to the branch (`git push origin feature/fooBar`) 116 | 5. Create a new Pull Request 117 | 118 | ## License 119 | 120 | This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details 121 | 122 | ## Acknowledgments 123 | 124 | - This project was inspired by this post from codepen.io [Checkbox Toggle Switches Are Confusing UI](https://codepen.io/marcusconnor/post/checkbox-toggle-switches-are-confusing-ui) by [@MarcusConnorNH](https://twitter.com/MarcusConnorNH) 125 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/app' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vue-rocker-switch", 3 | "version": "1.2.4", 4 | "description": "A customisable rocker switch component for Vue.js", 5 | "main": "./dist/vue-rocker-switch.umd.min.js", 6 | "files": [ 7 | "dist/vue-rocker-switch.umd.min.js", 8 | "dist/vue-rocker-switch.css" 9 | ], 10 | "keywords": [ 11 | "vue", 12 | "rocker", 13 | "switch", 14 | "vue-rocker", 15 | "vue-rocker-switch", 16 | "light-rocker-switch", 17 | "light-switcher" 18 | ], 19 | "author": "Danny Feliz ", 20 | "license": "MIT", 21 | "bugs": "https://github.com/DannyFeliz/vue-rocker-switch/issues/new", 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/DannyFeliz/vue-rocker-switch" 25 | }, 26 | "scripts": { 27 | "serve": "vue-cli-service serve", 28 | "build": "vue-cli-service build", 29 | "bundle": "vue-cli-service build --target lib --name vue-rocker-switch ./src/components/RockerSwitch.vue", 30 | "lint": "vue-cli-service lint", 31 | "publish": "npm publish --access public" 32 | }, 33 | "dependencies": { 34 | "color-string": "^1.5.3", 35 | "vue": "^2.5.21" 36 | }, 37 | "devDependencies": { 38 | "@vue/cli-plugin-babel": "^3.2.0", 39 | "@vue/cli-plugin-eslint": "^3.2.0", 40 | "@vue/cli-service": "^3.2.0", 41 | "babel-eslint": "^10.0.1", 42 | "eslint": "^5.8.0", 43 | "eslint-plugin-vue": "^5.0.0", 44 | "node-sass": "^4.9.0", 45 | "sass-loader": "^7.0.1", 46 | "vue-template-compiler": "^2.5.21" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | autoprefixer: {} 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DannyFeliz/vue-rocker-switch/ef5d9f2f51a288573e8cfb83d49cad7421921187/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | vue-rocker-switch 9 | 10 | 11 | 14 |
15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/App.vue: -------------------------------------------------------------------------------- 1 | 30 | 31 | 48 | 49 | 60 | -------------------------------------------------------------------------------- /src/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DannyFeliz/vue-rocker-switch/ef5d9f2f51a288573e8cfb83d49cad7421921187/src/assets/logo.png -------------------------------------------------------------------------------- /src/components/Lightbulb.vue: -------------------------------------------------------------------------------- 1 | 15 | 22 | -------------------------------------------------------------------------------- /src/components/RockerSwitch.vue: -------------------------------------------------------------------------------- 1 | 22 | 23 | 153 | 154 | 301 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/utils/helpers.js: -------------------------------------------------------------------------------- 1 | import colorString from 'color-string'; 2 | 3 | export const isColorValid = (color) => { 4 | const isValid = !!colorString.get(color); 5 | 6 | if (!isValid) { 7 | console.warn(`The color ${color} it's not a valid color, please check your input.`); 8 | } 9 | 10 | return isValid; 11 | }; 12 | --------------------------------------------------------------------------------