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

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,233 @@
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
+ search: undefined,
20
+ searchPlaceholder: undefined,
21
+ title: undefined,
22
+ modal: true,
23
+ showClose: true,
24
+ closeOnClickOutside: false,
25
+ sidebarWidth: undefined,
26
+ contentClass: undefined,
27
+ class: undefined,
28
+ })
29
+
30
+ const emit = defineEmits<{
31
+ 'update:visible': [value: boolean]
32
+ 'update:active': [key: string]
33
+ 'update:search': [keyword: string]
34
+ 'select': [item: SidebarLayoutMenuItem]
35
+ 'open': []
36
+ 'close': []
37
+ 'closed': []
38
+ }>()
39
+
40
+ // Each menu key doubles as a slot name (`#general`); default slot is the fallback.
41
+ defineSlots<{
42
+ default?: (props: SidebarModalPaneSlotProps) => any
43
+ trigger?: () => any
44
+ header?: () => any
45
+ footer?: () => any
46
+ [key: string]: ((props: any) => any) | undefined
47
+ }>()
48
+
49
+ const { t } = useI18n()
50
+ const T = useTranslations('components.ui.SidebarModal')
51
+
52
+ const dialogOpen = ref(props.visible ?? false)
53
+ const activeKey = ref(props.active ?? '')
54
+ const searchQuery = ref(props.search)
55
+
56
+ const activeItem = computed(() => findSidebarMenuItem(props.menus, activeKey.value))
57
+
58
+ const paneSlotProps = computed<SidebarModalPaneSlotProps>(() => ({
59
+ active: activeKey.value,
60
+ item: activeItem.value,
61
+ }))
62
+
63
+ const searchKeyword = computed(() => searchQuery.value?.trim() ?? '')
64
+
65
+ const filteredMenus = computed(() => {
66
+ // A custom filter runs for every keyword, empty included, so it fully owns the
67
+ // listing; reading its own reactive state in there also covers async results.
68
+ if (typeof props.searchable === 'function') {
69
+ return props.searchable(props.menus, searchKeyword.value)
70
+ }
71
+ if (!searchKeyword.value) return props.menus
72
+ return filterMenus(props.menus, searchKeyword.value.toLowerCase())
73
+ })
74
+
75
+ const dialogClass = computed(() =>
76
+ cn(
77
+ `
78
+ gap-0 bg-popover p-0
79
+ sm:max-w-4xl
80
+ flex h-[min(80vh,42rem)] flex-col overflow-hidden
81
+ `,
82
+ props.class,
83
+ ),
84
+ )
85
+
86
+ const paneClass = computed(() => cn('px-6 py-5', props.contentClass))
87
+
88
+ watch(() => props.visible, value => {
89
+ if (value !== undefined) dialogOpen.value = value
90
+ })
91
+
92
+ watch(dialogOpen, value => {
93
+ emit('update:visible', value)
94
+ if (value) {
95
+ emit('open')
96
+ return
97
+ }
98
+ emit('close')
99
+ // Drop the filter so a stale search does not greet the next open.
100
+ searchQuery.value = undefined
101
+ })
102
+
103
+ watch(() => props.search, keyword => {
104
+ if (keyword !== undefined) searchQuery.value = keyword
105
+ })
106
+
107
+ watch(searchQuery, keyword => emit('update:search', keyword ?? ''))
108
+
109
+ watch(() => props.active, key => {
110
+ if (key !== undefined) activeKey.value = key
111
+ })
112
+
113
+ watch(activeKey, key => emit('update:active', key))
114
+
115
+ // Keep a pane selected, including once asynchronously loaded menus arrive.
116
+ watch(() => props.menus, () => {
117
+ if (props.active !== undefined || activeItem.value) return
118
+ activeKey.value = firstSidebarMenuItemKey(props.menus) ?? ''
119
+ }, { immediate: true })
120
+
121
+ function matchesKeyword (item: SidebarLayoutMenuItem, keyword: string): boolean {
122
+ return `${item.label} ${item.group ?? ''}`.toLowerCase().includes(keyword)
123
+ }
124
+
125
+ // Matched children surface as flat entries grouped under their parent's label,
126
+ // so no result stays hidden behind a collapsed parent.
127
+ function filterMenus (menus: SidebarLayoutMenuItem[], keyword: string): SidebarLayoutMenuItem[] {
128
+ const result: SidebarLayoutMenuItem[] = []
129
+
130
+ for (const item of menus) {
131
+ const selfMatch = matchesKeyword(item, keyword)
132
+ if (item.children?.length) {
133
+ const children = selfMatch
134
+ ? item.children
135
+ : item.children.filter(child => matchesKeyword(child, keyword))
136
+ result.push(...children.map(child => ({ ...child, group: item.label })))
137
+ } else if (selfMatch) {
138
+ result.push(item)
139
+ }
140
+ }
141
+
142
+ return result
143
+ }
144
+
145
+ function onPointerDownOutside (event: Event) {
146
+ if (!props.closeOnClickOutside) event.preventDefault()
147
+ }
148
+ </script>
149
+
150
+ <template>
151
+ <Dialog
152
+ v-model:open="dialogOpen"
153
+ :modal="modal"
154
+ >
155
+ <DialogTrigger
156
+ v-if="$slots.trigger"
157
+ asChild
158
+ >
159
+ <slot name="trigger" />
160
+ </DialogTrigger>
161
+
162
+ <DialogContent
163
+ v-bind="$attrs"
164
+ :class="dialogClass"
165
+ :showCloseButton="false"
166
+ @pointerDownOutside="onPointerDownOutside"
167
+ @closeAutoFocus="emit('closed')"
168
+ >
169
+ <!-- A11y: reka-ui requires a title and a description inside the dialog. -->
170
+ <DialogTitle class="sr-only">
171
+ {{ title }}
172
+ </DialogTitle>
173
+ <DialogDescription class="sr-only" />
174
+
175
+ <SidebarLayout
176
+ v-model:active="activeKey"
177
+ embedded
178
+ :menus="filteredMenus"
179
+ :emptyText="searchKeyword ? T('noResults') : undefined"
180
+ :sidebarWidth="sidebarWidth"
181
+ :contentClass="paneClass"
182
+ @select="emit('select', $event)"
183
+ >
184
+ <template
185
+ v-if="searchable || $slots.header"
186
+ #header
187
+ >
188
+ <slot name="header" />
189
+
190
+ <Input
191
+ v-if="searchable"
192
+ v-model="searchQuery"
193
+ :placeholder="searchPlaceholder || T('searchPlaceholder')"
194
+ >
195
+ <template #prefix>
196
+ <Icon name="search" />
197
+ </template>
198
+ </Input>
199
+ </template>
200
+
201
+ <template
202
+ v-if="$slots.footer"
203
+ #footer
204
+ >
205
+ <slot name="footer" />
206
+ </template>
207
+
208
+ <slot
209
+ :name="activeKey || 'default'"
210
+ v-bind="paneSlotProps"
211
+ >
212
+ <slot v-bind="paneSlotProps" />
213
+ </slot>
214
+ </SidebarLayout>
215
+
216
+ <DialogClose
217
+ v-if="showClose"
218
+ class="
219
+ top-3 right-3 size-8 text-muted-foreground ring-offset-background
220
+ hover:bg-accent/50 hover:text-foreground
221
+ focus:ring-ring
222
+ absolute flex items-center justify-center rounded-full transition
223
+ focus:ring-2 focus:ring-offset-2 focus:outline-hidden
224
+ "
225
+ >
226
+ <Icon name="x" />
227
+ <span class="sr-only">
228
+ {{ t('common.actions.close') }}
229
+ </span>
230
+ </DialogClose>
231
+ </DialogContent>
232
+ </Dialog>
233
+ </template>
@@ -0,0 +1,41 @@
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
+ /**
10
+ * Menus to list for the current keyword. Receives the keyword as typed (trimmed),
11
+ * so a business search can look beyond labels — pane content, a remote index —
12
+ * and return whatever entries should show.
13
+ */
14
+ export type SidebarModalFilter = (
15
+ menus: SidebarLayoutMenuItem[],
16
+ keyword: string,
17
+ ) => SidebarLayoutMenuItem[]
18
+
19
+ export interface SidebarModalProps {
20
+ menus: SidebarLayoutMenuItem[]
21
+ visible?: boolean
22
+ /** Key of the selected menu item. Omitted → the first selectable item. */
23
+ active?: string
24
+ /**
25
+ * Render a search field between `#header` and the menu. `true`: filter menus by
26
+ * label and group; function: custom filter (replaces the built-in one).
27
+ */
28
+ searchable?: boolean | SidebarModalFilter
29
+ /** Search keyword. Use `v-model:search` to read or drive it from the outside. */
30
+ search?: string
31
+ searchPlaceholder?: string
32
+ /** Accessible name of the dialog, rendered for screen readers only. */
33
+ title?: string
34
+ modal?: boolean
35
+ showClose?: boolean
36
+ closeOnClickOutside?: boolean
37
+ /** Width of the menu column, as a CSS length. */
38
+ sidebarWidth?: string
39
+ contentClass?: ClassValue
40
+ class?: ClassValue
41
+ }
@@ -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.1",
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": "fcb519f4b49b1057560758810895da335df8366c"
46
46
  }