@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.
- package/app/components/ui/AdminLayout/index.vue +29 -70
- package/app/components/ui/AdminLayout/types.ts +2 -10
- package/app/components/ui/{AdminLayout → SidebarLayout}/SidebarMenus.vue +46 -56
- package/app/components/ui/SidebarLayout/index.stories.ts +274 -0
- package/app/components/ui/SidebarLayout/index.vue +141 -0
- package/app/components/ui/SidebarLayout/types.ts +31 -0
- package/app/components/ui/SidebarLayout/utils.ts +29 -0
- package/app/components/ui/SidebarModal/en.json +4 -0
- package/app/components/ui/SidebarModal/index.stories.ts +479 -0
- package/app/components/ui/SidebarModal/index.vue +233 -0
- package/app/components/ui/SidebarModal/types.ts +41 -0
- package/i18n/messages/ar.json +4 -0
- package/i18n/messages/de.json +4 -0
- package/i18n/messages/en.json +4 -0
- package/i18n/messages/es.json +4 -0
- package/i18n/messages/fr.json +4 -0
- package/i18n/messages/hi.json +4 -0
- package/i18n/messages/id.json +4 -0
- package/i18n/messages/it.json +4 -0
- package/i18n/messages/ja.json +4 -0
- package/i18n/messages/ko.json +4 -0
- package/i18n/messages/nl.json +4 -0
- package/i18n/messages/pl.json +4 -0
- package/i18n/messages/pt.json +4 -0
- package/i18n/messages/ru.json +4 -0
- package/i18n/messages/th.json +4 -0
- package/i18n/messages/tr.json +4 -0
- package/i18n/messages/vi.json +4 -0
- package/i18n/messages/zh-CN.json +4 -0
- package/i18n/messages/zh-TW.json +4 -0
- package/package.json +2 -2
|
@@ -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
|
+
}
|
package/i18n/messages/ar.json
CHANGED
package/i18n/messages/de.json
CHANGED
package/i18n/messages/en.json
CHANGED
package/i18n/messages/es.json
CHANGED
package/i18n/messages/fr.json
CHANGED
package/i18n/messages/hi.json
CHANGED
package/i18n/messages/id.json
CHANGED
package/i18n/messages/it.json
CHANGED
package/i18n/messages/ja.json
CHANGED
package/i18n/messages/ko.json
CHANGED
package/i18n/messages/nl.json
CHANGED
package/i18n/messages/pl.json
CHANGED
package/i18n/messages/pt.json
CHANGED
package/i18n/messages/ru.json
CHANGED
package/i18n/messages/th.json
CHANGED
package/i18n/messages/tr.json
CHANGED
package/i18n/messages/vi.json
CHANGED
package/i18n/messages/zh-CN.json
CHANGED
package/i18n/messages/zh-TW.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "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": "
|
|
45
|
+
"gitHead": "fcb519f4b49b1057560758810895da335df8366c"
|
|
46
46
|
}
|