forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQLayoutFooter.js
More file actions
160 lines (155 loc) · 4.1 KB
/
QLayoutFooter.js
File metadata and controls
160 lines (155 loc) · 4.1 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
import QResizeObservable from '../observables/QResizeObservable.js'
import QWindowResizeObservable from '../observables/QWindowResizeObservable.js'
import CanRenderMixin from '../../mixins/can-render.js'
import { onSSR } from '../../plugins/platform.js'
export default {
name: 'QLayoutFooter',
mixins: [ CanRenderMixin ],
inject: {
layout: {
default () {
console.error('QLayoutFooter needs to be child of QLayout')
}
}
},
props: {
value: {
type: Boolean,
default: true
},
reveal: Boolean
},
data () {
return {
size: 0,
revealed: true,
windowHeight: onSSR || this.layout.container ? 0 : window.innerHeight
}
},
watch: {
value (val) {
this.__update('space', val)
this.__updateLocal('revealed', true)
this.layout.__animate()
},
offset (val) {
this.__update('offset', val)
},
reveal (val) {
if (!val) {
this.__updateLocal('revealed', this.value)
}
},
revealed (val) {
this.layout.__animate()
this.$emit('reveal', val)
},
'layout.scroll' () {
this.__updateRevealed()
},
'layout.height' () {
this.__updateRevealed()
},
size () {
this.__updateRevealed()
}
},
computed: {
fixed () {
return this.reveal || this.layout.view.indexOf('F') > -1 || this.layout.container
},
containerHeight () {
return this.layout.container
? this.layout.containerHeight
: this.windowHeight
},
offset () {
if (!this.canRender || !this.value) {
return 0
}
if (this.fixed) {
return this.revealed ? this.size : 0
}
const offset = this.layout.scroll.position + this.containerHeight + this.size - this.layout.height
return offset > 0 ? offset : 0
},
computedClass () {
return {
'fixed-bottom': this.fixed,
'absolute-bottom': !this.fixed,
'hidden': !this.value && !this.fixed,
'q-layout-footer-hidden': !this.canRender || !this.value || (this.fixed && !this.revealed)
}
},
computedStyle () {
const
view = this.layout.rows.bottom,
css = {}
if (view[0] === 'l' && this.layout.left.space) {
css[this.$q.i18n.rtl ? 'right' : 'left'] = `${this.layout.left.size}px`
}
if (view[2] === 'r' && this.layout.right.space) {
css[this.$q.i18n.rtl ? 'left' : 'right'] = `${this.layout.right.size}px`
}
return css
}
},
render (h) {
return h('footer', {
staticClass: 'q-layout-footer q-layout-marginal q-layout-transition',
'class': this.computedClass,
style: this.computedStyle
}, [
h(QResizeObservable, {
props: { debounce: 0 },
on: { resize: this.__onResize }
}),
(!this.layout.container && h(QWindowResizeObservable, {
props: { debounce: 0 },
on: { resize: this.__onWindowResize }
})) || void 0,
this.$slots.default
])
},
created () {
this.layout.instances.footer = this
this.__update('space', this.value)
this.__update('offset', this.offset)
},
beforeDestroy () {
if (this.layout.instances.footer === this) {
this.layout.instances.footer = null
this.__update('size', 0)
this.__update('offset', 0)
this.__update('space', false)
}
},
methods: {
__onResize ({ height }) {
this.__updateLocal('size', height)
this.__update('size', height)
},
__onWindowResize ({ height }) {
this.__updateLocal('windowHeight', height)
},
__update (prop, val) {
if (this.layout.footer[prop] !== val) {
this.layout.footer[prop] = val
}
},
__updateLocal (prop, val) {
if (this[prop] !== val) {
this[prop] = val
}
},
__updateRevealed () {
if (!this.reveal) { return }
const { direction, position, inflexionPosition } = this.layout.scroll
this.__updateLocal('revealed', (
direction === 'up' ||
position - inflexionPosition < 100 ||
this.layout.height - this.containerHeight - position - this.size < 300
))
}
}
}