LCOV - code coverage report
Current view: top level - packages/design-system/src/components/layout - BaseModalLayout.vue Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 81.1 % 37 30
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1           16 : <template>
       2          514 :   <div
       3              :     :class="
       4              :       cn(
       5              :         'relative overflow-hidden rounded-2xl border bg-background shadow-lg',
       6              :         sizeClasses
       7              :       )
       8              :     "
       9              :     @keydown.esc.capture="handleEscape"
      10              :   >
      11              :     <div
      12              :       class="grid size-full transition-[grid-template-columns] duration-300 ease-out"
      13              :       :style="gridStyle"
      14              :     >
      15              :       <nav
      16              :         class="flex h-full flex-col overflow-hidden bg-card"
      17              :         :inert="!showLeftPanel"
      18              :         :aria-hidden="!showLeftPanel"
      19              :       >
      20              :         <header
      21              :           data-component-id="LeftPanelHeader"
      22              :           class="flex h-18 w-full shrink-0 items-center-safe gap-2 pr-3 pl-6"
      23              :         >
      24              :           <slot name="leftPanelHeaderTitle" />
      25              :           <Button
      26              :             v-if="!notMobile && showLeftPanel"
      27              :             size="lg"
      28              :             class="ml-auto w-10 p-0"
      29              :             :aria-label="labels.hideLeftPanel"
      30              :             @click="toggleLeftPanel"
      31              :           >
      32              :             <i class="icon-[lucide--panel-left-close]" />
      33              :           </Button>
      34              :         </header>
      35              :         <slot name="leftPanel" />
      36              :       </nav>
      37              : 
      38              :       <div class="flex flex-col overflow-hidden bg-background">
      39              :         <header v-if="$slots.header" :class="headerClass">
      40              :           <div :class="headerContentClass">
      41              :             <Button
      42              :               v-if="!notMobile && !showLeftPanel"
      43              :               size="lg"
      44              :               class="w-10 p-0"
      45              :               :aria-label="labels.showLeftPanel"
      46              :               @click="toggleLeftPanel"
      47              :             >
      48              :               <i class="icon-[lucide--panel-left]" />
      49              :             </Button>
      50              :             <slot name="header" />
      51              :           </div>
      52              :           <slot name="header-right-area" />
      53              :           <template v-if="!isRightPanelOpen">
      54              :             <Button
      55              :               v-if="hasRightPanel"
      56              :               size="lg"
      57              :               class="w-10 p-0"
      58              :               :aria-label="labels.showRightPanel"
      59              :               @click="toggleRightPanel"
      60              :             >
      61              :               <i class="icon-[lucide--panel-right]" />
      62              :             </Button>
      63              :             <Button
      64              :               size="lg"
      65              :               class="w-10"
      66              :               :variant="closeButtonVariant"
      67              :               :aria-label="labels.close"
      68              :               @click="emit('close')"
      69              :             >
      70              :               <i :class="closeIcon" />
      71              :             </Button>
      72              :           </template>
      73              :         </header>
      74              : 
      75              :         <main class="flex min-h-0 flex-1 flex-col">
      76              :           <slot name="contentFilter" />
      77              :           <DialogTitle
      78              :             :class="
      79              :               cn(
      80              :                 'px-6 pt-2 pb-6 text-2xl font-normal capitalize select-none',
      81              :                 hasLeftPanel && 'sr-only'
      82              :               )
      83              :             "
      84              :           >
      85              :             {{ contentTitle }}
      86              :           </DialogTitle>
      87              :           <div
      88              :             ref="contentContainer"
      89              :             data-testid="base-modal-content"
      90              :             :class="contentContainerClass"
      91              :           >
      92              :             <slot name="content" />
      93              :           </div>
      94              :         </main>
      95              :       </div>
      96              : 
      97              :       <aside
      98              :         v-if="hasRightPanel"
      99              :         class="overflow-hidden"
     100              :         :inert="!isRightPanelOpen"
     101              :         :aria-hidden="!isRightPanelOpen"
     102              :       >
     103              :         <div class="flex h-full w-72 min-w-72 flex-col bg-card">
     104              :           <header
     105              :             data-component-id="RightPanelHeader"
     106              :             class="flex h-18 shrink-0 items-center gap-2 px-6"
     107              :           >
     108              :             <h2
     109              :               v-if="rightPanelTitle"
     110              :               class="flex-1 text-base font-semibold select-none"
     111              :             >
     112              :               {{ rightPanelTitle }}
     113              :             </h2>
     114              :             <div v-else class="flex-1">
     115              :               <slot name="rightPanelHeaderTitle" />
     116              :             </div>
     117              :             <slot name="rightPanelHeaderActions" />
     118              :             <Button
     119              :               size="lg"
     120              :               class="w-10 p-0"
     121              :               :aria-label="labels.hideRightPanel"
     122              :               @click="toggleRightPanel"
     123              :             >
     124              :               <i class="icon-[lucide--panel-right-close]" />
     125              :             </Button>
     126              :             <Button
     127              :               size="lg"
     128              :               class="w-10 p-0"
     129              :               :variant="closeButtonVariant"
     130              :               :aria-label="labels.close"
     131              :               @click="emit('close')"
     132              :             >
     133              :               <i :class="closeIcon" />
     134              :             </Button>
     135              :           </header>
     136              :           <div class="min-h-0 flex-1 overflow-y-auto">
     137              :             <slot name="rightPanel" />
     138              :           </div>
     139              :         </div>
     140              :       </aside>
     141              :     </div>
     142              :   </div>
     143              : </template>
     144              : 
     145              : <script setup lang="ts">
     146              : import { useBreakpoints } from '@vueuse/core'
     147              : import { computed, ref, useSlots, watch } from 'vue'
     148              : 
     149              : import Button from '@comfyorg/design-system/button/Button'
     150              : import DialogTitle from '@comfyorg/design-system/dialog/DialogTitle'
     151              : import type { ButtonVariants } from '@comfyorg/design-system/button.variants'
     152              : import { cn } from '@comfyorg/tailwind-utils'
     153              : 
     154          179 : const SIZE_CLASSES = {
     155              :   md: 'h-[80vh] w-[90vw] max-w-[1400px]',
     156              :   lg: 'h-[80vh] max-h-[1026px] w-[90vw] max-w-[1280px] min-[1450px]:max-w-[1724px] min-[3000px]:max-h-[1320px] min-[3000px]:max-w-[2200px]'
     157              : } as const
     158              : 
     159              : type ModalSize = keyof typeof SIZE_CLASSES
     160              : type ContentPadding = 'default' | 'compact' | 'none'
     161              : type HeaderPadding = 'default' | 'symmetric'
     162              : 
     163              : const {
     164              :   contentTitle,
     165              :   labels,
     166              :   rightPanelTitle,
     167              :   size = 'lg',
     168              :   leftPanelWidth = '14rem',
     169              :   contentPadding = 'default',
     170              :   headerPadding = 'default',
     171              :   closeButtonVariant,
     172              :   closeIcon = 'icon-[lucide--x]'
     173              : } = defineProps<{
     174              :   contentTitle: string
     175              :   labels: {
     176              :     showLeftPanel: string
     177              :     hideLeftPanel: string
     178              :     showRightPanel: string
     179              :     hideRightPanel: string
     180              :     close: string
     181              :   }
     182              :   rightPanelTitle?: string
     183              :   size?: ModalSize
     184              :   leftPanelWidth?: string
     185              :   contentPadding?: ContentPadding
     186              :   headerPadding?: HeaderPadding
     187              :   closeButtonVariant?: ButtonVariants['variant']
     188              :   closeIcon?: string
     189              : }>()
     190              : 
     191          179 : const emit = defineEmits<{
     192              :   close: []
     193              : }>()
     194              : 
     195          179 : const sizeClasses = computed(() => SIZE_CLASSES[size])
     196              : 
     197          179 : const isRightPanelOpen = defineModel<boolean>('rightPanelOpen', {
     198              :   default: false
     199              : })
     200              : 
     201          179 : const slots = useSlots()
     202          179 : const hasLeftPanel = computed(() => !!slots.leftPanel)
     203          179 : const hasRightPanel = computed(() => !!slots.rightPanel)
     204              : 
     205              : const BREAKPOINTS = { md: 880 }
     206              : 
     207              : const breakpoints = useBreakpoints(BREAKPOINTS)
     208          179 : const notMobile = breakpoints.greater('md')
     209              : 
     210          179 : const isLeftPanelOpen = ref<boolean>(true)
     211          179 : const mobileMenuOpen = ref<boolean>(false)
     212          179 : const contentContainer = ref<HTMLElement | null>(null)
     213              : 
     214          179 : watch(notMobile, (isDesktop) => {
     215            9 :   if (!isDesktop) {
     216            7 :     mobileMenuOpen.value = false
     217              :   }
     218              : })
     219              : 
     220          179 : const showLeftPanel = computed(() => {
     221              :   const shouldShow = notMobile.value
     222              :     ? isLeftPanelOpen.value
     223              :     : mobileMenuOpen.value
     224              :   return shouldShow
     225              : })
     226              : 
     227          179 : const headerClass = computed(() =>
     228              :   cn(
     229              :     'flex w-full items-center justify-between gap-2',
     230              :     headerPadding === 'symmetric' ? 'px-6 py-5' : 'h-18 px-6'
     231              :   )
     232              : )
     233              : 
     234          179 : const headerContentClass = computed(() =>
     235              :   cn(
     236              :     'flex min-w-0 flex-1 gap-2',
     237              :     headerPadding === 'symmetric' && 'min-h-10 items-center'
     238              :   )
     239              : )
     240              : 
     241          179 : const contentContainerClass = computed(() =>
     242              :   cn(
     243              :     'flex scrollbar-custom min-h-0 flex-1 flex-col overflow-y-auto',
     244              :     contentPadding === 'default' && 'px-6 pt-0 pb-10',
     245              :     contentPadding === 'compact' && 'px-6 pt-0 pb-2'
     246              :   )
     247              : )
     248              : 
     249          179 : const gridStyle = computed(() => ({
     250              :   gridTemplateColumns: hasRightPanel.value
     251              :     ? `${hasLeftPanel.value && showLeftPanel.value ? leftPanelWidth : '0rem'} 1fr ${isRightPanelOpen.value ? '18rem' : '0rem'}`
     252              :     : `${hasLeftPanel.value && showLeftPanel.value ? leftPanelWidth : '0rem'} 1fr`
     253              : }))
     254              : 
     255          179 : const toggleLeftPanel = () => {
     256            0 :   if (notMobile.value) {
     257            0 :     isLeftPanelOpen.value = !isLeftPanelOpen.value
     258              :   } else {
     259            0 :     mobileMenuOpen.value = !mobileMenuOpen.value
     260              :   }
     261              : }
     262              : 
     263          179 : const toggleRightPanel = () => {
     264            0 :   isRightPanelOpen.value = !isRightPanelOpen.value
     265              : }
     266              : 
     267            7 : function handleEscape(event: KeyboardEvent) {
     268            7 :   const target = event.target
     269            7 :   if (!(target instanceof HTMLElement)) return
     270            7 :   if (
     271              :     target instanceof HTMLInputElement ||
     272              :     target instanceof HTMLTextAreaElement ||
     273              :     target instanceof HTMLSelectElement ||
     274              :     target.isContentEditable
     275              :   ) {
     276            6 :     return
     277              :   }
     278            1 :   if (isRightPanelOpen.value) {
     279            0 :     event.stopPropagation()
     280            0 :     isRightPanelOpen.value = false
     281              :   }
     282              : }
     283              : 
     284          179 : defineExpose({
     285              :   getContentScrollTop: () => contentContainer.value?.scrollTop ?? 0,
     286              :   setContentScrollTop: (scrollTop: number) => {
     287            0 :     if (contentContainer.value) contentContainer.value.scrollTop = scrollTop
     288              :   }
     289              : })
     290              : </script>
        

Generated by: LCOV version 2.0-1