@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
@@ -2,11 +2,18 @@
2
2
  /* Reference: https://www.shadcn-vue.com/themes */
3
3
 
4
4
  :root {
5
- /* Background */
5
+ /* Background elevation axis: page -> card -> overlay, opaque colors.
6
+ In light mode card and overlay are both pure white; elevation is
7
+ expressed by shadows instead of lightness. */
6
8
  --background: oklch(0.98 0 0);
7
9
  --background-surface: oklch(1 0 0);
8
- --background-muted: oklch(0.95 0 0);
9
- --background-accent: oklch(0.93 0 0);
10
+ --background-elevated: oklch(1 0 0);
11
+
12
+ /* Background interaction axis: translucent "ink" overlays (black in light
13
+ mode, white in dark mode) that compose on any elevation surface, so
14
+ muted/hover states look consistent on page, card and overlay alike. */
15
+ --background-muted: oklch(0 0 0 / 5%);
16
+ --background-accent: oklch(0 0 0 / 8%);
10
17
 
11
18
  /* Foreground */
12
19
  --foreground: oklch(0.145 0 0);
@@ -17,9 +24,9 @@
17
24
  --primary: oklch(0.205 0 0);
18
25
  --primary-foreground: oklch(0.985 0 0);
19
26
 
20
- /* Border */
21
- --border: oklch(0.922 0 0);
22
- --input: oklch(0.922 0 0);
27
+ /* Border: translucent ink like the interaction axis, adapts to the surface beneath */
28
+ --border: oklch(0 0 0 / 10%);
29
+ --input: oklch(0 0 0 / 10%);
23
30
  --ring: oklch(0.708 0 0);
24
31
 
25
32
  /* Status */
@@ -32,12 +39,15 @@
32
39
  }
33
40
 
34
41
  .dark {
35
- /* Background — muted/accent go brighter than surface here; they're an
36
- interaction axis, not a deeper elevation level than cards. */
37
- --background: oklch(0.12 0 0);
38
- --background-surface: oklch(0.18 0 0);
39
- --background-muted: oklch(0.25 0 0);
40
- --background-accent: oklch(0.3 0 0);
42
+ /* Background elevation axis: in dark mode overlay sits above card, card
43
+ above page; steps are kept narrow for a calm ladder */
44
+ --background: oklch(0.145 0 0);
45
+ --background-surface: oklch(0.205 0 0);
46
+ --background-elevated: oklch(0.25 0 0);
47
+
48
+ /* Background interaction axis: white ink in dark mode */
49
+ --background-muted: oklch(1 0 0 / 6%);
50
+ --background-accent: oklch(1 0 0 / 10%);
41
51
 
42
52
  /* Foreground */
43
53
  --foreground: oklch(0.985 0 0);
@@ -49,7 +59,7 @@
49
59
  --primary-foreground: oklch(0.205 0 0);
50
60
 
51
61
  /* Border */
52
- --border: oklch(0.269 0 0);
62
+ --border: oklch(1 0 0 / 10%);
53
63
  --input: oklch(1 0 0 / 15%);
54
64
  --ring: oklch(0.439 0 0);
55
65
 
@@ -71,7 +81,7 @@
71
81
  /* Components */
72
82
  --color-card: var(--background-surface);
73
83
  --color-card-foreground: var(--foreground);
74
- --color-popover: var(--background-surface);
84
+ --color-popover: var(--background-elevated);
75
85
  --color-popover-foreground: var(--foreground);
76
86
 
77
87
  /* Brand */
@@ -113,4 +123,4 @@
113
123
  --color-sidebar-accent-foreground: var(--foreground-accent);
114
124
  --color-sidebar-border: var(--border);
115
125
  --color-sidebar-ring: var(--ring);
116
- }
126
+ }
@@ -2,19 +2,8 @@
2
2
  import type { AdminLayoutProps } from './types'
3
3
  import SidebarBrand from './SidebarBrand.vue'
