@bjj/nuxt-layer-shadcn-ui 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,218 @@
1
+ <script setup lang="ts">
2
+ import type { SidebarLayoutMenuItem } from '../SidebarLayout/types'
3
+ import type { SidebarModalPaneSlotProps, SidebarModalProps } from './types'
4
+ import {
5
+ Dialog,
6
+ DialogClose,
7
+ DialogContent,
8
+ DialogDescription,
9
+ DialogTitle,
10
+ DialogTrigger,
11
+ } from '../../shadcn/dialog'
12
+ import { findSidebarMenuItem, firstSidebarMenuItemKey } from '../SidebarLayout/utils'
13
+
14
+ defineOptions({ inheritAttrs: false })
15
+
16
+ const props = withDefaults(defineProps<SidebarModalProps>(), {
17
+ visible: undefined,
18
+ active: undefined,
19
+ searchPlaceholder: undefined,
20
+ title: undefined,
21
+ modal: true,
22
+ showClose: true,
23
+ closeOnClickOutside: false,
24
+ sidebarWidth: undefined,
25
+ contentClass: undefined,
26
+ class: undefined,
27
+ })
28
+
29
+ const emit = defineEmits<{
30
+ 'update:visible': [value: boolean]
31
+ 'update:active': [key: string]
32
+ 'select': [item: SidebarLayoutMenuItem]
33
+ 'open': []
34
+ 'close': []
35
+ 'closed': []
36
+ }>()
37
+
38
+ // Each menu key doubles as a slot name (`#general`); default slot is the fallback.
39
+ defineSlots<{
40
+ default?: (props: SidebarModalPaneSlotProps) => any
41
+ trigger?: () => any
42
+ header?: () => any
43
+ footer?: () => any
44
+ [key: string]: ((props: any) => any) | undefined
45
+ }>()
46
+
47
+ const { t } = useI18n()
48
+ const T = useTranslations('components.ui.SidebarModal')
49
+
50
+ const dialogOpen = ref(props.visible ?? false)
51
+ const activeKey = ref(props.active ?? '')
52
+ const searchQuery = ref<string>()
53
+
54
+ const activeItem = computed(() => findSidebarMenuItem(props.menus, activeKey.value))
55
+
56
+ const paneSlotProps = computed<SidebarModalPaneSlotProps>(() => ({
57
+ active: activeKey.value,
58
+ item: activeItem.value,
59
+ }))
60
+
61
+ const searchKeyword = computed(() => searchQuery.value?.trim().toLowerCase() ?? '')
62
+
63
+ const filteredMenus = computed(() =>
64
+ searchKeyword.value ? filterMenus(props.menus, searchKeyword.value) : props.menus,
65
+ )
66
+
67
+ const dialogClass = computed(() =>
68
+ cn(
69
+ `
70
+ gap-0 bg-popover p-0
71
+ sm:max-w-4xl
72
+ flex h-[min(80vh,42rem)] flex-col overflow-hidden
73
+ `,
74
+ props.class,
75
+ ),
76
+ )
77
+
78
+ const paneClass = computed(() => cn('px-6 py-5', props.contentClass))
79
+
80
+ watch(() => props.visible, value => {
81
+ if (value !== undefined) dialogOpen.value = value
82
+ })
83
+
84
+ watch(dialogOpen, value => {
85
+ emit('update:visible', value)
86
+ if (value) {
87
+ emit('open')
88
+ return
89
+ }
90
+ emit('close')
91
+ // Drop the filter so a stale search does not greet the next open.
92
+ searchQuery.value = undefined
93
+ })
94
+
95
+ watch(() => props.active, key => {
96
+ if (key !== undefined) activeKey.value = key
97
+ })
98
+
99
+ watch(activeKey, key => emit('update:active', key))
100
+
101
+ // Keep a pane selected, including once asynchronously loaded menus arrive.
102
+ watch(() => props.menus, () => {
103
+ if (props.active !== undefined || activeItem.value) return
104
+ activeKey.value = firstSidebarMenuItemKey(props.menus) ?? ''
105
+ }, { immediate: true })
106
+
107
+ function matchesKeyword (item: SidebarLayoutMenuItem, keyword: string): boolean {
108
+ return `${item.label} ${item.group ?? ''}`.toLowerCase().includes(keyword)
109
+ }
110
+
111
+ // Matched children surface as flat entries grouped under their parent's label,
112
+ // so no result stays hidden behind a collapsed parent.
113
+ function filterMenus (menus: SidebarLayoutMenuItem[], keyword: string): SidebarLayoutMenuItem[] {
114
+ const result: SidebarLayoutMenuItem[] = []
115
+
116
+ for (const item of menus) {
117
+ const selfMatch = matchesKeyword(item, keyword)
118
+ if (item.children?.length) {
119
+ const children = selfMatch
120
+ ? item.children
121
+ : item.children.filter(child => matchesKeyword(child, keyword))
122
+ result.push(...children.map(child => ({ ...child, group: item.label })))
123
+ } else if (selfMatch) {
124
+ result.push(item)
125
+ }
126
+ }
127
+
128
+ return result
129
+ }
130
+
131
+ function onPointerDownOutside (event: Event) {
132
+ if (!props.closeOnClickOutside) event.preventDefault()
133
+ }
134
+ </script>
135
+
136
+ <template>
137
+ <Dialog
138
+ v-model:open="dialogOpen"
139
+ :modal="modal"
140
+ >
141
+ <DialogTrigger
142
+ v-if="$slots.trigger"
143
+ asChild
144
+ >
145
+ <slot name="trigger" />
146
+ </DialogTrigger>
147
+
148
+ <DialogContent
149
+ v-bind="$attrs"
150
+ :class="dialogClass"
151
+ :showCloseButton="false"
152
+ @pointerDownOutside="onPointerDownOutside"
153
+ @closeAutoFocus="emit('closed')"
154
+ >
155
+ <!-- A11y: reka-ui requires a title and a description inside the dialog. -->
156
+ <DialogTitle class="sr-only">
157
+ {{ title }}
158
+ </DialogTitle>
159
+ <DialogDescription class="sr-only" />
160
+
161
+ <SidebarLayout
162
+ v-model:active="activeKey"
163
+ embedded
164
+ :menus="filteredMenus"
165
+ :emptyText="searchKeyword ? T('noResults') : undefined"
166
+ :sidebarWidth="sidebarWidth"
167
+ :contentClass="paneClass"
168
+ @select="emit('select', $event)"
169
+ >
170
+ <template
171
+ v-if="searchable || $slots.header"
172
+ #header
173
+ >
174
+ <slot name="header">
175
+ <Input
176
+ v-model="searchQuery"
177
+ :placeholder="searchPlaceholder || T('searchPlaceholder')"
178
+ >
179
+ <template #prefix>
180
+ <Icon name="search" />
181
+ </template>
182
+ </Input>
183
+ </slot>
184
+ </template>
185
+
186
+ <template
187
+ v-if="$slots.footer"
188
+ #footer
189
+ >
190
+ <slot name="footer" />
191
+ </template>
192
+
193
+ <slot
194
+ :name="activeKey || 'default'"
195
+ v-bind="paneSlotProps"
196
+ >
197
+ <slot v-bind="paneSlotProps" />
198
+ </slot>
199
+ </SidebarLayout>
200
+
201
+ <DialogClose
202
+ v-if="showClose"
203
+ class="
204
+ top-3 right-3 size-8 text-muted-foreground ring-offset-background
205
+ hover:bg-accent/50 hover:text-foreground
206
+ focus:ring-ring
207
+ absolute flex items-center justify-center rounded-full transition
208
+ focus:ring-2 focus:ring-offset-2 focus:outline-hidden
209
+ "
210
+ >
211
+ <Icon name="x" />
212
+ <span class="sr-only">
213
+ {{ t('common.actions.close') }}
214
+ </span>
215
+ </DialogClose>
216
+ </DialogContent>
217
+ </Dialog>
218
+ </template>
@@ -0,0 +1,26 @@
1
+ import type { SidebarLayoutMenuItem } from '../SidebarLayout/types'
2
+
3
+ export interface SidebarModalPaneSlotProps {
4
+ active: string
5
+ /** The selected menu item, when `active` still points at one. */
6
+ item?: SidebarLayoutMenuItem
7
+ }
8
+
9
+ export interface SidebarModalProps {
10
+ menus: SidebarLayoutMenuItem[]
11
+ visible?: boolean
12
+ /** Key of the selected menu item. Omitted → the first selectable item. */
13
+ active?: string
14
+ /** Render a search field above the menu, filtering items by label and group. */
15
+ searchable?: boolean
16
+ searchPlaceholder?: string
17
+ /** Accessible name of the dialog, rendered for screen readers only. */
18
+ title?: string
19
+ modal?: boolean
20
+ showClose?: boolean
21
+ closeOnClickOutside?: boolean
22
+ /** Width of the menu column, as a CSS length. */
23
+ sidebarWidth?: string
24
+ contentClass?: ClassValue
25
+ class?: ClassValue
26
+ }
@@ -82,6 +82,10 @@
82
82
  "placeholder": "يرجى اختيار",
