Line data Source code
1 : <template>
2 89 : <div
3 : class="flex min-h-0 scrollbar-hide w-full flex-auto flex-col gap-1 overflow-y-auto bg-card px-3"
4 : >
5 : <template
6 : v-for="item in navItems"
7 370 : :key="'title' in item ? item.title : item.id"
8 : >
9 : <div v-if="'items' in item" class="flex flex-col gap-2">
10 : <NavTitle
11 : v-model="collapsedGroups[item.title]"
12 : :title="item.title"
13 : :collapsible="item.collapsible"
14 : />
15 : <template v-if="!item.collapsible || !collapsedGroups[item.title]">
16 368 : <NavItem
17 : v-for="subItem in item.items"
18 : :key="subItem.id"
19 : :icon="subItem.icon"
20 : :badge="subItem.badge"
21 : :active="activeItem === subItem.id"
22 : @click="activeItem = subItem.id"
23 : >
24 : {{ subItem.label }}
25 : </NavItem>
26 : </template>
27 : </div>
28 : <div v-else class="flex flex-col gap-2">
29 : <NavItem
30 : :icon="item.icon"
31 : :badge="item.badge"
32 : :active="activeItem === item.id"
33 : @click="activeItem = item.id"
34 : >
35 : {{ item.label }}
36 : </NavItem>
37 : </div>
38 : </template>
39 : </div>
40 : </template>
41 :
42 : <script setup lang="ts">
43 : import { computed, ref } from 'vue'
44 :
45 : import NavItem from '@comfyorg/design-system/navigation/NavItem'
46 : import NavTitle from '@comfyorg/design-system/navigation/NavTitle'
47 : import type {
48 : NavGroupData,
49 : NavItemData
50 : } from '@comfyorg/design-system/lib/navigation/types'
51 :
52 : const { navItems = [], modelValue } = defineProps<{
53 : navItems?: (NavItemData | NavGroupData)[]
54 : modelValue?: string | null
55 : }>()
56 :
57 42 : const emit = defineEmits<{
58 : 'update:modelValue': [value: string | null]
59 : }>()
60 :
61 : // Track collapsed state for each group
62 42 : const collapsedGroups = ref<Record<string, boolean>>({})
63 :
64 42 : const getFirstItemId = () => {
65 0 : if (!navItems || navItems.length === 0) {
66 0 : return null
67 : }
68 :
69 0 : const firstEntry = navItems[0]
70 :
71 0 : if ('items' in firstEntry && firstEntry.items.length > 0) {
72 0 : return firstEntry.items[0].id
73 : }
74 0 : if ('id' in firstEntry) {
75 0 : return firstEntry.id
76 : }
77 :
78 0 : return null
79 : }
80 :
81 42 : const activeItem = computed({
82 : get: () => modelValue ?? getFirstItemId(),
83 : set: (value: string | null) => emit('update:modelValue', value)
84 : })
85 : </script>
|