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

46 lines
1.2 KiB
Vue
Raw Normal View History

2022-07-16 09:52:39 +00:00
<template>
2024-04-04 22:20:42 +00:00
<article
:class="layout"
:style="{ backgroundImage: `url(${defaultCover})` }"
class="thumbnail-stack aspect-square overflow-hidden grid bg-cover bg-no-repeat"
>
2022-07-22 14:35:30 +00:00
<span
v-for="thumbnail in displayedThumbnails"
2024-04-04 22:20:42 +00:00
:key="thumbnail"
:style="{ backgroundImage: `url(${thumbnail}` }"
2024-04-04 22:20:42 +00:00
class="block will-change-transform w-full h-full bg-cover bg-no-repeat"
2022-07-22 14:35:30 +00:00
data-testid="thumbnail"
/>
2024-04-04 22:20:42 +00:00
</article>
2022-07-16 09:52:39 +00:00
</template>
<script lang="ts" setup>
import { take } from 'lodash'
import { computed, toRefs } from 'vue'
import { defaultCover } from '@/utils'
const props = defineProps<{ thumbnails: string[] }>()
2024-04-23 21:01:27 +00:00
const defaultBackgroundImage = `url(${defaultCover})`
2024-04-04 22:20:42 +00:00
2022-07-16 09:52:39 +00:00
const { thumbnails } = toRefs(props)
const displayedThumbnails = computed(() => {
return thumbnails.value.length === 0
2022-07-16 09:52:39 +00:00
? [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>
2024-04-04 20:13:35 +00:00
<style lang="postcss" scoped>
2024-04-04 22:20:42 +00:00
article {
background-image: v-bind(defaultBackgroundImage);
2022-07-16 09:52:39 +00:00
&.tiles {
2024-04-04 22:20:42 +00:00
@apply grid-cols-2;
2022-07-16 09:52:39 +00:00
}
}
</style>