83
83
  "searchPlaceholder": "البحث..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "لا توجد نتائج",
87
+ "searchPlaceholder": "البحث"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "الإجراءات"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Bitte wählen",
83
83
  "searchPlaceholder": "Suchen..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Keine Ergebnisse",
87
+ "searchPlaceholder": "Suchen"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Aktionen"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Please select",
83
83
  "searchPlaceholder": "Search..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "No results",
87
+ "searchPlaceholder": "Search"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Actions"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Por favor selecciona",
83
83
  "searchPlaceholder": "Buscar..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Sin resultados",
87
+ "searchPlaceholder": "Buscar"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Acciones"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Veuillez sélectionner",
83
83
  "searchPlaceholder": "Rechercher..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Aucun résultat",
87
+ "searchPlaceholder": "Rechercher"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Actions"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "कृपया चुनें",
83
83
  "searchPlaceholder": "खोजें..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "कोई परिणाम नहीं",
87
+ "searchPlaceholder": "खोजें"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "क्रियाएं"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Silakan pilih",
83
83
  "searchPlaceholder": "Cari..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Tidak ada hasil",
87
+ "searchPlaceholder": "Cari"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Tindakan"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Seleziona",
83
83
  "searchPlaceholder": "Cerca..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Nessun risultato",
87
+ "searchPlaceholder": "Cerca"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Azioni"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "選択してください",
83
83
  "searchPlaceholder": "検索..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "結果がありません",
