@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.
- 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 +368 -0
- package/app/components/ui/SidebarModal/index.vue +218 -0
- package/app/components/ui/SidebarModal/types.ts +26 -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,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
|
+
}
|
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.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": "
|
|
45
|
+
"gitHead": "8b94a7bdf44027021baccd353801079740f84b3e"
|
|
46
46
|
}
|