2020-06-29 01:55:10 +00:00
|
|
|
<template>
|
|
|
|
<div class="scroll">
|
|
|
|
<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">
|
|
|
|
<Expand
|
|
|
|
v-if="expanded"
|
|
|
|
:expanded="expanded"
|
|
|
|
class="expand-light"
|
2020-07-01 02:47:05 +00:00
|
|
|
@expand="(state) => $emit('expand', state)"
|
2020-06-29 23:07:48 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<div
|
|
|
|
v-show="enabled && !expanded"
|
|
|
|
class="scroll-button scroll-left noselect"
|
|
|
|
:class="{ 'scroll-start': scrollAtStart }"
|
|
|
|
@click="scroll('left')"
|
|
|
|
><Icon icon="arrow-left3" /></div>
|
|
|
|
|
2020-07-01 02:47:05 +00:00
|
|
|
<slot />
|
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"
|
|
|
|
class="expand-dark"
|
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"
|
|
|
|
class="expand-light"
|
2020-07-01 02:47:05 +00:00
|
|
|
@expand="(state) => $emit('expand', state)"
|
2020-06-29 01:55:10 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Expand from '../expand/expand.vue';
|
|
|
|
|
|
|
|
function updateScroll() {
|
|
|
|
this.scrollable = this.target.scrollWidth > this.target.clientWidth;
|
|
|
|
this.scrollAtStart = this.target.scrollLeft === 0;
|
|
|
|
this.scrollAtEnd = this.target.scrollWidth - this.target.clientWidth === this.target.scrollLeft;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scroll(direction) {
|
|
|
|
if (direction === 'right') {
|
|
|
|
this.target.scrollLeft = this.target.scrollLeft + this.target.clientWidth - 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (direction === 'left') {
|
|
|
|
this.target.scrollLeft = this.target.scrollLeft - this.target.clientWidth + 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mounted() {
|
|
|
|
this.target = this.$slots.default[0].elm;
|
|
|
|
|
2020-07-06 00:40:10 +00:00
|
|
|
this.target.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
|
|
|
|
2020-07-06 00:40:10 +00:00
|
|
|
// typically triggered by slotted component when an image loads, affecting scrollWidth
|
|
|
|
this.$on('load', () => this.updateScroll());
|
2020-06-29 23:07:48 +00:00
|
|
|
this.updateScroll();
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function beforeDestroy() {
|
|
|
|
this.target.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,
|
|
|
|
default: true,
|
|
|
|
},
|
2020-07-01 02:47:05 +00:00
|
|
|
expanded: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2020-06-29 01:55:10 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
target: null,
|
|
|
|
scrollable: true,
|
|
|
|
scrollAtStart: true,
|
|
|
|
scrollAtEnd: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted,
|
2020-06-29 23:07:48 +00:00
|
|
|
updated,
|
2020-06-29 01:55:10 +00:00
|
|
|
beforeDestroy,
|
|
|
|
methods: {
|
|
|
|
scroll,
|
|
|
|
updateScroll,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import 'theme';
|
|
|
|
|
|
|
|
.scroll {
|
|
|
|
background: var(--profile);
|
|
|
|
|
|
|
|
&.expanded {
|
|
|
|
padding: 0;
|
|
|
|
|
|
|
|
.scroll {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 23:07:48 +00:00
|
|
|
.scrollable {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
2020-06-29 02:43:39 +00:00
|
|
|
.expand-light {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
2020-06-29 01:55:10 +00:00
|
|
|
.scroll-light {
|
|
|
|
background: var(--background-dim);
|
|
|
|
|
|
|
|
.scroll-button {
|
|
|
|
.icon {
|
|
|
|
fill: var(--darken);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.scroll-start .icon,
|
|
|
|
&.scroll-end .icon {
|
|
|
|
fill: var(--darken-weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover:not(.scroll-start):not(.scroll-end) .icon {
|
|
|
|
fill: var(--text-dark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-left {
|
|
|
|
background: linear-gradient(to right, var(--background-dim) 50%, transparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-right {
|
|
|
|
background: linear-gradient(to left, var(--background-dim) 50%, transparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
.expand-dark {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-06-29 02:43:39 +00:00
|
|
|
|
|
|
|
.expand-light {
|
|
|
|
display: block;
|
|
|
|
}
|
2020-06-29 01:55:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-dark {
|
|
|
|
background: var(--profile);
|
|
|
|
|
|
|
|
.scroll-button {
|
|
|
|
.icon {
|
|
|
|
fill: var(--lighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.scroll-start .icon,
|
|
|
|
&.scroll-end .icon {
|
|
|
|
fill: var(--darken-weak);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover:not(.scroll-start):not(.scroll-end) .icon {
|
|
|
|
fill: var(--text-light);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-left {
|
|
|
|
background: linear-gradient(to right, var(--profile) 50%, transparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
.scroll-right {
|
|
|
|
background: linear-gradient(to left, var(--profile) 50%, transparent);
|
|
|
|
}
|
|
|
|
|
|
|
|
.expand-light {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-06-29 02:43:39 +00:00
|
|
|
|
|
|
|
.expand-dark {
|
|
|
|
display: block;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
&: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
|
|
|
}
|
|
|
|
|
|
|
|
@media(max-width: $breakpoint) {
|
|
|
|
.scroll-button {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|