-
Notifications
You must be signed in to change notification settings - Fork 41
/
switches.vue
95 lines (73 loc) · 1.97 KB
/
switches.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<label :class="classObject">
<span class="vue-switcher__label" v-if="shouldShowLabel">
<span v-if="label" v-text="label"></span>
<span v-if="!label && value" v-text="textEnabled"></span>
<span v-if="!label && !value" v-text="textDisabled"></span>
</span>
<input type="checkbox" :disabled="disabled" @change="trigger" :checked="value">
<div></div>
</label>
</template>
<script>
export default {
name: 'switches',
props: {
typeBold: {
default: false
},
value: {
default: false
},
disabled: {
default: false
},
label: {
default: ''
},
textEnabled: {
default: ''
},
textDisabled: {
default: ''
},
color: {
default: 'default'
},
theme: {
default: 'default'
},
emitOnMount: {
default: true
}
},
mounted () {
if(this.emitOnMount) {
this.$emit('input', this.value)
}
},
methods: {
trigger (e) {
this.$emit('input', e.target.checked)
}
},
computed: {
classObject () {
const { color, value, theme, typeBold, disabled } = this;
return {
'vue-switcher' : true,
['vue-switcher--unchecked'] : !value,
['vue-switcher--disabled'] : disabled,
['vue-switcher--bold']: typeBold,
['vue-switcher--bold--unchecked']: typeBold && !value,
[`vue-switcher-theme--${theme}`] : color,
[`vue-switcher-color--${color}`] : color,
};
},
shouldShowLabel () {
return this.label !== '' || this.textEnabled !== '' || this.textDisabled !== '';
}
}
}
</script>
<style src="./../dist/switches.css"></style>