forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
QFab.js
176 lines (143 loc) · 3.94 KB
/
QFab.js
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import Vue from 'vue'
import QBtn from '../btn/QBtn.js'
import QIcon from '../icon/QIcon.js'
import FabMixin from '../../mixins/fab.js'
import AttrsMixin from '../../mixins/attrs.js'
import ModelToggleMixin from '../../mixins/model-toggle.js'
import { slot, mergeSlot } from '../../utils/private/slot.js'
import cache from '../../utils/private/cache.js'
import uid from '../../utils/uid.js'
const directions = ['up', 'right', 'down', 'left']
const alignValues = [ 'left', 'center', 'right' ]
export default Vue.extend({
name: 'QFab',
inheritAttrs: false,
mixins: [ FabMixin, AttrsMixin, ModelToggleMixin ],
provide () {
return {
__qFab: this
}
},
props: {
icon: String,
activeIcon: String,
hideIcon: Boolean,
hideLabel: {
default: null
},
direction: {
type: String,
default: 'right',
validator: v => directions.includes(v)
},
persistent: Boolean,
verticalActionsAlign: {
type: String,
default: 'center',
validator: v => alignValues.includes(v)
}
},
data () {
return {
showing: this.value === true
}
},
computed: {
hideOnRouteChange () {
return this.persistent !== true
},
classes () {
return `q-fab--align-${this.verticalActionsAlign} ${this.formClass}` +
(this.showing === true ? ' q-fab--opened' : '')
},
actionsClasses () {
return `q-fab__actions--${this.direction}` + (this.showing === true ? ' q-fab__actions--opened' : '')
},
actionsAttrs () {
const attrs = {
id: this.targetUid,
role: 'menu'
}
if (this.showing !== true) {
attrs['aria-hidden'] = 'true'
}
return attrs
},
iconHolderClasses () {
return this.showing === true ? 'q-fab__icon-holder--opened' : ''
},
attrs () {
return {
'aria-expanded': this.showing === true ? 'true' : 'false',
'aria-haspopup': 'true',
'aria-controls': this.targetUid,
...this.qAttrs
}
},
slotScope () {
return { opened: this.showing }
}
},
methods: {
__onChildClick (evt) {
this.hide(evt)
if (this.$refs.trigger && this.$refs.trigger.$el) {
this.$refs.trigger.$el.focus()
}
},
__getIcon (h, kebab, camel) {
const slotFn = this.$scopedSlots[kebab]
const staticClass = `q-fab__${kebab} absolute-full`
return slotFn === void 0
? h(QIcon, { staticClass, props: { name: this[camel] || this.$q.iconSet.fab[camel] } })
: h('div', { staticClass }, slotFn(this.slotScope))
}
},
render (h) {
const child = []
this.hideIcon !== true && child.push(
h('div', { staticClass: 'q-fab__icon-holder', class: this.iconHolderClasses }, [
this.__getIcon(h, 'icon', 'icon'),
this.__getIcon(h, 'active-icon', 'activeIcon')
])
)
if (this.label !== '' || this.$scopedSlots.label !== void 0) {
child[this.labelProps.action](
h('div', this.labelProps.data, this.$scopedSlots.label !== void 0 ? this.$scopedSlots.label(this.slotScope) : [ this.label ])
)
}
return h('div', {
staticClass: 'q-fab z-fab row inline justify-center',
class: this.classes,
on: { ...this.qListeners }
}, [
h(QBtn, {
key: 'tog',
ref: 'trigger',
class: this.formClass,
props: {
...this.$props,
noWrap: true,
stack: this.stacked,
align: void 0,
icon: void 0,
label: void 0,
noCaps: true,
fab: true
},
attrs: this.attrs,
on: cache(this, 'tog', {
click: this.toggle
})
}, mergeSlot(child, this, 'tooltip')),
h('div', {
staticClass: 'q-fab__actions flex no-wrap inline',
class: this.actionsClasses,
attrs: this.actionsAttrs
}, slot(this, 'default'))
])
},
created () {
this.targetUid = `fb_${uid()}`
}
})