forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQBtnToggle.js
More file actions
93 lines (92 loc) · 2.47 KB
/
QBtnToggle.js
File metadata and controls
93 lines (92 loc) · 2.47 KB
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
import QBtn from './QBtn'
import QBtnGroup from './QBtnGroup'
export default {
name: 'QBtnToggle',
props: {
value: {
required: true
},
// To avoid seeing the active raise shadow through the transparent button, give it a color (even white).
color: String,
textColor: String,
toggleColor: {
type: String,
default: 'primary'
},
toggleTextColor: String,
options: {
type: Array,
required: true,
validator: v => v.every(opt => ('label' in opt || 'icon' in opt) && 'value' in opt)
},
readonly: Boolean,
disable: Boolean,
noCaps: Boolean,
noWrap: Boolean,
outline: Boolean,
flat: Boolean,
dense: Boolean,
rounded: Boolean,
push: Boolean,
size: String,
glossy: Boolean,
noRipple: Boolean,
waitForRipple: Boolean
},
computed: {
val () {
return this.options.map(opt => opt.value === this.value)
}
},
methods: {
set (value, opt) {
if (this.readonly) {
return
}
this.$emit('input', value, opt)
this.$nextTick(() => {
if (JSON.stringify(value) !== JSON.stringify(this.value)) {
this.$emit('change', value, opt)
}
})
}
},
render (h) {
return h(QBtnGroup, {
staticClass: 'q-btn-toggle',
props: {
outline: this.outline,
flat: this.flat,
rounded: this.rounded,
push: this.push
}
},
this.options.map(
(opt, i) => h(QBtn, {
key: `${opt.label}${opt.icon}${opt.iconRight}`,
on: { click: () => this.set(opt.value, opt) },
props: {
disable: this.disable,
label: opt.label,
// Colors come from the button specific options first, then from general props
color: this.val[i] ? opt.toggleColor || this.toggleColor : opt.color || this.color,
textColor: this.val[i] ? opt.toggleTextColor || this.toggleTextColor : opt.textColor || this.textColor,
icon: opt.icon,
iconRight: opt.iconRight,
noCaps: this.noCaps || opt.noCaps,
noWrap: this.noWrap || opt.noWrap,
outline: this.outline,
flat: this.flat,
rounded: this.rounded,
push: this.push,
glossy: this.glossy,
size: this.size,
dense: this.dense,
noRipple: this.noRipple || opt.noRipple,
waitForRipple: this.waitForRipple || opt.waitForRipple,
tabindex: opt.tabindex
}
})
))
}
}