forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQBtnDropdown.js
More file actions
162 lines (159 loc) · 3.81 KB
/
QBtnDropdown.js
File metadata and controls
162 lines (159 loc) · 3.81 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import BtnMixin from './btn-mixin'
import QBtn from './QBtn'
import QBtnGroup from './QBtnGroup'
import { QPopover } from '../popover'
export default {
name: 'QBtnDropdown',
mixins: [BtnMixin],
props: {
value: Boolean,
split: Boolean,
contentClass: [Array, String, Object],
contentStyle: [Array, String, Object]
},
data () {
return {
showing: this.value
}
},
watch: {
value (val) {
this.$refs.popover[val ? 'show' : 'hide']()
}
},
render (h) {
const
Popover = h(
QPopover,
{
ref: 'popover',
props: {
disable: this.disable,
fit: true,
anchorClick: !this.split,
anchor: 'bottom right',
self: 'top right'
},
'class': this.contentClass,
style: this.contentStyle,
on: {
show: e => {
this.showing = true
this.$emit('show', e)
this.$emit('input', true)
},
hide: e => {
this.showing = false
this.$emit('hide', e)
this.$emit('input', false)
}
}
},
[ this.$slots.default ]
),
Icon = h(
'QIcon',
{
props: {
name: this.$q.icon.input.dropdown
},
staticClass: 'transition-generic',
'class': {
'rotate-180': this.showing,
'on-right': !this.split,
'q-btn-dropdown-arrow': !this.split
}
}
),
Btn = h(QBtn, {
props: {
loading: this.loading,
disable: this.disable,
noCaps: this.noCaps,
noWrap: this.noWrap,
icon: this.icon,
label: this.label,
iconRight: this.split ? this.iconRight : null,
outline: this.outline,
flat: this.flat,
rounded: this.rounded,
push: this.push,
size: this.size,
color: this.color,
textColor: this.textColor,
glossy: this.glossy,
dense: this.dense,
noRipple: this.noRipple,
waitForRipple: this.waitForRipple
},
'class': this.split ? 'q-btn-dropdown-current' : 'q-btn-dropdown q-btn-dropdown-simple',
on: {
click: e => {
this.split && this.hide()
if (!this.disable) {
this.$emit('click', e)
}
}
}
}, this.split ? null : [ Icon, Popover ])
if (!this.split) {
return Btn
}
return h(
QBtnGroup,
{
props: {
outline: this.outline,
flat: this.flat,
rounded: this.rounded,
push: this.push
},
staticClass: 'q-btn-dropdown q-btn-dropdown-split no-wrap q-btn-item'
},
[
Btn,
h(
QBtn,
{
props: {
disable: this.disable,
outline: this.outline,
flat: this.flat,
rounded: this.rounded,
push: this.push,
size: this.size,
color: this.color,
textColor: this.textColor,
dense: this.dense,
glossy: this.glossy,
noRipple: this.noRipple,
waitForRipple: this.waitForRipple
},
staticClass: 'q-btn-dropdown-arrow',
on: { click: () => { this.toggle() } }
},
[ Icon ]
),
[ Popover ]
]
)
},
methods: {
toggle () {
return this.$refs.popover.toggle()
},
show () {
return this.$refs.popover.show()
},
hide () {
return this.$refs.popover.hide()
}
},
mounted () {
this.$nextTick(() => {
if (this.value) {
this.$refs.popover.show()
}
})
}
}