@bjj/nuxt-layer-shadcn-ui 0.15.1 → 0.15.3
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/SidebarLayout/SidebarMenus.vue +0 -2
- package/app/components/ui/SidebarLayout/index.stories.ts +22 -0
- package/app/components/ui/SidebarLayout/index.vue +66 -3
- package/app/components/ui/SidebarLayout/types.ts +6 -1
- package/app/components/ui/SidebarLayout/utils.ts +11 -6
- package/app/components/ui/SidebarModal/index.stories.ts +19 -0
- package/app/components/ui/SidebarModal/index.vue +24 -7
- package/app/components/ui/SidebarModal/types.ts +4 -1
- package/package.json +2 -2
|
@@ -71,10 +71,8 @@ function hasActiveChild (item: SidebarLayoutMenuItem): boolean {
|
|
|
71
71
|
return item.children?.some(isActive) ?? false
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// A linked item navigates through its `WebLink`, so `command` is for the rest.
|
|
75
74
|
function handleSelect (item: SidebarLayoutMenuItem) {
|
|
76
75
|
emit('select', item)
|
|
77
|
-
if (!isLink(item)) item.command?.()
|
|
78
76
|
}
|
|
79
77
|
</script>
|
|
80
78
|
|
|
@@ -160,6 +160,28 @@ export const Embedded: Story = {
|
|
|
160
160
|
},
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
+
// Embedded on a phone viewport: the nav stacks above the content as a strip.
|
|
164
|
+
export const Stacked: Story = {
|
|
165
|
+
parameters: {
|
|
166
|
+
...noControls,
|
|
167
|
+
viewport: {
|
|
168
|
+
options: {
|
|
169
|
+
mobile: {
|
|
170
|
+
name: 'Mobile',
|
|
171
|
+
styles: { width: '390px', height: '844px' },
|
|
172
|
+
type: 'mobile',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
globals: {
|
|
178
|
+
viewport: { value: 'mobile', isRotated: false },
|
|
179
|
+
},
|
|
180
|
+
args: {
|
|
181
|
+
embedded: true,
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
|
|
163
185
|
export const SidebarWidth: Story = {
|
|
164
186
|
parameters: noControls,
|
|
165
187
|
args: {
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import type { TabsItem } from '../Tabs/types'
|
|
2
3
|
import type { SidebarLayoutMenuItem, SidebarLayoutProps } from './types'
|
|
3
4
|
import SidebarMenus from './SidebarMenus.vue'
|
|
4
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
findSidebarMenuItem,
|
|
7
|
+
flattenSidebarMenuItems,
|
|
8
|
+
sidebarMenuItemKey,
|
|
9
|
+
} from './utils'
|
|
5
10
|
import {
|
|
6
11
|
Sidebar,
|
|
7
12
|
SidebarContent,
|
|
@@ -50,17 +55,42 @@ provideSidebarContext({
|
|
|
50
55
|
toggleSidebar: noop,
|
|
51
56
|
})
|
|
52
57
|
|
|
58
|
+
const { isMobile } = useDevice()
|
|
59
|
+
|
|
60
|
+
// A 16rem column would eat a phone's width, so an embedded layout stacks its nav
|
|
61
|
+
// above the content there. Page mode keeps the vendored drawer instead.
|
|
62
|
+
const stacked = computed(() => props.embedded && isMobile.value)
|
|
63
|
+
|
|
64
|
+
const tabItems = computed<TabsItem[]>(() =>
|
|
65
|
+
flattenSidebarMenuItems(props.menus).map(item => ({
|
|
66
|
+
value: sidebarMenuItemKey(item),
|
|
67
|
+
title: item.label,
|
|
68
|
+
icon: item.icon,
|
|
69
|
+
})),
|
|
70
|
+
)
|
|
71
|
+
|
|
53
72
|
const rootComponent = computed(() => props.embedded ? 'div' : SidebarProvider)
|
|
54
73
|
|
|
55
74
|
const rootStyle = computed(() => ({ '--sidebar-width': props.sidebarWidth }))
|
|
56
75
|
|
|
57
76
|
const rootClass = computed(() =>
|
|
58
|
-
cn(
|
|
77
|
+
cn(
|
|
78
|
+
props.embedded && 'min-h-0 flex size-full overflow-hidden',
|
|
79
|
+
stacked.value && 'flex-col',
|
|
80
|
+
props.class,
|
|
81
|
+
),
|
|
59
82
|
)
|
|
60
83
|
|
|
84
|
+
// A linked item navigates through its `WebLink`, so `command` is for the rest.
|
|
61
85
|
function onSelect (item: SidebarLayoutMenuItem) {
|
|
62
86
|
emit('select', item)
|
|
63
87
|
emit('update:active', sidebarMenuItemKey(item))
|
|
88
|
+
if (!item.href) item.command?.()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function onTabSelect (key: string) {
|
|
92
|
+
const item = findSidebarMenuItem(props.menus, key)
|
|
93
|
+
if (item) onSelect(item)
|
|
64
94
|
}
|
|
65
95
|
</script>
|
|
66
96
|
|
|
@@ -72,8 +102,41 @@ function onSelect (item: SidebarLayoutMenuItem) {
|
|
|
72
102
|
>
|
|
73
103
|
<!-- Menu-button tooltips need a provider, which embedded mode has none of. -->
|
|
74
104
|
<TooltipProvider>
|
|
105
|
+
<!-- Stacked: the menu becomes a scrollable strip, groups flattened away. -->
|
|
106
|
+
<template v-if="stacked">
|
|
107
|
+
<div
|
|
108
|
+
v-if="$slots.header"
|
|
109
|
+
class="gap-2 p-2 flex flex-col"
|
|
110
|
+
>
|
|
111
|
+
<slot name="header" />
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div
|
|
115
|
+
v-if="emptyText && !menus.length"
|
|
116
|
+
class="px-4 py-3 text-sm text-muted-foreground border-b text-center"
|
|
117
|
+
>
|
|
118
|
+
{{ emptyText }}
|
|
119
|
+
</div>
|
|
120
|
+
<Tabs
|
|
121
|
+
v-else
|
|
122
|
+
:items="tabItems"
|
|
123
|
+
:modelValue="active"
|
|
124
|
+
listClass="
|
|
125
|
+
h-auto w-full gap-1 rounded-none border-b bg-transparent p-2
|
|
126
|
+
justify-start overflow-x-auto
|
|
127
|
+
"
|
|
128
|
+
triggerClass="
|
|
129
|
+
data-[state=active]:bg-accent
|
|
130
|
+
data-[state=active]:shadow-none
|
|
131
|
+
flex-none
|
|
132
|
+
"
|
|
133
|
+
@update:modelValue="onTabSelect"
|
|
134
|
+
/>
|
|
135
|
+
</template>
|
|
136
|
+
|
|
75
137
|
<!-- `shrink-0`: wide pane content scrolls instead of squeezing the menu. -->
|
|
76
138
|
<Sidebar
|
|
139
|
+
v-else
|
|
77
140
|
:variant="variant"
|
|
78
141
|
:collapsible="embedded ? 'none' : collapsible"
|
|
79
142
|
:class="embedded ? 'shrink-0 border-r' : undefined"
|
|
@@ -108,7 +171,7 @@ function onSelect (item: SidebarLayoutMenuItem) {
|
|
|
108
171
|
Top padding on mobile reserves a safe area for the floating trigger. -->
|
|
109
172
|
<SidebarInset
|
|
110
173
|
:class="[
|
|
111
|
-
'min-w-0',
|
|
174
|
+
'min-w-0 min-h-0',
|
|
112
175
|
embedded ? 'bg-transparent' : 'bg-card',
|
|
113
176
|
!embedded && `
|
|
114
177
|
pt-14
|
|
@@ -19,8 +19,13 @@ export interface SidebarLayoutProps {
|
|
|
19
19
|
active?: string
|
|
20
20
|
/** Placeholder shown when `menus` is empty. */
|
|
21
21
|
emptyText?: string
|
|
22
|
-
/** Fill the parent instead of the viewport: never collapses, no rail
|
|
22
|
+
/** Fill the parent instead of the viewport: never collapses, no rail. */
|
|
23
23
|
embedded?: boolean
|
|
24
|
+
/**
|
|
25
|
+
* Stack the nav above the content as a scrollable strip instead of placing it
|
|
26
|
+
* in a column. The caller decides when — the layout holds no breakpoint.
|
|
27
|
+
*/
|
|
28
|
+
stacked?: boolean
|
|
24
29
|
variant?: 'sidebar' | 'floating' | 'inset'
|
|
25
30
|
/** Collapse behaviour of the sidebar. Ignored while `embedded`. */
|
|
26
31
|
collapsible?: 'offcanvas' | 'icon' | 'none'
|
|
@@ -17,13 +17,18 @@ export function findSidebarMenuItem (
|
|
|
17
17
|
return undefined
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/** Selectable (childless) items in listing order, with grouping flattened away. */
|
|
21
|
+
export function flattenSidebarMenuItems (
|
|
22
|
+
menus: SidebarLayoutMenuItem[],
|
|
23
|
+
): SidebarLayoutMenuItem[] {
|
|
24
|
+
return menus.flatMap(item =>
|
|
25
|
+
item.children?.length ? flattenSidebarMenuItems(item.children) : [ item ],
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
export function firstSidebarMenuItemKey (
|
|
21
30
|
menus: SidebarLayoutMenuItem[],
|
|
22
31
|
): string | undefined {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const key = firstSidebarMenuItemKey(item.children)
|
|
26
|
-
if (key) return key
|
|
27
|
-
}
|
|
28
|
-
return undefined
|
|
32
|
+
const [ first ] = flattenSidebarMenuItems(menus)
|
|
33
|
+
return first && sidebarMenuItemKey(first)
|
|
29
34
|
}
|
|
@@ -361,6 +361,25 @@ export const Scrolling: Story = {
|
|
|
361
361
|
}),
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
// Phone viewport: the menu becomes a scrollable strip under a visible title row.
|
|
365
|
+
export const Mobile: Story = {
|
|
366
|
+
parameters: {
|
|
367
|
+
...noControls,
|
|
368
|
+
viewport: {
|
|
369
|
+
options: {
|
|
370
|
+
mobile: {
|
|
371
|
+
name: 'Mobile',
|
|
372
|
+
styles: { width: '390px', height: '844px' },
|
|
373
|
+
type: 'mobile',
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
globals: {
|
|
379
|
+
viewport: { value: 'mobile', isRotated: false },
|
|
380
|
+
},
|
|
381
|
+
}
|
|
382
|
+
|
|
364
383
|
export const ClickOutsideToClose: Story = {
|
|
365
384
|
parameters: noControls,
|
|
366
385
|
args: {
|
|
@@ -76,14 +76,19 @@ const dialogClass = computed(() =>
|
|
|
76
76
|
cn(
|
|
77
77
|
`
|
|
78
78
|
gap-0 bg-popover p-0
|
|
79
|
-
|
|
80
|
-
flex h-[
|
|
79
|
+
md:max-w-4xl md:h-[min(80vh,42rem)]
|
|
80
|
+
flex h-[85vh] flex-col overflow-hidden
|
|
81
81
|
`,
|
|
82
82
|
props.class,
|
|
83
83
|
),
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
-
const paneClass = computed(() =>
|
|
86
|
+
const paneClass = computed(() =>
|
|
87
|
+
cn(`
|
|
88
|
+
px-4 py-4
|
|
89
|
+
md:px-6 md:py-5
|
|
90
|
+
`, props.contentClass),
|
|
91
|
+
)
|
|
87
92
|
|
|
88
93
|
watch(() => props.visible, value => {
|
|
89
94
|
if (value !== undefined) dialogOpen.value = value
|
|
@@ -166,8 +171,13 @@ function onPointerDownOutside (event: Event) {
|
|
|
166
171
|
@pointerDownOutside="onPointerDownOutside"
|
|
167
172
|
@closeAutoFocus="emit('closed')"
|
|
168
173
|
>
|
|
169
|
-
<!-- A11y: reka-ui requires a title and a description inside the dialog.
|
|
170
|
-
|
|
174
|
+
<!-- A11y: reka-ui requires a title and a description inside the dialog. The
|
|
175
|
+
visible title doubles as the accessible name, so this one steps in
|
|
176
|
+
whenever that one is not rendered. -->
|
|
177
|
+
<DialogTitle
|
|
178
|
+
v-if="$slots.header || !title"
|
|
179
|
+
class="sr-only"
|
|
180
|
+
>
|
|
171
181
|
{{ title }}
|
|
172
182
|
</DialogTitle>
|
|
173
183
|
<DialogDescription class="sr-only" />
|
|
@@ -182,10 +192,17 @@ function onPointerDownOutside (event: Event) {
|
|
|
182
192
|
@select="emit('select', $event)"
|
|
183
193
|
>
|
|
184
194
|
<template
|
|
185
|
-
v-if="searchable || $slots.header"
|
|
195
|
+
v-if="title || searchable || $slots.header"
|
|
186
196
|
#header
|
|
187
197
|
>
|
|
188
|
-
<slot name="header"
|
|
198
|
+
<slot name="header">
|
|
199
|
+
<DialogTitle
|
|
200
|
+
v-if="title"
|
|
201
|
+
class="px-2 py-1 text-base font-semibold"
|
|
202
|
+
>
|
|
203
|
+
{{ title }}
|
|
204
|
+
</DialogTitle>
|
|
205
|
+
</slot>
|
|
189
206
|
|
|
190
207
|
<Input
|
|
191
208
|
v-if="searchable"
|
|
@@ -29,7 +29,10 @@ export interface SidebarModalProps {
|
|
|
29
29
|
/** Search keyword. Use `v-model:search` to read or drive it from the outside. */
|
|
30
30
|
search?: string
|
|
31
31
|
searchPlaceholder?: string
|
|
32
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* Accessible name of the dialog, and the default content of `#header`. A
|
|
34
|
+
* `#header` slot replaces it there and leaves it to screen readers.
|
|
35
|
+
*/
|
|
33
36
|
title?: string
|
|
34
37
|
modal?: boolean
|
|
35
38
|
showClose?: boolean
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.3",
|
|
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": "7bc35e8ae2098667e03bc0e30343815cfb1a69bb"
|
|
46
46
|
}
|