@bjj/nuxt-layer-shadcn-ui 0.13.7 → 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/assets/styles/tailwind-colors.css +25 -15
- package/app/components/ui/AdminLayout/index.vue +29 -70
- package/app/components/ui/AdminLayout/types.ts +2 -10
- package/app/components/ui/DataTable/index.vue +21 -6
- 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/app/components/ui/Upload/index.vue +0 -3
- 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,368 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/vue3'
|
|
2
|
+
import type { SidebarLayoutMenuItem } from '../SidebarLayout/types'
|
|
3
|
+
import EventLog from '#storybook/EventLog.vue'
|
|
4
|
+
import { useArgsModel } from '#storybook/argsModel'
|
|
5
|
+
import Button from '../Button/index.vue'
|
|
6
|
+
import Icon from '../Icon/index.vue'
|
|
7
|
+
import Input from '../Input/index.vue'
|
|
8
|
+
import Switch from '../Switch/index.vue'
|
|
9
|
+
import SidebarModal from './index.vue'
|
|
10
|
+
|
|
11
|
+
const menus: SidebarLayoutMenuItem[] = [
|
|
12
|
+
{ key: 'general', label: 'General', icon: 'settings', group: 'Settings' },
|
|
13
|
+
{ key: 'account', label: 'Account', icon: 'circle-user', group: 'Settings' },
|
|
14
|
+
{ key: 'usage', label: 'Usage', icon: 'chart-column', group: 'Settings' },
|
|
15
|
+
{ key: 'capabilities', label: 'Capabilities', icon: 'briefcase-business', group: 'Settings' },
|
|
16
|
+
{ key: 'appearance', label: 'Appearance', icon: 'monitor', group: 'Desktop app' },
|
|
17
|
+
{ key: 'extensions', label: 'Extensions', icon: 'blocks', group: 'Desktop app' },
|
|
18
|
+
{ key: 'developer', label: 'Developer', icon: 'wrench', group: 'Desktop app' },
|
|
19
|
+
{ key: 'skills', label: 'Skills', icon: 'scroll-text', group: 'Customize' },
|
|
20
|
+
{ key: 'connectors', label: 'Connectors', icon: 'plug', group: 'Customize' },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
const nestedMenus: SidebarLayoutMenuItem[] = [
|
|
24
|
+
{ key: 'general', label: 'General', icon: 'settings' },
|
|
25
|
+
{
|
|
26
|
+
label: 'Workspace',
|
|
27
|
+
icon: 'building-2',
|
|
28
|
+
expanded: true,
|
|
29
|
+
children: [
|
|
30
|
+
{ key: 'members', label: 'Members' },
|
|
31
|
+
{ key: 'billing', label: 'Billing' },
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
const scrollingMenus: SidebarLayoutMenuItem[] = [
|
|
37
|
+
...menus,
|
|
38
|
+
...Array.from({ length: 12 }, (_, index) => ({
|
|
39
|
+
key: `plugin-${index + 1}`,
|
|
40
|
+
label: `Plugin ${index + 1}`,
|
|
41
|
+
icon: 'puzzle',
|
|
42
|
+
group: 'Plugins',
|
|
43
|
+
})),
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
const generalPane = `
|
|
47
|
+
<template #general>
|
|
48
|
+
<div class="space-y-4">
|
|
49
|
+
<h2 class="text-lg font-semibold">Profile</h2>
|
|
50
|
+
<div class="divide-y divide-border">
|
|
51
|
+
<div class="flex items-center justify-between gap-4 py-4">
|
|
52
|
+
<span class="text-sm">Full name</span>
|
|
53
|
+
<Input class="max-w-64" modelValue="b.jj" />
|
|
54
|
+
</div>
|
|
55
|
+
<div class="flex items-center justify-between gap-4 py-4">
|
|
56
|
+
<span class="text-sm">Email</span>
|
|
57
|
+
<Input class="max-w-64" modelValue="b.jj@example.com" />
|
|
58
|
+
</div>
|
|
59
|
+
<div class="flex items-center justify-between gap-4 py-4">
|
|
60
|
+
<span class="text-sm">Email notifications</span>
|
|
61
|
+
<Switch :modelValue="true" />
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
</template>
|
|
66
|
+
`
|
|
67
|
+
|
|
68
|
+
const accountPane = `
|
|
69
|
+
<template #account>
|
|
70
|
+
<div class="space-y-4">
|
|
71
|
+
<h2 class="text-lg font-semibold">Account</h2>
|
|
72
|
+
<p class="text-sm text-muted-foreground">Manage the credentials used to sign in.</p>
|
|
73
|
+
<Button variant="outline" icon="lock-keyhole">Change password</Button>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
76
|
+
`
|
|
77
|
+
|
|
78
|
+
const fallbackPane = `
|
|
79
|
+
<template #default="{ active, item }">
|
|
80
|
+
<div class="space-y-2">
|
|
81
|
+
<h2 class="text-lg font-semibold">{{ item?.label }}</h2>
|
|
82
|
+
<p class="text-sm text-muted-foreground">No pane is declared for "{{ active }}" yet.</p>
|
|
83
|
+
</div>
|
|
84
|
+
</template>
|
|
85
|
+
`
|
|
86
|
+
|
|
87
|
+
const scrollingPane = `
|
|
88
|
+
<template #general>
|
|
89
|
+
<div class="space-y-4">
|
|
90
|
+
<h2 class="text-lg font-semibold">Preferences</h2>
|
|
91
|
+
<div class="divide-y divide-border">
|
|
92
|
+
<div
|
|
93
|
+
v-for="i in 20"
|
|
94
|
+
:key="i"
|
|
95
|
+
class="flex items-center justify-between gap-4 py-4"
|
|
96
|
+
>
|
|
97
|
+
<span class="text-sm">Preference {{ i }}</span>
|
|
98
|
+
<Switch :modelValue="i % 2 === 0" />
|
|
99
|
+
</div>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
</template>
|
|
103
|
+
`
|
|
104
|
+
|
|
105
|
+
const meta = {
|
|
106
|
+
title: 'UI/SidebarModal',
|
|
107
|
+
component: SidebarModal,
|
|
108
|
+
argTypes: {
|
|
109
|
+
menus: { control: 'object' },
|
|
110
|
+
visible: { control: 'boolean' },
|
|
111
|
+
active: { control: 'text' },
|
|
112
|
+
searchable: { control: 'boolean' },
|
|
113
|
+
searchPlaceholder: { control: 'text' },
|
|
114
|
+
title: { control: 'text' },
|
|
115
|
+
modal: { control: 'boolean' },
|
|
116
|
+
showClose: { control: 'boolean' },
|
|
117
|
+
closeOnClickOutside: { control: 'boolean' },
|
|
118
|
+
sidebarWidth: { control: 'text' },
|
|
119
|
+
contentClass: { control: 'text' },
|
|
120
|
+
},
|
|
121
|
+
args: {
|
|
122
|
+
menus,
|
|
123
|
+
visible: false,
|
|
124
|
+
active: 'general',
|
|
125
|
+
searchable: true,
|
|
126
|
+
searchPlaceholder: '',
|
|
127
|
+
title: 'Settings',
|
|
128
|
+
modal: true,
|
|
129
|
+
showClose: true,
|
|
130
|
+
closeOnClickOutside: false,
|
|
131
|
+
sidebarWidth: '',
|
|
132
|
+
contentClass: '',
|
|
133
|
+
},
|
|
134
|
+
render: args => {
|
|
135
|
+
const onUpdateVisible = useArgsModel('visible')
|
|
136
|
+
const onUpdateActive = useArgsModel('active')
|
|
137
|
+
return {
|
|
138
|
+
components: { SidebarModal, Button, Input, Switch },
|
|
139
|
+
setup: () => ({ args, onUpdateVisible, onUpdateActive }),
|
|
140
|
+
// Opening through `#trigger` keeps the demo alive on the Docs page, where
|
|
141
|
+
// only the primary story's args round-trip; the emits still sync Controls.
|
|
142
|
+
template: `
|
|
143
|
+
<SidebarModal
|
|
144
|
+
v-bind="args"
|
|
145
|
+
@update:visible="onUpdateVisible"
|
|
146
|
+
@update:active="onUpdateActive"
|
|
147
|
+
>
|
|
148
|
+
<template #trigger>
|
|
149
|
+
<Button>Open Settings</Button>
|
|
150
|
+
</template>
|
|
151
|
+
|
|
152
|
+
${generalPane}
|
|
153
|
+
${accountPane}
|
|
154
|
+
${fallbackPane}
|
|
155
|
+
</SidebarModal>
|
|
156
|
+
`,
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
} satisfies Meta<typeof SidebarModal>
|
|
160
|
+
|
|
161
|
+
export default meta
|
|
162
|
+
type Story = StoryObj<typeof meta>
|
|
163
|
+
|
|
164
|
+
const noControls = { controls: { disable: true }} satisfies Story['parameters']
|
|
165
|
+
|
|
166
|
+
export const Default: Story = {}
|
|
167
|
+
|
|
168
|
+
export const WithoutSearch: Story = {
|
|
169
|
+
parameters: noControls,
|
|
170
|
+
args: {
|
|
171
|
+
searchable: false,
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export const SearchPlaceholder: Story = {
|
|
176
|
+
parameters: noControls,
|
|
177
|
+
args: {
|
|
178
|
+
searchPlaceholder: 'Find a setting',
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// A search flattens matched children so none stays hidden behind a closed parent.
|
|
183
|
+
export const NestedMenus: Story = {
|
|
184
|
+
parameters: noControls,
|
|
185
|
+
args: {
|
|
186
|
+
menus: nestedMenus,
|
|
187
|
+
active: 'members',
|
|
188
|
+
},
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export const Sizing: Story = {
|
|
192
|
+
parameters: noControls,
|
|
193
|
+
args: {
|
|
194
|
+
sidebarWidth: '12rem',
|
|
195
|
+
contentClass: 'px-8 py-6',
|
|
196
|
+
class: 'sm:max-w-2xl h-[560px]',
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Both columns outgrow the dialog: the height stays capped and each side
|
|
201
|
+
// scrolls on its own, with the search field and the pane header staying put.
|
|
202
|
+
export const Scrolling: Story = {
|
|
203
|
+
parameters: {
|
|
204
|
+
...noControls,
|
|
205
|
+
docs: {
|
|
206
|
+
source: {
|
|
207
|
+
code: `
|
|
208
|
+
<template>
|
|
209
|
+
<SidebarModal
|
|
210
|
+
:menus="menus"
|
|
211
|
+
title="Settings"
|
|
212
|
+
searchable
|
|
213
|
+
>
|
|
214
|
+
<template #trigger>
|
|
215
|
+
<Button>Open Settings</Button>
|
|
216
|
+
</template>
|
|
217
|
+
|
|
218
|
+
<template #general>
|
|
219
|
+
<div class="divide-y divide-border">
|
|
220
|
+
<div
|
|
221
|
+
v-for="i in 20"
|
|
222
|
+
:key="i"
|
|
223
|
+
class="flex items-center justify-between gap-4 py-4"
|
|
224
|
+
>
|
|
225
|
+
<span class="text-sm">Preference {{ i }}</span>
|
|
226
|
+
<Switch :modelValue="i % 2 === 0" />
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
</template>
|
|
230
|
+
</SidebarModal>
|
|
231
|
+
</template>
|
|
232
|
+
`.trim(),
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
render: () => ({
|
|
237
|
+
components: { SidebarModal, Button, Switch },
|
|
238
|
+
setup: () => ({ menus: scrollingMenus }),
|
|
239
|
+
template: `
|
|
240
|
+
<SidebarModal :menus="menus" title="Settings" searchable>
|
|
241
|
+
<template #trigger>
|
|
242
|
+
<Button>Open Settings</Button>
|
|
243
|
+
</template>
|
|
244
|
+
|
|
245
|
+
${scrollingPane}
|
|
246
|
+
|
|
247
|
+
<template #default="{ item }">
|
|
248
|
+
<h2 class="text-lg font-semibold">{{ item?.label }}</h2>
|
|
249
|
+
</template>
|
|
250
|
+
</SidebarModal>
|
|
251
|
+
`,
|
|
252
|
+
}),
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export const ClickOutsideToClose: Story = {
|
|
256
|
+
parameters: noControls,
|
|
257
|
+
args: {
|
|
258
|
+
showClose: false,
|
|
259
|
+
closeOnClickOutside: true,
|
|
260
|
+
},
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export const NonModal: Story = {
|
|
264
|
+
parameters: noControls,
|
|
265
|
+
args: {
|
|
266
|
+
modal: false,
|
|
267
|
+
},
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
export const CustomHeader: Story = {
|
|
271
|
+
parameters: {
|
|
272
|
+
...noControls,
|
|
273
|
+
docs: {
|
|
274
|
+
source: {
|
|
275
|
+
code: `
|
|
276
|
+
<template>
|
|
277
|
+
<SidebarModal
|
|
278
|
+
v-model:visible="visible"
|
|
279
|
+
:menus="menus"
|
|
280
|
+
title="Settings"
|
|
281
|
+
>
|
|
282
|
+
<template #header>
|
|
283
|
+
<div class="flex items-center gap-2 px-2 py-1">
|
|
284
|
+
<Icon name="building-2" />
|
|
285
|
+
<span class="text-base font-semibold">Acme Inc.</span>
|
|
286
|
+
</div>
|
|
287
|
+
</template>
|
|
288
|
+
|
|
289
|
+
<template #footer>
|
|
290
|
+
<Button
|
|
291
|
+
variant="ghost"
|
|
292
|
+
icon="log-out"
|
|
293
|
+
class="justify-start"
|
|
294
|
+
>
|
|
295
|
+
Sign out
|
|
296
|
+
</Button>
|
|
297
|
+
</template>
|
|
298
|
+
|
|
299
|
+
<template #default="{ item }">
|
|
300
|
+
<h2 class="text-lg font-semibold">{{ item?.label }}</h2>
|
|
301
|
+
</template>
|
|
302
|
+
</SidebarModal>
|
|
303
|
+
</template>
|
|
304
|
+
`.trim(),
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
},
|
|
308
|
+
render: () => ({
|
|
309
|
+
components: { SidebarModal, Button, Icon },
|
|
310
|
+
setup () {
|
|
311
|
+
const visible = ref(false)
|
|
312
|
+
return { visible, menus }
|
|
313
|
+
},
|
|
314
|
+
template: `
|
|
315
|
+
<div>
|
|
316
|
+
<Button @click="visible = true">Open Settings</Button>
|
|
317
|
+
<SidebarModal v-model:visible="visible" :menus="menus" title="Settings">
|
|
318
|
+
<template #header>
|
|
319
|
+
<div class="flex items-center gap-2 px-2 py-1">
|
|
320
|
+
<Icon name="building-2" />
|
|
321
|
+
<span class="text-base font-semibold">Acme Inc.</span>
|
|
322
|
+
</div>
|
|
323
|
+
</template>
|
|
324
|
+
|
|
325
|
+
<template #footer>
|
|
326
|
+
<Button variant="ghost" icon="log-out" class="justify-start">Sign out</Button>
|
|
327
|
+
</template>
|
|
328
|
+
|
|
329
|
+
<template #default="{ item }">
|
|
330
|
+
<h2 class="text-lg font-semibold">{{ item?.label }}</h2>
|
|
331
|
+
</template>
|
|
332
|
+
</SidebarModal>
|
|
333
|
+
</div>
|
|
334
|
+
`,
|
|
335
|
+
}),
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export const EventHandling: Story = {
|
|
339
|
+
parameters: noControls,
|
|
340
|
+
render: () => ({
|
|
341
|
+
components: { SidebarModal, Button, EventLog },
|
|
342
|
+
setup () {
|
|
343
|
+
const visible = ref(false)
|
|
344
|
+
return { visible, menus }
|
|
345
|
+
},
|
|
346
|
+
template: `
|
|
347
|
+
<EventLog v-slot="{ record }">
|
|
348
|
+
<Button @click="visible = true">Open Settings</Button>
|
|
349
|
+
<SidebarModal
|
|
350
|
+
v-model:visible="visible"
|
|
351
|
+
:menus="menus"
|
|
352
|
+
title="Settings"
|
|
353
|
+
searchable
|
|
354
|
+
@open="record('open')"
|
|
355
|
+
@close="record('close')"
|
|
356
|
+
@closed="record('closed')"
|
|
357
|
+
@select="(item) => record('select', item.label)"
|
|
358
|
+
@update:active="(key) => record('update:active', key)"
|
|
359
|
+
@update:visible="(value) => record('update:visible', value)"
|
|
360
|
+
>
|
|
361
|
+
<template #default="{ item }">
|
|
362
|
+
<h2 class="text-lg font-semibold">{{ item?.label }}</h2>
|
|
363
|
+
</template>
|
|
364
|
+
</SidebarModal>
|
|
365
|
+
</EventLog>
|
|
366
|
+
`,
|
|
367
|
+
}),
|
|
368
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -175,14 +175,12 @@ const dragAreaBase = `
|
|
|
175
175
|
flex cursor-pointer flex-col items-center justify-center gap-2
|
|
176
176
|
rounded-md border border-dashed bg-muted/40 px-6 py-10
|
|
177
177
|
text-center transition-colors
|
|
178
|
-
dark:bg-muted/20
|
|
179
178
|
`
|
|
180
179
|
|
|
181
180
|
const boxTriggerBase = `
|
|
182
181
|
flex size-24 shrink-0 cursor-pointer flex-col items-center justify-center
|
|
183
182
|
gap-1 rounded-md border border-dashed bg-muted/40 text-xs
|
|
184
183
|
text-muted-foreground transition-colors
|
|
185
|
-
dark:bg-muted/20
|
|
186
184
|
`
|
|
187
185
|
|
|
188
186
|
const disabledClass = 'pointer-events-none cursor-not-allowed opacity-60'
|
|
@@ -215,7 +213,6 @@ const boxTriggerClass = computed(() => makeTriggerClass(
|
|
|
215
213
|
const thumbBase = `
|
|
216
214
|
group/thumb
|
|
217
215
|
relative size-24 shrink-0 overflow-hidden rounded-md border bg-muted/40
|
|
218
|
-
dark:bg-muted/20
|
|
219
216
|
`
|
|
220
217
|
|
|
221
218
|
const rowItemBase = `
|
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