Line data Source code
1 : <script setup lang="ts">
2 : import { cn } from '@comfyorg/tailwind-utils'
3 : import { useResizeObserver } from '@vueuse/core'
4 : import { nextTick, onMounted, ref, useTemplateRef, watch } from 'vue'
5 : import { useI18n } from 'vue-i18n'
6 :
7 : const { description } = defineProps<{ description: string }>()
8 2355 : const { t } = useI18n()
9 :
10 : /** Clipping depends on rendered width, so it is measured rather than counted. */
11 0 : const showFullDescription = ref(false)
12 0 : const descriptionElement =
13 : useTemplateRef<HTMLParagraphElement>('descriptionElement')
14 0 : const descriptionOverflows = ref(false)
15 :
16 0 : function measureDescriptionOverflow() {
17 0 : const element = descriptionElement.value
18 0 : descriptionOverflows.value =
19 : !!element && element.scrollHeight > element.clientHeight + 1
20 : }
21 :
22 0 : onMounted(measureDescriptionOverflow)
23 0 : useResizeObserver(descriptionElement, measureDescriptionOverflow)
24 :
25 : /** A clamped paragraph keeps its height, so the resize observer never fires here. */
26 0 : watch(
27 : () => description,
28 : () => {
29 0 : showFullDescription.value = false
30 0 : void nextTick(measureDescriptionOverflow)
31 : }
32 : )
33 0 : </script>
34 :
35 : <template>
36 : <p
37 : ref="descriptionElement"
38 : :class="
39 : cn(
40 : 'm-0 max-w-2xl overflow-hidden text-sm/relaxed wrap-break-word text-muted-foreground transition-[max-height] duration-200 ease-out [interpolate-size:allow-keywords] motion-reduce:transition-none',
41 : showFullDescription ? 'max-h-max' : 'line-clamp-3 max-h-[3lh]'
42 : )
43 : "
44 : >
45 : {{ description }}
46 : </p>
47 : <!--
48 : Expanding removes the overflow that revealed this control, so the expanded
49 : state has to keep it rendered or there is no way back to three lines.
50 : -->
51 : <button
52 : v-if="descriptionOverflows || showFullDescription"
53 : type="button"
54 : class="m-0 flex w-fit cursor-pointer items-center gap-1 border-0 bg-transparent p-0 text-sm hover:underline"
55 : :aria-expanded="showFullDescription"
56 : @click="showFullDescription = !showFullDescription"
57 : >
58 : {{
59 : t(
60 : showFullDescription
61 : ? 'templateWorkflows.detail.descriptionLess'
62 : : 'templateWorkflows.detail.descriptionMore'
63 : )
64 : }}
65 : <i
66 : aria-hidden="true"
67 : :class="
68 : cn(
69 : 'icon-[lucide--chevron-down] size-3.5 transition-transform duration-200 motion-reduce:transition-none',
70 : showFullDescription && 'rotate-180'
71 : )
72 : "
73 : />
74 : </button>
75 : </template>
|