forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQFixedPosition.vue
More file actions
71 lines (65 loc) · 1.82 KB
/
QFixedPosition.vue
File metadata and controls
71 lines (65 loc) · 1.82 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
<template>
<div class="z-fixed" :class="[`fixed-${corner}`]" :style="style">
<slot></slot>
</div>
</template>
<script>
import extend from '../../utils/extend'
import { cssTransform } from '../../utils/dom'
const sides = ['top', 'right', 'bottom', 'left']
export default {
name: 'q-fixed-position',
props: {
corner: {
type: String,
default: 'bottom-right',
validator: v => ['top-right', 'top-left', 'bottom-right', 'bottom-left'].includes(v)
},
offset: {
type: Array,
validator: v => v.length === 2
}
},
inject: ['layout'],
computed: {
animated () {
return this.pos.top && this.layout.reveal
},
pos () {
return {
top: this.corner.indexOf('top') > -1,
right: this.corner.indexOf('right') > -1,
bottom: this.corner.indexOf('bottom') > -1,
left: this.corner.indexOf('left') > -1
}
},
style () {
const
css = {},
layout = this.layout,
page = layout.computedPageStyle
if (this.offset) {
css.margin = `${this.offset[1]}px ${this.offset[0]}px`
}
if (this.animated && !layout.showHeader) {
extend(css, cssTransform(`translateY(${-layout.header.h}px)`))
}
else if (this.pos.top && layout.offsetTop) {
if (layout.offsetTop > 0) {
extend(css, cssTransform(`translateY(${layout.offsetTop}px)`))
}
}
else if (this.pos.bottom && layout.offsetBottom) {
extend(css, cssTransform(`translateY(${layout.offsetBottom}px)`))
}
sides.forEach(side => {
let prop = `padding${side.charAt(0).toUpperCase() + side.slice(1)}`
if (this.pos[side] && page[prop]) {
css[side] = css[side] ? `calc(${page[prop]} + ${css[side]})` : page[prop]
}
})
return css
}
}
}
</script>