Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
7255f89
added btn color prop
cristiandan Mar 12, 2018
8d860d2
support btn color object
cristiandan Apr 19, 2018
2b1ae4c
updated readme
cristiandan Apr 19, 2018
22b59c7
allow generic background css property
cristiandan Apr 19, 2018
23b14f0
demo of button background
cristiandan Apr 19, 2018
bc7a9df
changed buttonBackground to switchColor
cristiandan Apr 26, 2018
4e779a3
updated readme and demo
cristiandan Apr 26, 2018
08da79e
Merge pull request #62 from cristiandan/master
euvl Apr 26, 2018
a3d6041
Version bump: 1.2.3
euvl Apr 26, 2018
0d24e82
Update README.md to show how to import component
aldencolerain May 11, 2018
cf2dbb9
Merge pull request #66 from aldencolerain/master
euvl May 12, 2018
8d980c2
Mention installing sass-loader
AnalyzePlatypus May 13, 2018
3a6836c
Merge pull request #68 from AnalyzePlatypus/master
euvl May 13, 2018
e9fa600
fixed typo in readme
KeisukeYamashita Jul 7, 2018
6f47955
Merge pull request #72 from KeisukeYamashita/bugfix/fix-typo-readme
euvl Jul 8, 2018
9ead20c
Add `name` prop, which can be attached to input
ajhaupt7 Aug 10, 2018
bf7351e
add name prop example to README and demo
ajhaupt7 Aug 10, 2018
76c351c
Update README.md
euvl Aug 11, 2018
3e87f52
Merge pull request #76 from ajhaupt7/master
euvl Aug 11, 2018
68d23ce
Add ability to customize color for disabled state (#63)
xavier Aug 11, 2018
e96b91c
Rebuild new version 🍰
euvl Aug 11, 2018
fc83089
1.3.0
euvl Aug 11, 2018
368f740
Set checked attribute based on value prop (#81)
Aug 31, 2018
7550a4b
Fix color object example typo (#84)
Sep 8, 2018
b6cd951
Improve accessibility (#85)
VictorCazanave Oct 18, 2018
d31ffe0
add ToggleButton export and remove unneeded imports/args (#95)
OmgImAlexis Dec 11, 2018
aea92a2
Adds the ability to use slots for labels, useful for the use of Vue c…
AsclepiLiz Dec 11, 2018
953ec3c
update readme (#90)
Dec 11, 2018
b81603f
Adds a font size property to the switch. (#77)
xon52 Dec 11, 2018
d096bff
Bug fixes & improvements + rebuild new feature
euvl Dec 11, 2018
3a6e7e6
1.3.1
euvl Dec 11, 2018
1171032
Update README.md
euvl Dec 11, 2018
fe803d1
Update README.md
euvl Dec 11, 2018
b0dbd52
Update README.md
euvl Dec 11, 2018
5e6859e
Update README.md
euvl Dec 11, 2018
4c41472
Update README.md
euvl Dec 11, 2018
c805d6e
Update README.md
euvl Dec 11, 2018
dc07727
Update README.md
euvl Dec 11, 2018
1fc14c5
Update README.md
euvl Dec 11, 2018
d5ab004
Merge branch 'master' of github.com:euvl/vue-js-toggle-button
euvl Dec 13, 2018
976afd0
Update README.md (#100)
MikhailLoginov Dec 30, 2018
a6f9802
Update README.md available properties syntax. (#106)
frankperez87 Feb 24, 2019
57debd2
Disabled toggle button should not be togglable via keyboard. (#105)
kabalage Feb 24, 2019
91f2bd4
Add margin prop (#99)
domnantas Feb 24, 2019
a63cd2b
Rebuild
euvl Feb 24, 2019
d86802b
Cleanup
euvl Feb 24, 2019
7adaa4f
1.3.2
euvl Feb 24, 2019
90f789f
Bump mixin-deep from 1.3.1 to 1.3.2 (#119)
dependabot[bot] Oct 19, 2019
7a658cb
Bump lodash from 4.17.11 to 4.17.14 (#114)
dependabot[bot] Oct 19, 2019
b14ca02
Bump lodash.mergewith from 4.6.1 to 4.6.2 (#113)
dependabot[bot] Oct 19, 2019
cab9c84
Bump fstream from 1.0.11 to 1.0.12 (#111)
dependabot[bot] Oct 19, 2019
4a60d4d
added basic typescript definition file (#121)
adrianthedev Oct 19, 2019
4dab16c
ability to tag values, add sync blocker (#107)
veebuv Oct 19, 2019
6f8603a
Minor refactoring
euvl Oct 19, 2019
4824a12
Updated build
euvl Oct 22, 2019
242f6fe
1.3.3
euvl Oct 26, 2019
05e431a
Change translate3d to translate (#125)
strateego Jan 2, 2020
24ce674
Create FUNDING
euvl May 16, 2020
9d6ad82
Rename FUNDING to FUNDING.ylm
euvl May 16, 2020
94e40af
Rename FUNDING.ylm to FUNDING.yml
euvl May 16, 2020
1921117
Added keyboard based focus and toggle (#124)
jlucaspains May 16, 2020
1374ff2
Added prettier, fixed a11y
euvl May 16, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: euvl
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ yarn-error.log
demo/dist
*.map
package-lock.json
.vscode
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"arrowParens": "always",
"semi": false,
"trailingComma": "none",
"singleQuote": true
}
106 changes: 63 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,107 @@
[![npm version](https://badge.fury.io/js/vue-js-toggle-button.svg)](https://badge.fury.io/js/vue-js-toggle-button)
[![npm](https://img.shields.io/npm/dm/vue-js-toggle-button.svg)](https://www.npmjs.com/package/vue-js-toggle-button)
<br/>
<a align="right" href="https://www.buymeacoffee.com/yev" target="_blank">
<img width="200" alt="screen shot 2018-03-01 at 10 33 39" src="https://user-images.githubusercontent.com/1577802/36840220-21beb89c-1d3c-11e8-98a4-45fc334842cf.png">
</a>

### Vue.js 2 toggle / switch button - simple, pretty, customizable.

![Imgur](http://i.imgur.com/a2Hf7pm.png)

Feel free to ask questions or propose features in the "Issues" section
<span>
<img src="https://badge.fury.io/js/vue-js-toggle-button.svg">
</span> <span>
<img src="https://img.shields.io/npm/dm/vue-js-toggle-button.svg">
</span>

# Vue.js toggle/switch button.

<p align="right">
<a href="https://www.buymeacoffee.com/yev" target="_blank">
<img
width="140"
alt="Get a coffee"
src="https://user-images.githubusercontent.com/1577802/36840220-21beb89c-1d3c-11e8-98a4-45fc334842cf.png">
</a>
</p>

<p align="center">
<img src="http://i.imgur.com/a2Hf7pm.png">
</p>

[Live demo here](http://vue-js-toggle-button.yev.io/)

Install:
### Install

```bash
npm install vue-js-toggle-button --save
```
Import:

### Import

Import plugin:

```javascript
import ToggleButton from 'vue-js-toggle-button'

Vue.use(ToggleButton)
```
Use:
**OR**

Import component:

```javascript
import { ToggleButton } from 'vue-js-toggle-button'

Vue.component('ToggleButton', ToggleButton)
```

### Use

```xml
<toggle-button @change="onChangeEventHandler"/>

<toggle-button v-model="myDataVariable"/>

<toggle-button :value="false"
color="#82C7EB"
:sync="true"
<toggle-button :value="false"
color="#82C7EB"
:sync="true"
:labels="true"/>

<toggle-button :value="true"
<toggle-button :value="true"
:labels="{checked: 'Foo', unchecked: 'Bar'}"/>
```

### Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| value | Boolean | false | Initial state of the toggle button |
| sync | Boolean | false | If set to `true`, will be watching changes in `value` property and overwrite the current state of the button whenever `value` prop. changes |
| speed | Number | 300 | Transition time for the animation |
| disabled | Boolean | false | Button does not react on mouse events |
| color | [String, Object] | `#75C791` | If `String` - color of the button when checked <br>If `Object` - colors for the button when checked/uncheked <br>Example: `{checked: '#00FF00', unchecked: '#FF0000'}` |
| cssColors | Boolean | false | If `true` - deactivates the setting of colors through inline styles in favor of using CSS styling |
| labels | [Boolean, Object] | false | If `Boolean` - shows/hides default labels ("on" and "off") <br>If `Object` - sets custom labels for both states. <br>Example: `{checked: 'Foo', unchecked: 'Bar'}` |
| width | Number | 50 | Width of the button, default is 50 |
| height | Number | 22 | Height of the button, default is 22 |

`labels` object accepts HTML text (for example, you can use FontAwesome for checked/unchecked states).
| Name | Type | Default | Description |
| --- | --- | --- | --- |
| value | Boolean | false | Initial state of the toggle button |
| sync | Boolean | false | If set to `true`, will be watching changes in `value` property and overwrite the current state of the button whenever `value` prop changes |
| speed | Number | 300 | Transition time for the animation |
| disabled | Boolean | false | Button does not react on mouse events |
| color | [String, Object] | `#75C791` | If `String` - color of the button when checked <br>If `Object` - colors for the button when checked/unchecked or disabled<br>Example: `{checked: '#00FF00', unchecked: '#FF0000', disabled: '#CCCCCC'}` |
| css-colors | Boolean | false | If `true` - deactivates the setting of colors through inline styles in favor of using CSS styling |
| labels | [Boolean, Object] | false | If `Boolean` - shows/hides default labels ("on" and "off") <br>If `Object` - sets custom labels for both states. <br>Example: `{checked: 'Foo', unchecked: 'Bar'}` |
| switch-color | [String, Object] | `#BFCBD9` | If `String` - color or background property of the switch when checked <br>If `Object` - colors or background property for the switch when checked/uncheked <br>Example: `{checked: '#25EF02', unchecked: 'linear-gradient(red, yellow)'}` |
| width | Number | 50 | Width of the button |
| height | Number | 22 | Height of the button |
| margin | Number | 3 | Space between the switch and background border |
| name | String | undefined | Name to attach to the generated input field |
| font-size | Number | undefined | Font size |

### Events

| Name | Description |
| --- | --- |
| change | Triggered whenever state of the component changes. <br>Contains: <br>`value` - state of the object <br>`srcEvent` - source click event |
| input | Input event for v-model |

### SSR

Include plugin in your `nuxt.config.js` file:

```javascript
module.exports = {
plugins: ['~plugins/vue-js-toggle-button']
}
```

And your `plugins/vue-js-toggle-button.js` will look like:

```javascript
import Vue from 'vue'
import Button from 'vue-js-toggle-button/dist/ssr.index'
import Button from 'vue-js-toggle-button'

Vue.use(Button)
```
Expand All @@ -83,13 +113,3 @@ Vue.use(Button)
* Safari: 10+
* IE: 11+

### Font size
To change font size please use basic css:
```css
.vue-js-switch#changed-font {
font-size: 16px;
}
```
```vue
<toggle-button id="changed-font"/>
```
5 changes: 4 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"vue-loader": "^11.1.4",
"vue-template-compiler": "^2.2.1",
"webpack": "^2.2.0",
"webpack-dev-server": "^2.2.0"
"webpack-dev-server": "^2.2.0",
"@fortawesome/fontawesome-svg-core": "^1.2.8",
"@fortawesome/free-solid-svg-icons": "^5.5.0",
"@fortawesome/vue-fontawesome": "^0.1.2"
}
}
60 changes: 48 additions & 12 deletions demo/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<toggle-button :labels="true" color="#82C7EB"/>

<toggle-button :value="true"
name="phone"
:labels="{checked: 'Android', unchecked: 'iPhone'}"
:color="{checked: '#7DCE94', unchecked: '#82C7EB'}"
:width="80"/>
Expand All @@ -30,10 +31,43 @@

<toggle-button
:value="false"
:width="110"
:color="{unchecked: '#FF6699'}"
:labels="{unchecked: 'Disabled button'}"
:width="80"
:labels="{unchecked: 'Disabled'}"
:disabled="true"/>

<toggle-button
:value="false"
:width="140"
:color="{disabled: '#FF6699'}"
:labels="{unchecked: 'Custom disabled color'}"
:disabled="true"/>

<toggle-button :value="true"
:labels="{checked: 'Button', unchecked: 'Color'}"
:color="{checked: '#7DCE94', unchecked: '#82C7EB'}"
:width="80"
:switchColor="{checked: 'linear-gradient(red, yellow)', unchecked: '#F2C00B'}"/>

<toggle-button :labels="true">
<template slot="checked">
<fa icon='check'></fa>
</template>
<template slot="unchecked">
<fa icon='times'></fa>
</template>
</toggle-button>

<toggle-button :width="120" :labels="{checked: '', unchecked: 'FA Icon Support'}">
<template slot="checked">
<fa icon='check'></fa>
</template>
</toggle-button>

<toggle-button
:value="true"
:width="80"
:labels="{checked: 'Custom', unchecked: 'Margin'}"
:margin="7"/>
</div>
<div style="padding-top: 20px;">
<toggle-button
Expand All @@ -50,7 +84,7 @@
<div class="padding">
<h2>And be programatically set/reset</h2>
<div>
<span v-for="(item, i) in items" style="padding: 5px">
<span v-for="(item, i) in items" :key="i" style="padding: 5px">
<toggle-button
:value="item.value"
:color="item.color"
Expand All @@ -71,20 +105,22 @@ export default {
return {
toggled: false,
items: [
{color: '#E8D2AE', value: false},
{color: '#CB8589', value: false},
{color: '#796465', value: false},
{color: '#79BD8F', value: false},
{color: '#00A388', value: false}
{ color: '#E8D2AE', value: false },
{ color: '#CB8589', value: false },
{ color: '#796465', value: false },
{ color: '#79BD8F', value: false },
{ color: '#00A388', value: false }
],
hodor: false
}
},
mounted () {
var i = 0;
var itemIndex = 0;

setInterval(() => {
this.updateItemValue(i)
i = (i + 1) % this.items.length
this.updateItemValue(itemIndex)

itemIndex = (itemIndex + 1) % this.items.length
}, 600)
},
methods: {
Expand Down
6 changes: 6 additions & 0 deletions demo/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Vue from 'vue'
import App from './App.vue'
import ToggleButton from 'plugin'
import { library } from '@fortawesome/fontawesome-svg-core'
import { faCheck, faTimes } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'

library.add([faCheck, faTimes])
Vue.component('fa', FontAwesomeIcon)

Vue.use(ToggleButton)

Expand Down
Loading