@bjj/nuxt-layer-shadcn-ui 0.10.3 → 0.11.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 (40) hide show
  1. package/app/components/shadcn/stepper/Stepper.vue +27 -0
  2. package/app/components/shadcn/stepper/StepperDescription.vue +19 -0
  3. package/app/components/shadcn/stepper/StepperIndicator.vue +32 -0
  4. package/app/components/shadcn/stepper/StepperItem.vue +23 -0
  5. package/app/components/shadcn/stepper/StepperSeparator.vue +27 -0
  6. package/app/components/shadcn/stepper/StepperTitle.vue +19 -0
  7. package/app/components/shadcn/stepper/StepperTrigger.vue +22 -0
  8. package/app/components/shadcn/stepper/index.ts +7 -0
  9. package/app/components/ui/AsyncDataTable/index.stories.ts +0 -2
  10. package/app/components/ui/AsyncDataTable/index.vue +2 -8
  11. package/app/components/ui/AsyncDataTable/types.ts +4 -6
  12. package/app/components/ui/DataTable/index.vue +5 -1
  13. package/app/components/ui/StaticDataTable/en.json +3 -0
  14. package/app/components/ui/StaticDataTable/index.stories.ts +231 -0
  15. package/app/components/ui/StaticDataTable/index.vue +249 -0
  16. package/app/components/ui/StaticDataTable/types.ts +35 -0
  17. package/app/components/ui/Steps/index.stories.ts +219 -0
  18. package/app/components/ui/Steps/index.vue +129 -0
  19. package/app/components/ui/Steps/types.ts +34 -0
  20. package/app/components/ui/Upload/index.vue +1 -1
  21. package/i18n/messages/ar.json +3 -0
  22. package/i18n/messages/de.json +3 -0
  23. package/i18n/messages/en.json +3 -0
  24. package/i18n/messages/es.json +3 -0
  25. package/i18n/messages/fr.json +3 -0
  26. package/i18n/messages/hi.json +3 -0
  27. package/i18n/messages/id.json +3 -0
  28. package/i18n/messages/it.json +3 -0
  29. package/i18n/messages/ja.json +3 -0
  30. package/i18n/messages/ko.json +3 -0
  31. package/i18n/messages/nl.json +3 -0
  32. package/i18n/messages/pl.json +3 -0
  33. package/i18n/messages/pt.json +3 -0
  34. package/i18n/messages/ru.json +3 -0
  35. package/i18n/messages/th.json +3 -0
  36. package/i18n/messages/tr.json +3 -0
  37. package/i18n/messages/vi.json +3 -0
  38. package/i18n/messages/zh-CN.json +3 -0
  39. package/i18n/messages/zh-TW.json +3 -0
  40. package/package.json +2 -2
