@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.
Files changed (34) hide show
  1. package/app/assets/styles/tailwind-colors.css +25 -15
  2. package/app/components/ui/AdminLayout/index.vue +29 -70
  3. package/app/components/ui/AdminLayout/types.ts +2 -10
  4. package/app/components/ui/DataTable/index.vue +21 -6
  5. package/app/components/ui/{AdminLayout → SidebarLayout}/SidebarMenus.vue +46 -56
  6. package/app/components/ui/SidebarLayout/index.stories.ts +274 -0
  7. package/app/components/ui/SidebarLayout/index.vue +141 -0
  8. package/app/components/ui/SidebarLayout/types.ts +31 -0
  9. package/app/components/ui/SidebarLayout/utils.ts +29 -0
  10. package/app/components/ui/SidebarModal/en.json +4 -0
  11. package/app/components/ui/SidebarModal/index.stories.ts +368 -0
  12. package/app/components/ui/SidebarModal/index.vue +218 -0
  13. package/app/components/ui/SidebarModal/types.ts +26 -0
  14. package/app/components/ui/Upload/index.vue +0 -3
  15. package/i18n/messages/ar.json +4 -0
  16. package/i18n/messages/de.json +4 -0
  17. package/i18n/messages/en.json +4 -0
  18. package/i18n/messages/es.json +4 -0
  19. package/i18n/messages/fr.json +4 -0
  20. package/i18n/messages/hi.json +4 -0
  21. package/i18n/messages/id.json +4 -0
  22. package/i18n/messages/it.json +4 -0
  23. package/i18n/messages/ja.json +4 -0
  24. package/i18n/messages/ko.json +4 -0
  25. package/i18n/messages/nl.json +4 -0
  26. package/i18n/messages/pl.json +4 -0
  27. package/i18n/messages/pt.json +4 -0
  28. package/i18n/messages/ru.json +4 -0
  29. package/i18n/messages/th.json +4 -0
  30. package/i18n/messages/tr.json +4 -0
  31. package/i18n/messages/vi.json +4 -0
  32. package/i18n/messages/zh-CN.json +4 -0
  33. package/i18n/messages/zh-TW.json +4 -0
  34. package/package.json +2 -2
