2020-06-29 01:55:10 +00:00
|
|
|
<template>
|
|
|
|
<div class="scroll">
|
2021-01-15 03:04:32 +00:00
|
|
|
<Expand
|
|
|
|
v-if="expanded"
|
|
|
|
:expanded="expanded"
|
|
|
|
class="expand-light"
|
|
|
|
@expand="(state) => $emit('expand', state)"
|
|
|
|
/>
|
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
<Expand
|
|
|
|
v-if="expanded"
|
|
|
|
:expanded="expanded"
|
|
|
|
class="expand-dark"
|
2020-07-01 02:47:05 +00:00
|
|
|
@expand="(state) => $emit('expand', state)"
|
2020-06-29 01:55:10 +00:00
|
|
|
/>
|
|
|
|
|
2020-06-29 23:07:48 +00:00
|
|
|
<div class="scrollable">
|
|
|
|
<div
|
|
|
|
v-show="enabled && !expanded"
|
|
|
|
class="scroll-button scroll-left noselect"
|
|
|
|
:class="{ 'scroll-start': scrollAtStart }"
|
|
|
|
@click="scroll('left')"
|
|
|
|
><Icon icon="arrow-left3" /></div>
|
|
|
|
|
2020-12-26 22:51:27 +00:00
|
|
|
<div
|
|
|
|
ref="content"
|
2021-01-23 22:26:56 +00:00
|
|
|
class="scroll-content"
|
2020-12-26 22:51:27 +00:00
|
|
|
>
|
|
|
|
<slot :loaded="loaded" />
|
|
|
|
</div>
|
2020-06-29 23:07:48 +00:00
|
|
|
|
|
|
|
<div
|
|
|
|
v-show="enabled && !expanded"
|
|
|
|
class="scroll-button scroll-right noselect"
|
|
|
|
:class="{ 'scroll-end': scrollAtEnd }"
|
|
|
|
@click="scroll('right')"
|
|
|
|
><Icon icon="arrow-right3" /></div>
|
|
|
|
</div>
|
2020-06-29 01:55:10 +00:00
|
|
|
|
|
|
|
<Expand
|
2020-06-29 23:07:48 +00:00
|
|
|
v-if="expanded || (expandable && scrollable)"
|
2020-06-29 01:55:10 +00:00
|
|
|
:expanded="expanded"
|
2021-01-15 03:04:32 +00:00
|
|
|
class="expand-light"
|
2020-07-01 02:47:05 +00:00
|
|
|
@expand="(state) => $emit('expand', state)"
|
2020-06-29 01:55:10 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<Expand
|
2020-06-29 23:07:48 +00:00
|
|
|
v-if="expanded || (expandable && scrollable)"
|
2020-06-29 01:55:10 +00:00
|
|
|
:expanded="expanded"
|
2021-01-15 03:04:32 +00:00
|
|
|
class="expand-dark"
|
2020-07-01 02:47:05 +00:00
|
|
|
@expand="(state) => $emit('expand', state)"
|
2020-06-29 01:55:10 +00:00
|
|
|
/>
|
2021-01-24 16:44:34 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
v-if="album && items && items.length > 0 && scrollable"
|
|
|
|
class="album-toggle"
|
|
|
|
@click="showAlbum = true"
|
|
|
|
><Icon icon="grid3" />View album</button>
|
2020-06-29 01:55:10 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Expand from '../expand/expand.vue';
|
|
|
|
|
|
|
|
function updateScroll() {
|
2020-12-26 22:51:27 +00:00
|
|
|
this.scrollable = this.$refs.content.scrollWidth > this.$refs.content.clientWidth;
|
|
|
|
this.scrollAtStart = this.$refs.content.scrollLeft === 0;
|
|
|
|
this.scrollAtEnd = this.$refs.content.scrollWidth - this.$refs.content.clientWidth === this.$refs.content.scrollLeft;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scroll(direction) {
|
|
|
|
if (direction === 'right') {
|
2020-12-26 22:51:27 +00:00
|
|
|
this.$refs.content.scrollLeft = this.$refs.content.scrollLeft + this.$refs.content.clientWidth - 100;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (direction === 'left') {
|
2020-12-26 22:51:27 +00:00
|
|
|
this.$refs.content.scrollLeft = this.$refs.content.scrollLeft - this.$refs.content.clientWidth + 100;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-26 22:51:27 +00:00
|
|
|
function loaded(_event) {
|
|
|
|
// typically triggered by slotted component when an image loads, affecting scrollWidth
|
|
|
|
this.updateScroll();
|
|
|
|
}
|
2020-06-29 01:55:10 +00:00
|
|
|
|
2020-12-26 22:51:27 +00:00
|
|
|
function mounted() {
|
|
|
|
this.$refs.content.addEventListener('scroll', () => this.updateScroll());
|
2020-06-29 01:55:10 +00:00
|
|
|
window.addEventListener('resize', this.updateScroll);
|
2020-06-29 23:07:48 +00:00
|
|
|
|
|
|
|
this.updateScroll();
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 03:20:13 +00:00
|
|
|
function beforeUnmount() {
|
2020-12-26 22:51:27 +00:00
|
|
|
this.$refs.content.removeEventListener('scroll', this.updateScroll);
|
2020-07-06 00:40:10 +00:00
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
window.removeEventListener('resize', this.updateScroll);
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:07:48 +00:00
|
|
|
function updated() {
|
|
|
|
this.updateScroll();
|
|
|
|
}
|
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
Expand,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
enabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
expandable: {
|
|
|
|
type: Boolean,
|
2021-02-03 18:21:47 +00:00
|
|
|
default: false,
|
2020-06-29 01:55:10 +00:00
|
|
|
},
|
2020-07-01 02:47:05 +00:00
|
|
|
expanded: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-01-24 16:44:34 +00:00
|
|
|
album: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-01-24 16:16:55 +00:00
|
|
|
items: {
|
|
|
|
type: Array,
|
|
|
|
default: null,
|
|
|
|
},
|
2020-06-29 01:55:10 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
scrollable: true,
|
|
|
|
scrollAtStart: true,
|
|
|
|
scrollAtEnd: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted,
|
2020-06-29 23:07:48 +00:00
|
|
|
updated,
|
2020-12-29 03:20:13 +00:00
|
|
|
beforeUnmount,
|
2020-06-29 01:55:10 +00:00
|
|
|
methods: {
|
|
|
|
scroll,
|
2020-12-26 22:51:27 +00:00
|
|
|
loaded,
|
2020-06-29 01:55:10 +00:00
|
|
|
updateScroll,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-01-19 14:58:27 +00:00
|
|
|
@import 'breakpoints';
|
2020-06-29 01:55:10 +00:00
|
|
|
|
2020-12-29 03:20:13 +00:00
|
|
|
.scroll.expanded {
|
|
|
|
padding: 0;
|
2020-06-29 01:55:10 +00:00
|
|
|
|
2020-12-29 03:20:13 +00:00
|
|
|
.scroll {
|
|
|
|
display: none;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:07:48 +00:00
|
|
|
.scrollable {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2021-01-23 22:26:56 +00:00
|
|
|
.scroll-content {
|
2020-12-26 22:51:27 +00:00
|
|
|
overflow-x: scroll;
|
|
|
|
scroll-behavior: smooth;
|
|
|
|
scrollbar-width: none;
|
|
|
|
|
|
|
|
&::-webkit-scrollbar {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
.scroll-button {
|
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
box-sizing: border-box;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
bottom: 0;
|
2020-06-29 02:43:39 +00:00
|
|
|
z-index: 10;
|
2020-06-29 01:55:10 +00:00
|
|
|
|
|
|
|
&.scroll-start,
|
|
|
|
&.scroll-end {
|
|
|
|
/* use over v-show so button stays visible while still hovered */
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-12-26 22:51:27 +00:00
|
|
|
&.scroll-start {
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.scroll-end {
|
|
|
|
right: 0;
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:02:18 +00:00
|
|
|
.icon {
|
|
|
|
width: 1.5rem;
|
|
|
|
height: 1.5rem;
|
|
|
|
fill: var(--lighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.scroll-start .icon,
|
|
|
|
&.scroll-end .icon {
|
|
|
|
fill: var(--lighten-weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover:not(.scroll-start):not(.scroll-end) .icon {
|
|
|
|
fill: var(--lighten-strong);
|
|
|
|
}
|
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
&:hover {
|
|
|
|
display: flex;
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-left {
|
|
|
|
left: 0;
|
2020-07-02 02:04:28 +00:00
|
|
|
padding: 1rem 2rem 1rem .5rem;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-right {
|
|
|
|
right: 0;
|
2020-07-02 02:04:28 +00:00
|
|
|
padding: 1rem .5rem 1rem 2rem;
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 20:24:20 +00:00
|
|
|
.scroll .expand-light {
|
2021-01-15 03:04:32 +00:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2021-01-17 20:24:20 +00:00
|
|
|
.scroll-light {
|
|
|
|
.expand-light {
|
|
|
|
display: block;
|
|
|
|
}
|
2021-01-15 03:04:32 +00:00
|
|
|
|
2021-01-17 20:24:20 +00:00
|
|
|
.expand-dark {
|
2020-06-29 01:55:10 +00:00
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2021-01-17 20:24:20 +00:00
|
|
|
|
|
|
|
.scroll-dark .expand-light {
|
|
|
|
display: none;
|
|
|
|
}
|
2021-01-19 14:58:27 +00:00
|
|
|
|
|
|
|
@media(max-width: $breakpoint-micro) {
|
|
|
|
/* buttons block swiping motion */
|
|
|
|
.scroll-button {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2020-06-29 01:55:10 +00:00
|
|
|
</style>
|