|
| 1 | +<template> |
| 2 | + <div class="mt-8 w-full"> |
| 3 | + <UCarousel |
| 4 | + ref="carousel" |
| 5 | + v-slot="{ item }" |
| 6 | + :items="preparedPins" |
| 7 | + loop |
| 8 | + arrows |
| 9 | + :auto-scroll="{ |
| 10 | + active: true, |
| 11 | + playOnInit: true, |
| 12 | + startDelay: 200, |
| 13 | + speed: 0.5, |
| 14 | + stopOnInteraction: true, |
| 15 | + stopOnMouseEnter: true, |
| 16 | + }" |
| 17 | + :ui="{ |
| 18 | + item: 'basis-60 py-1', |
| 19 | + prev: 'absolute left-4! size-10 justify-center rounded-full', |
| 20 | + next: 'absolute right-4! size-10 justify-center rounded-full', |
| 21 | + }" |
| 22 | + > |
| 23 | + <NuxtLink |
| 24 | + :to="undefined" |
| 25 | + class="h-full self-start" |
| 26 | + > |
| 27 | + <UPageCard |
| 28 | + variant="subtle" |
| 29 | + :ui="{ |
| 30 | + root: 'w-56 aspect-2/3 self-start hover:scale-98 active:scale-95 duration-200 cursor-pointer', |
| 31 | + container: 'p-0!', |
| 32 | + }" |
| 33 | + > |
| 34 | + <template #body> |
| 35 | + <div v-if="item.type === 'review_quote_with_image'" class="h-full p-2.5 flex flex-col gap-2 justify-between overflow-hidden"> |
| 36 | + <div class="flex flex-col gap-2"> |
| 37 | + <div class="flex flex-row gap-2 items-center line-clamp-1"> |
| 38 | + <UAvatar |
| 39 | + v-if="item.user?.avatarUrl" |
| 40 | + :src="item.user.avatarUrl" |
| 41 | + size="md" |
| 42 | + /> |
| 43 | + <h4 class="font-semibold leading-6"> |
| 44 | + {{ item.user?.name }} |
| 45 | + </h4> |
| 46 | + </div> |
| 47 | + |
| 48 | + <p class="text-sm/4 text-muted italic before:content-[open-quote] after:content-[close-quote] line-clamp-3"> |
| 49 | + {{ item.text }} |
| 50 | + </p> |
| 51 | + </div> |
| 52 | + |
| 53 | + <div class="shrink-0 w-full h-auto aspect-square flex flex-col justify-center items-center rounded-lg"> |
| 54 | + <img |
| 55 | + v-if="item.mediaUrl" |
| 56 | + :src="item.mediaUrl" |
| 57 | + loading="lazy" |
| 58 | + class="w-full h-full object-cover rounded-lg" |
| 59 | + > |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div v-if="item.type === 'image'" class="w-full h-full"> |
| 64 | + <img |
| 65 | + v-if="item.mediaUrl" |
| 66 | + :src="item.mediaUrl" |
| 67 | + loading="lazy" |
| 68 | + class="w-full h-full object-cover rounded-lg" |
| 69 | + > |
| 70 | + </div> |
| 71 | + </template> |
| 72 | + </UPageCard> |
| 73 | + </NuxtLink> |
| 74 | + </UCarousel> |
| 75 | + </div> |
| 76 | +</template> |
| 77 | + |
| 78 | +<script setup lang="ts"> |
| 79 | +import type { ShallowRef, ShallowUnwrapRef } from 'vue' |
| 80 | +import { useMouseInElement } from '@vueuse/core' |
| 81 | +
|
| 82 | +const { pins } = defineProps<{ pins: any[] }>() |
| 83 | +
|
| 84 | +const carousel = useTemplateRef('carousel') |
| 85 | +const { isOutside } = useMouseInElement(carousel as unknown as ShallowRef<ShallowUnwrapRef<HTMLElement>>) |
| 86 | +
|
| 87 | +onMounted(() => { |
| 88 | + const interval = setInterval(() => { |
| 89 | + if (carousel.value && isOutside.value) { |
| 90 | + carousel.value?.emblaApi?.plugins().autoScroll.play() |
| 91 | + } |
| 92 | + }, 2000) |
| 93 | + onBeforeUnmount(() => clearInterval(interval)) |
| 94 | +}) |
| 95 | +
|
| 96 | +const minimum = 9 |
| 97 | +
|
| 98 | +const preparedPins = computed(() => { |
| 99 | + const filtered = pins.filter((pin) => pin.type !== 'empty') |
| 100 | + const emptyCount = Math.max(0, minimum - filtered.length) |
| 101 | + const emptyPins: any[] = Array.from({ length: emptyCount }, (_, i) => ({ |
| 102 | + id: `empty-${i}`, |
| 103 | + createdAt: new Date().toISOString(), |
| 104 | + updatedAt: new Date().toISOString(), |
| 105 | + type: 'image', |
| 106 | + userId: null, |
| 107 | + user: null, |
| 108 | + text: null, |
| 109 | + mediaUrl: '/slider-test.jpg', |
| 110 | + pageId: 'placeholder', |
| 111 | + })) |
| 112 | + return [...filtered, ...emptyPins] |
| 113 | +}) |
| 114 | +</script> |
0 commit comments