@@ -0,0 +1,274 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3'
2
+ import type { SidebarLayoutMenuItem } from './types'
3
+ import EventLog from '#storybook/EventLog.vue'
4
+ import { useArgsModel } from '#storybook/argsModel'
5
+ import Button from '../Button/index.vue'
6
+ import SidebarLayout from './index.vue'
7
+
8
+ const variants = [ 'sidebar', 'floating', 'inset' ] as const
9
+ const collapsibles = [ 'icon', 'offcanvas', 'none' ] as const
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: 'appearance', label: 'Appearance', icon: 'monitor', group: 'Customize' },
16
+ { key: 'connectors', label: 'Connectors', icon: 'plug', group: 'Customize' },
17
+ ]
18
+
19
+ const nestedMenus: SidebarLayoutMenuItem[] = [
20
+ { key: 'overview', label: 'Overview', icon: 'layout-dashboard' },
21
+ {
22
+ label: 'Documentation',
23
+ icon: 'book-open',
24
+ group: 'Platform',
25
+ expanded: true,
26
+ children: [
27
+ { key: 'intro', label: 'Introduction' },
28
+ { key: 'tutorials', label: 'Tutorials' },
29
+ ],
30
+ },
31
+ {
32
+ key: 'design',
33
+ label: 'Design Engineering',
34
+ icon: 'frame',
35
+ group: 'Projects',
36
+ actions: [
37
+ { label: 'Share Project', icon: 'forward', command: () => {} },
38
+ { label: 'Delete Project', icon: 'trash-2', command: () => {} },
39
+ ],
40
+ },
41
+ ]
42
+
43
+ const paneTemplate = `
44
+ <div class="space-y-3">
45
+ <h2 class="text-lg font-semibold">{{ active || 'No selection' }}</h2>
46
+ <p class="text-sm text-muted-foreground">
47
+ The layout owns the menu and its active state; this pane comes from the default slot.
48
+ </p>
49
+ </div>
50
+ `
51
+
52
+ const brandTemplate = `
53
+ <template #header>
54
+ <div class="truncate px-2 py-1 text-base font-semibold group-data-[collapsible=icon]:hidden">Acme Inc.</div>
55
+ </template>
56
+ `
57
+
58
+ const meta = {
59
+ title: 'UI/SidebarLayout',
60
+ component: SidebarLayout,
61
+ argTypes: {
62
+ menus: { control: 'object' },
63
+ active: { control: 'text' },
64
+ emptyText: { control: 'text' },
65
+ embedded: { control: 'boolean' },
66
+ variant: { control: 'select', options: variants },
67
+ collapsible: { control: 'select', options: collapsibles },
68
+ sidebarWidth: { control: 'text' },
69
+ contentClass: { control: 'text' },
70
+ },
71
+ args: {
72
+ menus,
73
+ active: 'general',
74
+ emptyText: '',
75
+ embedded: false,
76
+ variant: 'sidebar',
77
+ collapsible: 'icon',
78
+ sidebarWidth: '16rem',
79
+ contentClass: 'p-6',
80
+ },
81
+ render: args => {
82
+ const onUpdateActive = useArgsModel('active')
83
+ return {
84
+ components: { SidebarLayout },
85
+ // The Docs page only round-trips the primary story's args, so selection is
86
+ // mirrored locally to stay clickable there, and pushed back to Controls.
87
+ setup () {
88
+ const active = ref(args.active)
89
+ watch(() => args.active, key => {
90
+ active.value = key
91
+ })
92
+ function onSelect (key: string) {
93
+ active.value = key
94
+ onUpdateActive(key)
95
+ }
96
+ return { args, active, onSelect }
97
+ },
98
+ template: `
99
+ <SidebarLayout
100
+ v-bind="args"
101
+ :active="active"
102
+ @update:active="onSelect"
103
+ >
104
+ ${brandTemplate}
105
+ ${paneTemplate}
106
+ </SidebarLayout>
107
+ `,
108
+ }
109
+ },
110
+ // The page-mode sidebar is `position: fixed`; pin it to the preview frame so it
111
+ // does not stretch across the whole Storybook viewport. `[data-state]` keeps the
112
+ // selector off an embedded sidebar, whose last child is its own footer.
113
+ decorators: [
114
+ () => ({
115
+ template: `
116
+ <div
117
+ class="relative h-[600px] overflow-hidden rounded-lg border border-border
118
+ [&_[data-slot=sidebar][data-state]>div:last-child]:absolute!
119
+ [&_[data-slot=sidebar][data-state]>div:last-child]:h-full!"
120
+ >
121
+ <story />
122
+ </div>
123
+ `,
124
+ }),
125
+ ],
126
+ } satisfies Meta<typeof SidebarLayout>
127
+
128
+ export default meta
129
+ type Story = StoryObj<typeof meta>
130
+
131
+ const noControls = { controls: { disable: true }} satisfies Story['parameters']
132
+
133
+ export const Default: Story = {}
134
+
135
+ export const Floating: Story = {
136
+ parameters: noControls,
137
+ args: {
138
+ variant: 'floating',
139
+ },
140
+ }
141
+
142
+ export const Inset: Story = {
143
+ parameters: noControls,
144
+ args: {
145
+ variant: 'inset',
146
+ },
147
+ }
148
+
149
+ export const Offcanvas: Story = {
150
+ parameters: noControls,
151
+ args: {
152
+ collapsible: 'offcanvas',
153
+ },
154
+ }
155
+
156
+ export const Embedded: Story = {
157
+ parameters: noControls,
158
+ args: {
159
+ embedded: true,
160
+ },
161
+ }
162
+
163
+ export const SidebarWidth: Story = {
164
+ parameters: noControls,
165
+ args: {
166
+ embedded: true,
167
+ sidebarWidth: '11rem',
168
+ },
169
+ }
170
+
171
+ export const NestedMenus: Story = {
172
+ parameters: noControls,
173
+ args: {
174
+ embedded: true,
175
+ menus: nestedMenus,
176
+ active: 'intro',
177
+ },
178
+ }
179
+
180
+ export const EmptyText: Story = {
181
+ parameters: noControls,
182
+ args: {
183
+ embedded: true,
184
+ menus: [],
185
+ emptyText: 'No results',
186
+ },
187
+ }
188
+
189
+ export const SidebarFooter: Story = {
190
+ parameters: {
191
+ ...noControls,
192
+ docs: {
193
+ source: {
194
+ code: `
195
+ <template>
196
+ <SidebarLayout
197
+ v-model:active="active"
198
+ embedded
199
+ :menus="menus"
200
+ contentClass="p-6"
201
+ >
202
+ <template #header>
203
+ <div class="px-2 py-1 text-base font-semibold">Acme Inc.</div>
204
+ </template>
205
+
206
+ <template #footer>
207
+ <Button
208
+ variant="ghost"
209
+ icon="log-out"
210
+ class="justify-start"
211
+ >
212
+ Sign out
213
+ </Button>
214
+ </template>
215
+
216
+ <div class="text-sm text-muted-foreground">Pane for {{ active }}</div>
217
+ </SidebarLayout>
218
+ </template>
219
+ `.trim(),
220
+ },
221
+ },
222
+ },
223
+ render: () => ({
224
+ components: { SidebarLayout, Button },
225
+ setup () {
226
+ const active = ref('general')
227
+ return { active, menus }
228
+ },
229
+ template: `
230
+ <SidebarLayout
231
+ v-model:active="active"
232
+ embedded
233
+ :menus="menus"
234
+ contentClass="p-6"
235
+ >
236
+ <template #header>
237
+ <div class="px-2 py-1 text-base font-semibold">Acme Inc.</div>
238
+ </template>
239
+
240
+ <template #footer>
241
+ <Button variant="ghost" icon="log-out" class="justify-start">Sign out</Button>
242
+ </template>
243
+
244
+ <div class="text-sm text-muted-foreground">Pane for {{ active }}</div>
245
+ </SidebarLayout>
246
+ `,
247
+ }),
248
+ }
249
+
250
+ export const EventHandling: Story = {
251
+ parameters: noControls,
252
+ render: () => ({
253
+ components: { SidebarLayout, EventLog },
254
+ setup () {
255
+ const active = ref('general')
256
+ return { active, menus }
257
+ },
258
+ template: `
259
+ <EventLog v-slot="{ record }">
260
+ <SidebarLayout
261
+ v-model:active="active"
262
+ embedded
263
+ :menus="menus"
264
+ contentClass="p-6"
265
+ class="h-80"
266
+ @select="(item) => record('select', item.label)"
267
+ @update:active="(key) => record('update:active', key)"
268
+ >
269
+ <div class="text-sm text-muted-foreground">Pick a menu item to log its events.</div>
270
+ </SidebarLayout>
271
+ </EventLog>
272
+ `,
273
+ }),
274
+ }
@@ -0,0 +1,141 @@
1
+ <script setup lang="ts">
2
+ import type { SidebarLayoutMenuItem, SidebarLayoutProps } from './types'
3
+ import SidebarMenus from './SidebarMenus.vue'
4
+ import { sidebarMenuItemKey } from './utils'
5
+ import {
6
+ Sidebar,
7
+ SidebarContent,
8
+ SidebarFooter,
9
+ SidebarHeader,
10
+ SidebarInset,
11
+ SidebarProvider,
12
+ SidebarRail,
13
+ SidebarTrigger,
14
+ } from '../../shadcn/sidebar'
15
+ import { provideSidebarContext, SIDEBAR_WIDTH } from '../../shadcn/sidebar/utils'
16
+ import { TooltipProvider } from '../../shadcn/tooltip'
17
+
18
+ const props = withDefaults(defineProps<SidebarLayoutProps>(), {
19
+ active: undefined,
20
+ emptyText: undefined,
21
+ variant: 'sidebar',
22
+ collapsible: 'icon',
23
+ sidebarWidth: SIDEBAR_WIDTH,
24
+ contentClass: undefined,
25
+ class: undefined,
26
+ })
27
+
28
+ const emit = defineEmits<{
29
+ 'update:active': [key: string]
30
+ 'select': [item: SidebarLayoutMenuItem]
31
+ }>()
32
+
33
+ defineSlots<{
34
+ default?: () => any
35
+ header?: () => any
36
+ footer?: () => any
37
+ }>()
38
+
39
+ // The context `Sidebar` requires, without nesting `SidebarProvider` — whose
40
+ // viewport wrapper, state cookie and Cmd/Ctrl+B toggle are page-level behaviour.
41
+ // In page mode the provider mounts anyway and shadows this.
42
+ const noop = () => {}
43
+ provideSidebarContext({
44
+ state: computed(() => 'expanded' as const),
45
+ open: ref(true),
46
+ setOpen: noop,
47
+ isMobile: ref(false),
48
+ openMobile: ref(false),
49
+ setOpenMobile: noop,
50
+ toggleSidebar: noop,
51
+ })
52
+
53
+ const rootComponent = computed(() => props.embedded ? 'div' : SidebarProvider)
54
+
55
+ const rootStyle = computed(() => ({ '--sidebar-width': props.sidebarWidth }))
56
+
57
+ const rootClass = computed(() =>
58
+ cn(props.embedded && 'min-h-0 flex size-full overflow-hidden', props.class),
59
+ )
60
+
61
+ function onSelect (item: SidebarLayoutMenuItem) {
62
+ emit('select', item)
63
+ emit('update:active', sidebarMenuItemKey(item))
64
+ }
65
+ </script>
66
+
67
+ <template>
68
+ <component
69
+ :is="rootComponent"
70
+ :style="rootStyle"
71
+ :class="rootClass"
72
+ >
73
+ <!-- Menu-button tooltips need a provider, which embedded mode has none of. -->
74
+ <TooltipProvider>
75
+ <!-- `shrink-0`: wide pane content scrolls instead of squeezing the menu. -->
76
+ <Sidebar
77
+ :variant="variant"
78
+ :collapsible="embedded ? 'none' : collapsible"
79
+ :class="embedded ? 'shrink-0 border-r' : undefined"
80
+ >
81
+ <SidebarHeader v-if="$slots.header">
82
+ <slot name="header" />
83
+ </SidebarHeader>
84
+
85
+ <SidebarContent class="overflow-hidden">
86
+ <ScrollArea
87
+ fadeMask
88
+ class="min-h-0 flex-1"
89
+ >
90
+ <SidebarMenus
91
+ :menus="menus"
92
+ :active="active"
93
+ :emptyText="emptyText"
94
+ @select="onSelect"
95
+ />
96
+ </ScrollArea>
97
+ </SidebarContent>
98
+
99
+ <SidebarFooter v-if="$slots.footer">
100
+ <slot name="footer" />
101
+ </SidebarFooter>
102
+
103
+ <SidebarRail v-if="!embedded" />
104
+ </Sidebar>
105
+
106
+ <!-- The nav keeps the page ground, so the content takes the raised surface —
107
+ embedded, the container owns it (a modal is `bg-popover`).
108
+ Top padding on mobile reserves a safe area for the floating trigger. -->
109
+ <SidebarInset
110
+ :class="[
111
+ 'min-w-0',
112
+ embedded ? 'bg-transparent' : 'bg-card',
113
+ !embedded && `
114
+ pt-14
115
+ md:pt-0
116
+ `,
117
+ ]"
118
+ >
119
+ <!-- Mobile-only trigger: the desktop toggle lives in the sidebar header. -->
120
+ <SidebarTrigger
121
+ v-if="!embedded"
122
+ class="
123
+ left-3 top-3 size-9 rounded-md bg-background/80 shadow-sm
124
+ backdrop-blur-sm
125
+ md:hidden
126
+ absolute z-30 cursor-pointer border
127
+ "
128
+ />
129
+
130
+ <ScrollArea
131
+ fadeMask
132
+ class="min-h-0 flex-1"
133
+ >
134
+ <div :class="contentClass">
135
+ <slot />
136
+ </div>
137
+ </ScrollArea>
138
+ </SidebarInset>
139
+ </TooltipProvider>
140
+ </component>
141
+ </template>
@@ -0,0 +1,31 @@
1
+ import type { Component } from 'vue'
2
+
3
+ export interface SidebarLayoutMenuItem {
4
+ label: string
5
+ /** Identity used for key-based selection. Falls back to `href`, then `label`. */
6
+ key?: string
7
+ icon?: string | Component
8
+ href?: string
9
+ command?: () => void
10
+ group?: string
11
+ expanded?: boolean
12
+ children?: SidebarLayoutMenuItem[]
13
+ actions?: SidebarLayoutMenuItem[]
14
+ }
15
+
16
+ export interface SidebarLayoutProps {
17
+ menus: SidebarLayoutMenuItem[]
18
+ /** Key of the selected item. Omitted → the active item is matched by route. */
19
+ active?: string
20
+ /** Placeholder shown when `menus` is empty. */
21
+ emptyText?: string
22
+ /** Fill the parent instead of the viewport: never collapses, no rail or mobile trigger. */
23
+ embedded?: boolean
24
+ variant?: 'sidebar' | 'floating' | 'inset'
25
+ /** Collapse behaviour of the sidebar. Ignored while `embedded`. */
26
+ collapsible?: 'offcanvas' | 'icon' | 'none'
27
+ /** Width of the sidebar, as a CSS length. */
28
+ sidebarWidth?: string
29
+ contentClass?: ClassValue
30
+ class?: ClassValue
31
+ }
@@ -0,0 +1,29 @@
1
+ import type { SidebarLayoutMenuItem } from './types'
2
+
3
+ /** Identity for key-based selection; an explicit `key` is only needed when neither fallback is unique. */
4
+ export function sidebarMenuItemKey (item: SidebarLayoutMenuItem): string {
5
+ return item.key ?? item.href ?? item.label
6
+ }
7
+
8
+ export function findSidebarMenuItem (
9
+ menus: SidebarLayoutMenuItem[],
10
+ key: string,
11
+ ): SidebarLayoutMenuItem | undefined {
12
+ for (const item of menus) {
13
+ if (sidebarMenuItemKey(item) === key) return item
14
+ const child = item.children && findSidebarMenuItem(item.children, key)
15
+ if (child) return child
16
+ }
17
+ return undefined
18
+ }
19
+
20
+ export function firstSidebarMenuItemKey (
21
+ menus: SidebarLayoutMenuItem[],
22
+ ): string | undefined {
23
+ for (const item of menus) {
24
+ if (!item.children?.length) return sidebarMenuItemKey(item)
25
+ const key = firstSidebarMenuItemKey(item.children)
26
+ if (key) return key
27
+ }
28
+ return undefined
29
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "noResults": "No results",
3
+ "searchPlaceholder": "Search"
4
+ }