87
+ "searchPlaceholder": "検索"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "アクション"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "선택하세요",
83
83
  "searchPlaceholder": "검색..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "결과 없음",
87
+ "searchPlaceholder": "검색"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "작업"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Selecteer alstublieft",
83
83
  "searchPlaceholder": "Zoeken..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Geen resultaten",
87
+ "searchPlaceholder": "Zoeken"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Acties"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Proszę wybrać",
83
83
  "searchPlaceholder": "Wyszukaj..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Brak wyników",
87
+ "searchPlaceholder": "Wyszukaj"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Akcje"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Por favor, selecione",
83
83
  "searchPlaceholder": "Pesquisar..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Nenhum resultado",
87
+ "searchPlaceholder": "Pesquisar"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Ações"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Пожалуйста, выберите",
83
83
  "searchPlaceholder": "Поиск..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Нет результатов",
87
+ "searchPlaceholder": "Поиск"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Действия"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "กรุณาเลือก",
83
83
  "searchPlaceholder": "ค้นหา..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "ไม่มีผลลัพธ์",
87
+ "searchPlaceholder": "ค้นหา"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "การกระทำ"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Lütfen seçin",
83
83
  "searchPlaceholder": "Ara..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Sonuç bulunamadı",
87
+ "searchPlaceholder": "Ara"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "İşlemler"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "Vui lòng chọn",
83
83
  "searchPlaceholder": "Tìm kiếm..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "Không có kết quả",
87
+ "searchPlaceholder": "Tìm kiếm"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "Hành động"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "请选择",
83
83
  "searchPlaceholder": "搜索..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "暂无结果",
87
+ "searchPlaceholder": "搜索"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "操作"
87
91
  },
@@ -82,6 +82,10 @@
82
82
  "placeholder": "請選擇",
83
83
  "searchPlaceholder": "搜尋..."
84
84
  },
85
+ "SidebarModal": {
86
+ "noResults": "暫無結果",
87
+ "searchPlaceholder": "搜尋"
88
+ },
85
89
  "StaticDataTable": {
86
90
  "actions": "操作"
87
91
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bjj/nuxt-layer-shadcn-ui",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Nuxt layer providing shadcn-vue based UI components",
5
5
  "type": "module",
6
6
  "main": "./nuxt.config.ts",
@@ -42,5 +42,5 @@
42
42
  "vue-i18n": "^11",
43
43
  "vue-router": "^4 || ^5"
44
44
  },
45
- "gitHead": "78110189a45b96010d17a058c174867e6feb4c42"
45
+ "gitHead": "8b94a7bdf44027021baccd353801079740f84b3e"
46
46
  }