4
4
  import SidebarDropdown from './SidebarDropdown.vue'
5
- import SidebarMenus from './SidebarMenus.vue'
6
- import {
7
- Sidebar,
8
- SidebarContent,
9
- SidebarFooter,
10
- SidebarHeader,
11
- SidebarInset,
12
- SidebarProvider,
13
- SidebarRail,
14
- SidebarTrigger,
15
- } from '../../shadcn/sidebar'
16
5
 
17
- const props = withDefaults(defineProps<AdminLayoutProps>(), {
6
+ withDefaults(defineProps<AdminLayoutProps>(), {
18
7
  brandName: undefined,
19
8
  footerDropdown: undefined,
20
9
  variant: 'sidebar',
@@ -28,65 +17,35 @@ defineSlots<{
28
17
  footer?: () => any
29
18
  logo?: () => any
30
19
  }>()
31
-
32
- const mergedContentClass = computed(() =>
33
- cn('flex-1 overflow-auto', props.contentClass),
34
- )
35
20
  </script>
36
21
 
37
22
  <template>
38
- <SidebarProvider>
39
- <Sidebar
40
- :variant="variant"
41
- :collapsible="collapsible"
42
- >
43
- <SidebarHeader>
44
- <slot name="header">
45
- <SidebarBrand :brandName="brandName">
46
- <template #logo>
47
- <slot name="logo" />
48
- </template>
49
- </SidebarBrand>
50
- </slot>
51
- </SidebarHeader>
52
-
53
- <SidebarContent>
54
- <SidebarMenus :menus="menus" />
55
- </SidebarContent>
56
-
57
- <SidebarFooter>
58
- <slot name="footer">
59
- <SidebarDropdown
60
- v-if="footerDropdown"
61
- :profile="footerDropdown.profile"
62
- :menuItems="footerDropdown.menuItems"
63
- />
64
- </slot>
65
- </SidebarFooter>
66
-
67
- <SidebarRail />
68
- </Sidebar>
69
-
70
- <!-- Top padding on mobile reserves a safe area for the floating trigger. -->
71
- <SidebarInset
72
- class="
73
- min-w-0 pt-14
74
- md:pt-0
75
- "
76
- >
77
- <!-- Mobile-only trigger: the desktop toggle lives in the sidebar header. -->
78
- <SidebarTrigger
79
- class="
80
- left-3 top-3 size-9 rounded-md bg-background/80 shadow-sm
81
- backdrop-blur-sm
82
- md:hidden
83
- absolute z-30 cursor-pointer border
84
- "
85
- />
86
-
87
- <div :class="mergedContentClass">
88
- <slot />
89
- </div>
90
- </SidebarInset>
91
- </SidebarProvider>
23
+ <SidebarLayout
24
+ :menus="menus"
25
+ :variant="variant"
26
+ :collapsible="collapsible"
27
+ :contentClass="contentClass"
28
+ >
29
+ <template #header>
30
+ <slot name="header">
31
+ <SidebarBrand :brandName="brandName">
32
+ <template #logo>
33
+ <slot name="logo" />
34
+ </template>
35
+ </SidebarBrand>
36
+ </slot>
37
+ </template>
38
+
39
+ <template #footer>
40
+ <slot name="footer">
41
+ <SidebarDropdown
42
+ v-if="footerDropdown"
43
+ :profile="footerDropdown.profile"
44
+ :menuItems="footerDropdown.menuItems"
45
+ />
46
+ </slot>
47
+ </template>
48
+
49
+ <slot />
50
+ </SidebarLayout>
92
51
  </template>
@@ -1,16 +1,8 @@
1
1
  import type { Component } from 'vue'
2
2
  import type { DropdownItem } from '../Dropdown/types'
3
+ import type { SidebarLayoutMenuItem } from '../SidebarLayout/types'
3
4
 
4
- export interface AdminLayoutSidebarMenuItem {
5
- label: string
6
- icon?: string | Component
7
- href?: string
8
- command?: () => void
9
- group?: string
10
- expanded?: boolean
11
- children?: AdminLayoutSidebarMenuItem[]
12
- actions?: AdminLayoutSidebarMenuItem[]
13
- }
5
+ export type AdminLayoutSidebarMenuItem = SidebarLayoutMenuItem
14
6
 
15
7
  export interface AdminLayoutSidebarDropdownProfile {
16
8
  title?: string
@@ -271,7 +271,7 @@ function buildColumnStyle (column: DataTableColumn): Record<string, string> {
271
271
  const heightStyle = computed(() => props.height ? { '--data-table-height': props.height } : undefined)
272
272
 
273
273
  // Reusable class fragments
274
- const headerCellClass = 'h-auto bg-border px-4 py-3 text-xs font-normal text-foreground'
274
+ const headerCellClass = 'h-auto px-4 py-3 text-xs font-normal text-foreground'
275
275
  const headerDividerClass = 'relative after:absolute after:top-1/2 after:right-0 after:h-4 after:w-px after:-translate-y-1/2 after:bg-muted-foreground/25'
276
276
  const stickyLeftClass = 'sticky left-0 z-10'
277
277
  const emptyCellClass = 'h-0.5 w-2.5 bg-muted-foreground/50 inline-block rounded-full align-middle'
@@ -293,7 +293,7 @@ defineExpose({
293
293
  <div
294
294
  :class="cn(
295
295
  `
296
- rounded-lg bg-border px-1 text-foreground @container relative
296
+ data-table-frame rounded-lg px-1 text-foreground @container relative
297
297
  overflow-hidden
298
298
  `,
299
299
  !$slots.footer && 'pb-1',
@@ -509,7 +509,7 @@ defineExpose({
509
509
  <TableRow>
510
510
  <TableCell
511
511
  :colspan="totalColumns"
512
- class="bg-border p-0!"
512
+ class="p-0!"
513
513
  >
514
514
  <div :class="footerViewportClass">
515
515
  <slot name="footer" />
@@ -522,6 +522,17 @@ defineExpose({
522
522
  </template>
523
523
 
524
524
  <style scoped>
525
+ /* Frame, sticky header and sticky footer share one opaque paint: the
526
+ translucent border tint composited over the card surface. They must stay
527
+ opaque so rows scrolling beneath sticky cells can't show through. */
528
+ .data-table-frame,
529
+ .data-table-frame :deep(thead th),
530
+ .data-table-frame :deep(tfoot td) {
531
+ background:
532
+ linear-gradient(var(--color-border), var(--color-border))
533
+ var(--color-card);
534
+ }
535
+
525
536
  :deep([data-slot="table-container"]) {
526
537
  height: var(--data-table-height, auto);
527
538
  }
@@ -545,16 +556,20 @@ defineExpose({
545
556
  }
546
557
 
547
558
  :deep(tbody tr) {
548
- --cell-bg: var(--color-card);
559
+ --cell-overlay: transparent;
549
560
  }
550
561
 
551
562
  :deep(tbody tr:not([data-virtual-row]):hover),
552
563
  :deep(tbody tr[data-state="selected"]) {
553
- --cell-bg: var(--color-muted);
564
+ --cell-overlay: var(--color-muted);
554
565
  }
555
566
 
567
+ /* Opaque card base under a translucent state overlay: frozen (sticky) cells
568
+ must fully occlude columns scrolling beneath them. */
556
569
  :deep(tbody td) {
557
- background: var(--cell-bg);
570
+ background:
571
+ linear-gradient(var(--cell-overlay), var(--cell-overlay))
572
+ var(--color-card);
558
573
  }
559
574
 
560
575
  :deep(tbody tr:has(+ tr[aria-hidden="true"])) {
@@ -1,5 +1,6 @@
1
1
  <script setup lang="ts">
2
- import type { AdminLayoutSidebarMenuItem } from './types'
2
+ import type { SidebarLayoutMenuItem } from './types'
3
+ import { sidebarMenuItemKey } from './utils'
3
4
  import {
4
5
  Collapsible,
5
6
  CollapsibleContent,
@@ -24,7 +25,14 @@ import {
24
25
  } from '../../shadcn/sidebar'
25
26
 
26
27
  const props = defineProps<{
27
- menus: AdminLayoutSidebarMenuItem[]
28
+ menus: SidebarLayoutMenuItem[]
29
+ /** Key of the selected item. Omitted → the active item is matched by route. */
30
+ active?: string
31
+ emptyText?: string
32
+ }>()
33
+
34
+ const emit = defineEmits<{
35
+ select: [item: SidebarLayoutMenuItem]
28
36
  }>()
29
37
 
30
38
  const route = useRoute()
@@ -32,13 +40,13 @@ const route = useRoute()
32
40
  const isExternal = (href: string) => /^https?:\/\//.test(href)
33
41
 
34
42
  const navGroups = computed(() => {
35
- const groups: { label?: string, items: AdminLayoutSidebarMenuItem[] }[] = []
36
- const groupMap = new Map<string | undefined, AdminLayoutSidebarMenuItem[]>()
43
+ const groups: { label?: string, items: SidebarLayoutMenuItem[] }[] = []
44
+ const groupMap = new Map<string | undefined, SidebarLayoutMenuItem[]>()
37
45
 
38
46
  for (const item of props.menus) {
39
47
  const key = item.group
40
48
  if (!groupMap.has(key)) {
41
- const items: AdminLayoutSidebarMenuItem[] = []
49
+ const items: SidebarLayoutMenuItem[] = []
42
50
  groupMap.set(key, items)
43
51
  groups.push({ label: key, items })
44
52
  }
@@ -48,17 +56,25 @@ const navGroups = computed(() => {
48
56
  return groups
49
57
  })
50
58
 
51
- function isActive (href?: string): boolean {
59
+ function isActive (item: SidebarLayoutMenuItem): boolean {
60
+ if (props.active !== undefined) return sidebarMenuItemKey(item) === props.active
61
+ const href = item.href
52
62
  if (!href || isExternal(href)) return false
53
63
  return route.path.startsWith(href)
54
64
  }
55
65
 
56
- function isLink (item: AdminLayoutSidebarMenuItem): boolean {
66
+ function isLink (item: SidebarLayoutMenuItem): boolean {
57
67
  return !!item.href
58
68
  }
59
69
 
60
- function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
61
- return item.children?.some(child => isActive(child.href)) ?? false
70
+ function hasActiveChild (item: SidebarLayoutMenuItem): boolean {
71
+ return item.children?.some(isActive) ?? false
72
+ }
73
+
74
+ // A linked item navigates through its `WebLink`, so `command` is for the rest.
75
+ function handleSelect (item: SidebarLayoutMenuItem) {
76
+ emit('select', item)
77
+ if (!isLink(item)) item.command?.()
62
78
  }
63
79
  </script>
64
80
 
@@ -73,11 +89,11 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
73
89
  <SidebarMenu>
74
90
  <template
75
91
  v-for="item in group.items"
76
- :key="item.label"
92
+ :key="sidebarMenuItemKey(item)"
77
93
  >
78
94
  <!-- Collapsible item with children -->
79
95
  <Collapsible
80
- v-if="item.children"
96
+ v-if="item.children?.length"
81
97
  asChild
82
98
  :defaultOpen="item.expanded ?? hasActiveChild(item)"
83
99
  class="group/collapsible"
@@ -103,18 +119,20 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
103
119
  <SidebarMenuSub>
104
120
  <SidebarMenuSubItem
105
121
  v-for="child in item.children"
106
- :key="child.label"
122
+ :key="sidebarMenuItemKey(child)"
107
123
  >
108
124
  <!-- The vendored sub-button renders `data-active=""` when active while its
109
125
  built-in styles only match `data-active="true"`, so the active styles
110
126
  are re-applied here via an attribute-presence selector. -->
111
127
  <SidebarMenuSubButton
112
128
  :asChild="isLink(child)"
113
- :isActive="isActive(child.href)"
129
+ :isActive="isActive(child)"
114
130
  class="
115
131
  data-active:bg-sidebar-accent
116
132
  data-active:text-sidebar-accent-foreground
133
+ cursor-pointer
117
134
  "
135
+ @click="handleSelect(child)"
118
136
  >
119
137
  <WebLink
120
138
  v-if="isLink(child)"
@@ -123,10 +141,7 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
123
141
  >
124
142
  <span>{{ child.label }}</span>
125
143
  </WebLink>
126
- <span
127
- v-else
128
- @click="child.command?.()"
129
- >
144
+ <span v-else>
130
145
  {{ child.label }}
131
146
  </span>
132
147
  </SidebarMenuSubButton>
@@ -136,13 +151,14 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
136
151
  </SidebarMenuItem>
137
152
  </Collapsible>
138
153
 
139
- <!-- Item with actions dropdown -->
140
- <SidebarMenuItem v-else-if="item.actions">
154
+ <!-- Leaf item, optionally with an actions dropdown -->
155
+ <SidebarMenuItem v-else>
141
156
  <SidebarMenuButton
142
157
  :asChild="isLink(item)"
143
- :isActive="isActive(item.href)"
158
+ :isActive="isActive(item)"
144
159
  :tooltip="item.label"
145
- @click="!isLink(item) ? item.command?.() : undefined"
160
+ class="cursor-pointer"
161
+ @click="handleSelect(item)"
146
162
  >
147
163
  <WebLink
148
164
  v-if="isLink(item)"
@@ -168,7 +184,8 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
168
184
  <span>{{ item.label }}</span>
169
185
  </template>
170
186
  </SidebarMenuButton>
171
- <DropdownMenu>
187
+
188
+ <DropdownMenu v-if="item.actions">
172
189
  <DropdownMenuTrigger asChild>
173
190
  <SidebarMenuAction showOnHover>
174
191
  <Icon name="ellipsis" />
@@ -209,41 +226,14 @@ function hasActiveChild (item: AdminLayoutSidebarMenuItem): boolean {
209
226
  </DropdownMenuContent>
210
227
  </DropdownMenu>
211
228
  </SidebarMenuItem>
212
-
213
- <!-- Simple item -->
214
- <SidebarMenuItem v-else>
215
- <SidebarMenuButton
216
- :asChild="isLink(item)"
217
- :isActive="isActive(item.href)"
218
- :tooltip="item.label"
219
- @click="!isLink(item) ? item.command?.() : undefined"
220
- >
221
- <WebLink
222
- v-if="isLink(item)"
223
- :href="item.href"
224
- unstyled
225
- >
226
- <Icon
227
- v-if="item.icon"
228
- :name="item.icon"
229
- />
230
- <span>{{ item.label }}</span>
231
- <Icon
232
- v-if="isExternal(item.href!)"
233
- name="external-link"
234
- class="size-3.5 text-sidebar-foreground/50 ml-auto"
235
- />
236
- </WebLink>
237
- <template v-else>
238
- <Icon
239
- v-if="item.icon"
240
- :name="item.icon"
241
- />
242
- <span>{{ item.label }}</span>
243
- </template>
244
- </SidebarMenuButton>
245
- </SidebarMenuItem>
246
229
  </template>
247
230
  </SidebarMenu>
248
231
  </SidebarGroup>
232
+
233
+ <div
234
+ v-if="emptyText && !navGroups.length"
235
+ class="px-2 py-6 text-sm text-muted-foreground text-center"
236
+ >
237
+ {{ emptyText }}
238
+ </div>
249
239
  </template>