-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScrollShadow.vue
106 lines (100 loc) · 2.54 KB
/
ScrollShadow.vue
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
<template>
<div
:style="styleGeneral"
aria-label="container-scroll"
:class="`container ${this.scroll ? 'containerScroll' : ''}`"
>
<div
aria-label="subcontainer-scroll"
ref="component"
class="subcontainer"
:style="styleSubcontainer"
>
<slot />
</div>
</div>
</template>
<script>
import ResizeObserver from 'resize-observer-polyfill';
export default {
name: 'ScrollShadow',
data() {
let styleGeneral = this.styleContainer;
styleGeneral += `--scrollColor:${this.scrollColor};`;
styleGeneral += `--shadow:${this.isShadow ? this.shadow : ''};`;
styleGeneral += `--scrollPadding:${this.scrollPadding};`;
styleGeneral += `--scrollWidth:${this.scrollWidth};`;
styleGeneral += `--scrollColorHover:${this.scrollColorHover}`;
return {
scroll: false,
component: null,
RO: null,
styleGeneral,
classGeneral: 'container'
};
},
props: {
styleContainer: { type: String, default: '' },
styleSubcontainer: { type: String, default: '' },
// Scroll color
scrollColor: { type: String, default: '#c5c5c5' },
// Left scroll padding
scrollPadding: { type: String, default: '0px' },
// Scroll Width
scrollWidth: { type: String, default: '8px' },
// Scroll color when hover
scrollColorHover: { type: String, default: '#a6a6a6' },
shadow: {
type: String,
default:
'0 2px 4px rgba(0, 0, 0, 0.2) inset, 0 -2px 4px rgba(0, 0, 0, 0.2) inset'
},
// Verify shadow is visible
isShadow: { type: Boolean, default: true }
},
mounted() {
const refComponent = this.$refs.component;
const RO = new ResizeObserver(() => {
if (refComponent.clientHeight < refComponent.scrollHeight) {
this.scroll = true;
} else {
this.scroll = false;
}
});
RO.observe(refComponent);
}
};
</script>
<style scoped>
.containerScroll {
box-shadow: var(--shadow);
}
.container {
width: 100%;
overflow-y: hidden;
box-sizing: border-box;
display: flex;
}
.subcontainer {
padding-right: var(--scrollPadding);
overflow-y: auto;
flex: 1;
scrollbar-color: var(--scrollColor);
scrollbar-width: thin;
}
.subcontainer::-webkit-scrollbar {
width: var(--scrollWidth);
background: transparent;
}
.subcontainer::-webkit-scrollbar-track {
background: 'transparent';
}
.subcontainer::-webkit-scrollbar-thumb {
background: var(--scrollColor);
border-radius: 5px;
overflow: hidden;
}
.subcontainer::-webkit-scrollbar-thumb:hover {
background: var(--scrollColorHover);
}
</style>