forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQPageSticky.js
More file actions
117 lines (109 loc) · 2.76 KB
/
QPageSticky.js
File metadata and controls
117 lines (109 loc) · 2.76 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
import { cssTransform } from '../../utils/dom'
export default {
name: 'QPageSticky',
inject: {
layout: {
default () {
console.error('QPageSticky needs to be child of QLayout')
}
}
},
props: {
position: {
type: String,
default: 'bottom-right',
validator: v => [
'top-right', 'top-left',
'bottom-right', 'bottom-left',
'top', 'right', 'bottom', 'left'
].includes(v)
},
offset: {
type: Array,
validator: v => v.length === 2
},
expand: Boolean
},
computed: {
attach () {
const pos = this.position
return {
top: pos.indexOf('top') > -1,
right: pos.indexOf('right') > -1,
bottom: pos.indexOf('bottom') > -1,
left: pos.indexOf('left') > -1,
vertical: pos === 'top' || pos === 'bottom',
horizontal: pos === 'left' || pos === 'right'
}
},
top () {
return this.layout.header.offset
},
right () {
return this.layout.right.offset
},
bottom () {
return this.layout.footer.offset
},
left () {
return this.layout.left.offset
},
computedStyle () {
const
attach = this.attach,
transforms = [],
dir = this.$q.i18n.rtl ? -1 : 1
if (attach.top && this.top) {
transforms.push(`translateY(${this.top}px)`)
}
else if (attach.bottom && this.bottom) {
transforms.push(`translateY(${-this.bottom}px)`)
}
if (attach.left && this.left) {
transforms.push(`translateX(${dir * this.left}px)`)
}
else if (attach.right && this.right) {
transforms.push(`translateX(${-dir * this.right}px)`)
}
const css = transforms.length
? cssTransform(transforms.join(' '))
: {}
if (this.offset) {
css.margin = `${this.offset[1]}px ${this.offset[0]}px`
}
if (attach.vertical) {
if (this.left) {
css[this.$q.i18n.rtl ? 'right' : 'left'] = `${this.left}px`
}
if (this.right) {
css[this.$q.i18n.rtl ? 'left' : 'right'] = `${this.right}px`
}
}
else if (attach.horizontal) {
if (this.top) {
css.top = `${this.top}px`
}
if (this.bottom) {
css.bottom = `${this.bottom}px`
}
}
return css
},
classes () {
return [ `fixed-${this.position}`, `q-page-sticky-${this.expand ? 'expand' : 'shrink'}` ]
}
},
render (h) {
return h('div', {
staticClass: 'q-page-sticky q-layout-transition z-fixed row flex-center',
'class': this.classes,
style: this.computedStyle
}, [
this.expand
? this.$slots.default
: h('span', [
this.$slots.default
])
])
}
}