Line data Source code
1 : <template>
2 12517 : <PopoverRoot v-model:open="open">
3 : <PopoverAnchor as="template" :reference="anchor ?? undefined" />
4 : <PopoverContent
5 : :side-offset="8"
6 : class="workflow-popover-fade w-fit rounded-xl border-none bg-transparent p-0 shadow-lg transition-opacity duration-150 ease-out data-[state=closed]:animate-none data-[state=open]:animate-none"
7 : @open-auto-focus="!clicked && $event.preventDefault()"
8 : @close-auto-focus.prevent="restoreFocus"
9 : @interact-outside="onInteractOutside"
10 : @mouseenter="stopHide"
11 : @mouseleave="hidePopover"
12 : >
13 : <div
14 : class="flex max-w-62.5 flex-col overflow-hidden rounded-xl bg-popover text-foreground"
15 : >
16 : <div
17 : v-if="thumbnailUrl && !isActiveTab"
18 : class="workflow-preview-thumbnail relative p-2"
19 : >
20 : <img
21 : :src="thumbnailUrl"
22 : class="block h-50 rounded-lg bg-secondary object-cover p-2 shadow-lg"
23 : :style="{ width: `${POPOVER_WIDTH}px` }"
24 : />
25 : </div>
26 : <div class="px-3 pt-1 pb-2">
27 : <span class="block truncate text-sm font-medium">
28 : {{ workflowFilename }}
29 : </span>
30 : </div>
31 : </div>
32 : </PopoverContent>
33 : </PopoverRoot>
34 : </template>
35 :
36 : <script setup lang="ts">
37 : import { useTimeoutFn } from '@vueuse/core'
38 : import { PopoverAnchor, PopoverRoot } from 'reka-ui'
39 : import type { FocusOutsideEvent, PointerDownOutsideEvent } from 'reka-ui'
40 : import PopoverContent from '@comfyorg/design-system/popover/PopoverContent'
41 : import { ref, watch } from 'vue'
42 :
43 : import { usePopoverViewportDismiss } from '@comfyorg/design-system/lib/popover/usePopoverViewportDismiss'
44 :
45 2355 : const POPOVER_WIDTH = 250
46 :
47 : interface Props {
48 : anchor: HTMLElement | null
49 : hovered: boolean
50 : workflowFilename: string
51 : thumbnailUrl?: string
52 : isActiveTab: boolean
53 : }
54 :
55 3370 : const props = defineProps<Props>()
56 3370 : const open = defineModel<boolean>('open', { default: false })
57 3370 : const clicked = defineModel<boolean>('clicked', { default: false })
58 3370 : const outside = ref(false)
59 3370 : watch(open, (value) => {
60 89 : stopShow()
61 89 : stopHide()
62 89 : if (value) outside.value = false
63 : })
64 3370 : const { start: startShow, stop: stopShow } = useTimeoutFn(
65 : () => {
66 14 : clicked.value = false
67 14 : open.value = true
68 : },
69 : 200,
70 : { immediate: false }
71 : )
72 3370 : const { start: startHide, stop: stopHide } = useTimeoutFn(
73 : () => {
74 72 : open.value = false
75 : },
76 : 100,
77 : { immediate: false }
78 : )
79 156 : function showPopover() {
80 156 : stopHide()
81 156 : startShow()
82 : }
83 109 : function hidePopover() {
84 109 : stopShow()
85 109 : startHide()
86 : }
87 68 : function restoreFocus() {
88 68 : if (clicked.value && !outside.value)
89 22 : props.anchor?.querySelector<HTMLElement>('[role="tab"]')?.focus()
90 : }
91 56 : function onInteractOutside(event: FocusOutsideEvent | PointerDownOutsideEvent) {
92 56 : const target = event.detail.originalEvent.target
93 56 : if (target instanceof Node && props.anchor?.contains(target)) {
94 22 : event.preventDefault()
95 : } else {
96 34 : outside.value = true
97 : }
98 : }
99 3370 : watch(
100 : () => props.hovered,
101 : (hovered) => {
102 263 : if (hovered) showPopover()
103 107 : else hidePopover()
104 : }
105 : )
106 3370 : usePopoverViewportDismiss(open, () => props.anchor)
107 : </script>
|