This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
IconToggle.vue
90 lines (87 loc) · 2.14 KB
/
IconToggle.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
<template>
<i class="mdc-icon-toggle" :class="classes" :id="id" role="button" :data-toggle-on="dataToggleOn" :data-toggle-off="dataToggleOff" @click="toggleState">
{{icon+'_border'}}
</i>
</template>
<script>
import { MDCIconToggle } from '@material/icon-toggle'
import { debounce } from '../utils'
export default {
props: {
id: {
type: String,
required: false
},
icon: {
type: String,
required: true
},
disabled: {
type: Boolean,
required: false
},
primary: {
type: Boolean,
required: false
},
accent: {
type: Boolean,
required: false
},
labelOn: {
type: String,
required: false
},
labelOff: {
type: String,
required: false
},
value: {
type: Boolean,
required: true
}
},
data() {
return {
mdcIconToggle: null
}
},
mounted() {
this.mdcIconToggle = new MDCIconToggle(this.$el)
this.mdcIconToggle.disabled = this.disabled
this.mdcIconToggle.on = this.value
},
destroy() {
this.mdcIconToggle.destroy()
},
computed: {
classes() {
return {
'material-icons': true,
'mdc-icon-toggle--disabled': this.disabled,
'mdc-icon-toggle--primary': this.primary,
'mdc-icon-toggle--accent': this.accent
}
},
dataToggleOn() {
return JSON.stringify({ 'content': this.icon, 'label': this.labelOn })
},
dataToggleOff() {
return JSON.stringify({ 'content': this.icon + '_border', 'label': this.labelOff })
}
},
methods: {
toggleState() {
debounce(this.$emit('input', !this.value))
}
},
watch: {
disabled() {
this.iconToggle.disabled = this.disabled
}
}
}
</script>
<style lang="scss">
@import '@material/icon-toggle/mdc-icon-toggle';
</style>