@@ -0,0 +1,27 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperRootEmits, StepperRootProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperRoot, useForwardPropsEmits } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperRootProps & { class?: HTMLAttributes["class"] }>()
9
+ const emits = defineEmits<StepperRootEmits>()
10
+
11
+ const delegatedProps = reactiveOmit(props, "class")
12
+
13
+ const forwarded = useForwardPropsEmits(delegatedProps, emits)
14
+ </script>
15
+
16
+ <template>
17
+ <StepperRoot
18
+ v-slot="slotProps"
19
+ :class="cn(
20
+ 'flex gap-2',
21
+ props.class,
22
+ )"
23
+ v-bind="forwarded"
24
+ >
25
+ <slot v-bind="slotProps" />
26
+ </StepperRoot>
27
+ </template>
@@ -0,0 +1,19 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperDescriptionProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperDescription, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperDescriptionProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperDescription v-slot="slotProps" v-bind="forwarded" :class="cn('text-xs text-muted-foreground', props.class)">
17
+ <slot v-bind="slotProps" />
18
+ </StepperDescription>
19
+ </template>
@@ -0,0 +1,32 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperIndicatorProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperIndicator, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperIndicatorProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperIndicator
17
+ v-slot="slotProps"
18
+ v-bind="forwarded"
19
+ :class="cn(
20
+ 'inline-flex items-center justify-center rounded-full text-muted-foreground/50 w-8 h-8',
21
+ // Disabled
22
+ 'group-data-[disabled]:text-muted-foreground group-data-[disabled]:opacity-50',
23
+ // Active
24
+ 'group-data-[state=active]:bg-primary group-data-[state=active]:text-primary-foreground',
25
+ // Completed
26
+ 'group-data-[state=completed]:bg-accent group-data-[state=completed]:text-accent-foreground',
27
+ props.class,
28
+ )"
29
+ >
30
+ <slot v-bind="slotProps" />
31
+ </StepperIndicator>
32
+ </template>
@@ -0,0 +1,23 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperItemProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperItem, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperItemProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperItem
17
+ v-slot="slotProps"
18
+ v-bind="forwarded"
19
+ :class="cn('flex items-center gap-2 group data-[disabled]:pointer-events-none', props.class)"
20
+ >
21
+ <slot v-bind="slotProps" />
22
+ </StepperItem>
23
+ </template>
@@ -0,0 +1,27 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperSeparatorProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperSeparator, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperSeparatorProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperSeparator
17
+ v-bind="forwarded"
18
+ :class="cn(
19
+ 'bg-muted',
20
+ // Disabled
21
+ 'group-data-[disabled]:bg-muted group-data-[disabled]:opacity-50',
22
+ // Completed
23
+ 'group-data-[state=completed]:bg-accent',
24
+ props.class,
25
+ )"
26
+ />
27
+ </template>
@@ -0,0 +1,19 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperTitleProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperTitle, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperTitleProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperTitle v-bind="forwarded" :class="cn('text-md font-semibold whitespace-nowrap', props.class)">
17
+ <slot />
18
+ </StepperTitle>
19
+ </template>
@@ -0,0 +1,22 @@
1
+ <script lang="ts" setup>
2
+ import type { StepperTriggerProps } from "reka-ui"
3
+ import type { HTMLAttributes } from "vue"
4
+ import { reactiveOmit } from "@vueuse/core"
5
+ import { StepperTrigger, useForwardProps } from "reka-ui"
6
+ import { cn } from '@bjj/nuxt-layer-shadcn-ui/app/utils'
7
+
8
+ const props = defineProps<StepperTriggerProps & { class?: HTMLAttributes["class"] }>()
9
+
10
+ const delegatedProps = reactiveOmit(props, "class")
11
+
12
+ const forwarded = useForwardProps(delegatedProps)
13
+ </script>
14
+
15
+ <template>
16
+ <StepperTrigger
17
+ v-bind="forwarded"
18
+ :class="cn('p-1 flex flex-col items-center text-center gap-1 rounded-md', props.class)"
19
+ >
20
+ <slot />
21
+ </StepperTrigger>
22
+ </template>
@@ -0,0 +1,7 @@
1
+ export { default as Stepper } from "./Stepper.vue"
2
+ export { default as StepperDescription } from "./StepperDescription.vue"
3
+ export { default as StepperIndicator } from "./StepperIndicator.vue"
4
+ export { default as StepperItem } from "./StepperItem.vue"
5
+ export { default as StepperSeparator } from "./StepperSeparator.vue"
6
+ export { default as StepperTitle } from "./StepperTitle.vue"
7
+ export { default as StepperTrigger } from "./StepperTrigger.vue"
@@ -77,7 +77,6 @@ const meta = {
77
77
  columns: { control: 'object' },
78
78
  fetchMethod: { control: false },
79
79
  autoFetch: { control: 'boolean' },
80
- data: { control: 'object' },
81
80
  filters: { control: 'object' },
82
81
  showTopToolbar: { control: 'boolean' },
83
82
  showBottomToolbar: { control: 'boolean' },
@@ -92,7 +91,6 @@ const meta = {
92
91
  columns,
93
92
  fetchMethod: mockFetch,
94
93
  autoFetch: true,
95
- data: [],
96
94
  filters: undefined,
97
95
  showTopToolbar: undefined,
98
96
  showBottomToolbar: true,
@@ -11,10 +11,8 @@ interface AsyncDataTablePagination {
11
11
  }
12
12
 
13
13
  const props = withDefaults(defineProps<AsyncDataTableProps<TData>>(), {
14
- columns: () => [],
15
- fetchMethod: undefined,
16
14
  autoFetch: true,
17
- data: () => [],
15
+ columns: () => [],
18
16
  filters: undefined,
19
17
  showTopToolbar: undefined,
20
18
  showBottomToolbar: true,
@@ -64,9 +62,6 @@ const sortState = ref<{ sortBy: string | null, sortOrder: number | null }>({
64
62
 
65
63
  // -- Computed --
66
64
 
67
- const useFetchMode = computed(() => !!props.fetchMethod)
68
- const tableData = computed(() => useFetchMode.value ? internalData.value : props.data)
69
-
70
65
  const showSelectionColumn = computed(() => props.selectable || props.batchActions.length > 0)
71
66
  const selectedCount = computed(() => props.selection?.length ?? 0)
72
67
  const hasBatchActions = computed(() => props.batchActions.length > 0)
@@ -98,7 +93,6 @@ const batchMenuItems = computed<DropdownItem[]>(() =>
98
93
  // -- Data fetching --
99
94
 
100
95
  async function fetchData (page?: number, forceRefresh = false) {
101
- if (!props.fetchMethod) return
102
96
  if (loading.value && !forceRefresh) return
103
97
 
104
98
  const currentVersion = ++requestVersion.value
@@ -261,7 +255,7 @@ onMounted(() => {
261
255
  <!-- DataTable -->
262
256
  <DataTable
263
257
  :selection="selectionValue"
264
- :data="tableData"
258
+ :data="internalData"
265
259
  :columns="columns"
266
260
  :loading="loading"
267
261
  :selectionMode="showSelectionColumn ? 'multiple' : undefined"
@@ -18,14 +18,12 @@ export interface AsyncDataTableFetchResult<T = Record<string, any>> {
18
18
  }
19
19
 
20
20
  export interface AsyncDataTableProps<T = Record<string, any>> {
21
- /** Column definitions */
22
- columns?: DataTableColumn[]
23
- /** Async function to fetch data. If not provided, uses static data mode */
24
- fetchMethod?: (params: AsyncDataTableFetchParams) => Promise<AsyncDataTableFetchResult<T>>
21
+ /** Async function to fetch data */
22
+ fetchMethod: (params: AsyncDataTableFetchParams) => Promise<AsyncDataTableFetchResult<T>>
25
23
  /** Whether to auto fetch data on mount (default: true) */
26
24
  autoFetch?: boolean
27
- /** Static data array (used when fetchMethod is not provided) */
28
- data?: T[]
25
+ /** Column definitions */
26
+ columns?: DataTableColumn[]
29
27
  /** External filter state */
30
28
  filters?: Record<string, any>
31
29
  /** Whether to show top toolbar (undefined = auto when page size >= 50) */
@@ -225,7 +225,11 @@ function buildColumnClass (column: DataTableColumn, headerIndex?: number): strin
225
225
  return cn(
226
226
  column.align === 'center' && 'text-center',
227
227
  column.align === 'right' && 'text-right',
228
- isDateType ? 'whitespace-pre' : !column.wrap && 'whitespace-nowrap',
228
+ isDateType
229
+ ? 'whitespace-pre'
230
+ : column.wrap
231
+ ? 'whitespace-normal'
232
+ : 'whitespace-nowrap',
229
233
  // Header-specific
230
234
  isHeader && column.sortable && `
231
235
  hover:text-foreground
@@ -0,0 +1,3 @@
1
+ {
2
+ "actions": "Actions"
3
+ }
@@ -0,0 +1,231 @@
1
+ import type { Meta, StoryObj } from '@storybook/vue3'
2
+ import type { StaticDataTableBatchAction, StaticDataTableSortMethod } from './types'
3
+ import type { DataTableColumn } from '../DataTable/types'
4
+ import StaticDataTable from './index.vue'
5
+
6
+ interface User {
7
+ id: number
8
+ name: string
9
+ email: string
10
+ role: 'Admin' | 'Editor' | 'User'
11
+ status: string
12
+ amount: number
13
+ createdAt: string
14
+ }
15
+
16
+ const allUsers: User[] = Array.from({ length: 85 }, (_, i) => ({
17
+ id: i + 1,
18
+ name: `User ${i + 1}`,
19
+ email: `user${i + 1}@example.com`,
20
+ role: ([ 'Admin', 'Editor', 'User' ] as const)[i % 3]!,
21
+ status: i % 4 === 0 ? 'inactive' : 'active',
22
+ amount: Math.round(Math.random() * 10000) / 100,
23
+ createdAt: new Date(2024, 0, 1 + i).toISOString(),
24
+ }))
25
+
26
+ const columns: DataTableColumn[] = [
27
+ { field: 'name', title: 'Name', width: '120px', sortable: true },
28
+ { field: 'email', title: 'Email', minWidth: '200px' },
29
+ { field: 'role', title: 'Role', width: '100px', sortable: true },
30
+ { field: 'status', title: 'Status', width: '100px' },
31
+ { field: 'amount', title: 'Amount', width: '120px', type: 'currency', sortable: true },
32
+ { field: 'createdAt', title: 'Created', width: '140px', type: 'date' },
33
+ ]
34
+
35
+ const batchActions: StaticDataTableBatchAction<User>[] = [
36
+ {
37
+ label: 'Delete',
38
+ icon: 'trash-2',
39
+ color: 'danger',
40
+ action: items => console.debug(`Delete ${items.length} items`),
41
+ },
42
+ {
43
+ label: 'Export',
44
+ icon: 'download',
45
+ action: items => console.debug(`Export ${items.length} items`),
46
+ },
47
+ ]
48
+
49
+ /** Sort users by role priority (Admin → Editor → User), then by name as a stable tiebreaker. */
50
+ const rolePrioritySort: StaticDataTableSortMethod<User> = (items, sortBy, sortOrder) => {
51
+ if (sortBy !== 'role') {
52
+ return [ ...items ].sort((a, b) => {
53
+ const av = a[sortBy as keyof User]
54
+ const bv = b[sortBy as keyof User]
55
+ if (av! < bv!) return -1 * sortOrder
56
+ if (av! > bv!) return 1 * sortOrder
57
+ return 0
58
+ })
59
+ }
60
+ const rank: Record<User['role'], number> = { Admin: 0, Editor: 1, User: 2 }
61
+ return [ ...items ].sort((a, b) => {
62
+ const diff = (rank[a.role] - rank[b.role]) * sortOrder
63
+ return diff !== 0 ? diff : a.name.localeCompare(b.name)
64
+ })
65
+ }
66
+
67
+ const meta = {
68
+ title: 'UI/StaticDataTable',
69
+ component: StaticDataTable as any,
70
+ argTypes: {
71
+ data: { control: 'object' },
72
+ columns: { control: 'object' },
73
+ sortMethod: { control: false },
74
+ showTopToolbar: { control: 'boolean' },
75
+ showBottomToolbar: { control: 'boolean' },
76
+ pageSizeOptions: { control: 'object' },
77
+ showPagination: { control: 'boolean' },
78
+ selectable: { control: 'boolean' },
79
+ clickable: { control: 'boolean' },
80
+ batchActions: { control: 'object' },
81
+ selection: { control: 'object' },
82
+ },
83
+ args: {
84
+ data: allUsers,
85
+ columns,
86
+ sortMethod: undefined,
87
+ showTopToolbar: undefined,
88
+ showBottomToolbar: true,
89
+ pageSizeOptions: [ 10, 20, 50 ],
90
+ showPagination: true,
91
+ selectable: false,
92
+ clickable: false,
93
+ batchActions: [],
94
+ selection: [],
95
+ },
96
+ render: args => ({
97
+ components: { StaticDataTable },
98
+ setup: () => ({ args }),
99
+ template: '<StaticDataTable v-bind="args" />',
100
+ }),
101
+ } satisfies Meta<typeof StaticDataTable>
102
+
103
+ export default meta
104
+ type Story = StoryObj<typeof meta>
105
+
106
+ const noControls = { controls: { disable: true }} satisfies Story['parameters']
107
+
108
+ /** Local data with header-driven sorting and built-in pagination. */
109
+ export const Default: Story = {}
110
+
111
+ /** Batch actions with row selection and dual toolbars. */
112
+ export const WithBatchActions: Story = {
113
+ parameters: {
114
+ ...noControls,
115
+ docs: {
116
+ source: {
117
+ code: `
118
+ <template>
119
+ <StaticDataTable
120
+ :data="users"
121
+ :columns="columns"
122
+ :batchActions="batchActions"
123
+ v-model:selection="selection"
124
+ showTopToolbar
125
+ />
126
+ </template>
127
+ `.trim(),
128
+ },
129
+ },
130
+ },
131
+ render: () => ({
132
+ components: { StaticDataTable },
133
+ setup () {
134
+ const selection = ref<User[]>([])
135
+ return { users: allUsers, columns, selection, batchActions }
136
+ },
137
+ template: `
138
+ <StaticDataTable
139
+ :data="users"
140
+ :columns="columns"
141
+ :batchActions="batchActions"
142
+ v-model:selection="selection"
143
+ showTopToolbar
144
+ />
145
+ <div class="mt-2 text-sm text-muted-foreground">
146
+ Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
147
+ </div>
148
+ `,
149
+ }),
150
+ }
151
+
152
+ /** Custom toolbar slot with an action button. */
153
+ export const WithCustomToolbar: Story = {
154
+ parameters: {
155
+ ...noControls,
156
+ docs: {
157
+ source: {
158
+ code: `
159
+ <template>
160
+ <StaticDataTable :data="users" :columns="columns" showTopToolbar>
161
+ <template #toolbar>
162
+ <button class="rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground">
163
+ + Add User
164
+ </button>
165
+ </template>
166
+ </StaticDataTable>
167
+ </template>
168
+ `.trim(),
169
+ },
170
+ },
171
+ },
172
+ render: () => ({
173
+ components: { StaticDataTable },
174
+ setup: () => ({ users: allUsers, columns }),
175
+ template: `
176
+ <StaticDataTable
177
+ :data="users"
178
+ :columns="columns"
179
+ showTopToolbar
180
+ >
181
+ <template #toolbar>
182
+ <button class="rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground">
183
+ + Add User
184
+ </button>
185
+ </template>
186
+ </StaticDataTable>
187
+ `,
188
+ }),
189
+ }
190
+
191
+ /** Override the default comparator — here `role` sorts by priority (Admin → Editor → User) instead of alphabetically. */
192
+ export const WithCustomSort: Story = {
193
+ parameters: {
194
+ ...noControls,
195
+ docs: {
196
+ source: {
197
+ code: `
198
+ <template>
199
+ <StaticDataTable
200
+ :data="users"
201
+ :columns="columns"
202
+ :sortMethod="rolePrioritySort"
203
+ />
204
+ </template>
205
+
206
+ <script setup>
207
+ const rolePrioritySort = (items, sortBy, sortOrder) => {
208
+ if (sortBy !== 'role') return defaultGenericSort(items, sortBy, sortOrder)
209
+ const rank = { Admin: 0, Editor: 1, User: 2 }
210
+ return [ ...items ].sort((a, b) => {
211
+ const diff = (rank[a.role] - rank[b.role]) * sortOrder
212
+ return diff !== 0 ? diff : a.name.localeCompare(b.name)
213
+ })
214
+ }
215
+ </script>
216
+ `.trim(),
217
+ },
218
+ },
219
+ },
220
+ render: () => ({
221
+ components: { StaticDataTable },
222
+ setup: () => ({ users: allUsers, columns, rolePrioritySort }),
223
+ template: `
224
+ <StaticDataTable
225
+ :data="users"
226
+ :columns="columns"
227
+ :sortMethod="rolePrioritySort"
228
+ />
229
+ `,
230
+ }),
231
+ }