koel/resources/assets/js/components/ui/ThumbnailStack.vue

50 lines
1.3 KiB
Vue
Raw Normal View History

2022-07-16 09:52:39 +00:00
<template>
2022-07-16 15:44:45 +00:00
<div class="thumbnail-stack" :class="layout" :style="{ backgroundImage: `url(${defaultCover})` }">
2022-07-22 14:35:30 +00:00
<span
v-for="thumbnail in displayedThumbnails"
:style="{ backgroundImage: `url(${thumbnail}`}"
data-testid="thumbnail"
/>
2022-07-16 09:52:39 +00:00
</div>
</template>
<script lang="ts" setup>
import { take } from 'lodash'
import { computed, toRefs } from 'vue'
import { defaultCover } from '@/utils'
const props = defineProps<{ thumbnails: string[] }>()
const { thumbnails } = toRefs(props)
const displayedThumbnails = computed(() => {
return thumbnails.value.length == 0
? [defaultCover]
: (thumbnails.value.length < 4 ? [thumbnails.value[0]] : take(thumbnails.value, 4)).map(url => url || defaultCover)
})
2022-07-22 14:35:30 +00:00
const layout = computed<'single' | 'tiles'>(() => displayedThumbnails.value.length < 4 ? 'single' : 'tiles')
2022-07-16 09:52:39 +00:00
</script>
<style lang="scss" scoped>
.thumbnail-stack {
aspect-ratio: 1/1;
display: grid;
overflow: hidden;
2022-07-16 15:44:45 +00:00
background-size: cover;
background-repeat: no-repeat;
2022-07-16 09:52:39 +00:00
&.tiles {
grid-template-columns: 1fr 1fr;
}
span {
display: block;
2022-07-16 15:44:45 +00:00
will-change: transform; // fix anti-aliasing problem with background images
2022-07-16 09:52:39 +00:00
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
}
}
</style>