Line data Source code
1 : <template>
2 : <div
3 0 : v-if="skeleton"
4 : :data-testid="testid"
5 : class="relative aspect-square overflow-hidden rounded-2xl"
6 : >
7 : <Skeleton class="absolute inset-0 rounded-2xl" />
8 : <Skeleton class="absolute inset-x-4 bottom-4 h-4 w-2/3" />
9 : </div>
10 : <div
11 : v-else
12 : ref="cardRef"
13 : role="button"
14 : :tabindex="loading ? -1 : 0"
15 : :aria-disabled="loading"
16 : :data-testid="testid"
17 : :aria-label="failed ? t('gettingStarted.retryTemplate', { title }) : title"
18 : :aria-busy="loading"
19 : class="group/card relative cursor-pointer overflow-hidden rounded-2xl focus-visible:ring-1 focus-visible:ring-ring focus-visible:outline-none"
20 : @click="onSelect"
21 : @keydown.enter.prevent="onSelect"
22 : @keydown.space.prevent="onSelect"
23 : >
24 : <DefaultThumbnail
25 : :src="imageSrc"
26 : :alt="title"
27 : :is-hovered
28 : :is-video
29 : :hover-zoom="5"
30 : />
31 : <div
32 : aria-hidden="true"
33 : class="pointer-events-none absolute inset-0 bg-linear-to-b from-black/60 via-black/20 via-50% to-black/70 transition-opacity duration-300 ease-out group-hover/card:opacity-0"
34 : />
35 : <div
36 : v-if="badgeIcon"
37 : aria-hidden="true"
38 : class="pointer-events-none absolute top-3 right-3 flex size-7 items-center justify-center rounded-full bg-black/50 backdrop-blur-sm"
39 : >
40 : <i :class="badgeIcon" />
41 : </div>
42 : <h3
43 : class="absolute inset-x-0 bottom-0 m-0 truncate p-4 text-sm font-semibold drop-shadow-md"
44 : :title
45 : >
46 : {{ title }}
47 : </h3>
48 : <div
49 : v-if="loading"
50 : class="absolute inset-0 flex items-center justify-center bg-background/70 backdrop-blur-md"
51 : >
52 : <Loader size="md" />
53 : </div>
54 : <div
55 : v-else-if="failed"
56 : class="pointer-events-none absolute inset-0 flex flex-col items-center justify-center gap-1 bg-background/80 p-4 text-xs backdrop-blur-md"
57 : >
58 : <span class="text-center font-medium">
59 : {{ t('gettingStarted.templateFailed') }}
60 : </span>
61 : <span class="font-semibold text-primary">
62 : {{ t('gettingStarted.retry') }}
63 : </span>
64 : </div>
65 : </div>
66 : </template>
67 :
68 : <script setup lang="ts">
69 : import { useElementHover } from '@vueuse/core'
70 : import { useTemplateRef } from 'vue'
71 : import { useI18n } from 'vue-i18n'
72 :
73 : import Loader from '@/components/loader/Loader.vue'
74 : import DefaultThumbnail from '@/platform/workflow/templates/components/thumbnails/DefaultThumbnail.vue'
75 : import Skeleton from '@comfyorg/design-system/skeleton/Skeleton'
76 :
77 : const {
78 : imageSrc = '',
79 : title = '',
80 : loading
81 : } = defineProps<{
82 : imageSrc?: string
83 : title?: string
84 : loading?: boolean
85 : /** Shows an inline error; selecting the card again retries. */
86 : failed?: boolean
87 : skeleton?: boolean
88 : isVideo?: boolean
89 : badgeIcon?: string
90 : testid?: string
91 : }>()
92 :
93 0 : const emit = defineEmits<{ select: [] }>()
94 :
95 0 : const { t } = useI18n()
96 :
97 0 : const cardRef = useTemplateRef<HTMLElement>('cardRef')
98 0 : const isHovered = useElementHover(cardRef)
99 :
100 0 : function onSelect() {
101 0 : if (loading) return
102 0 : emit('select')
103 : }
104 : </script>
|