@bjj/nuxt-layer-shadcn-ui 0.10.3 → 0.11.1

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 (42) 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 +2 -2
  10. package/app/components/ui/AsyncDataTable/index.vue +4 -9
  11. package/app/components/ui/AsyncDataTable/types.ts +7 -7
  12. package/app/components/ui/DataTable/index.stories.ts +45 -0
  13. package/app/components/ui/DataTable/index.vue +20 -3
  14. package/app/components/ui/DataTable/types.ts +3 -1
  15. package/app/components/ui/StaticDataTable/en.json +3 -0
  16. package/app/components/ui/StaticDataTable/index.stories.ts +233 -0
  17. package/app/components/ui/StaticDataTable/index.vue +250 -0
  18. package/app/components/ui/StaticDataTable/types.ts +37 -0
  19. package/app/components/ui/Steps/index.stories.ts +219 -0
  20. package/app/components/ui/Steps/index.vue +129 -0
  21. package/app/components/ui/Steps/types.ts +34 -0
  22. package/app/components/ui/Upload/index.vue +1 -1
  23. package/i18n/messages/ar.json +3 -0
  24. package/i18n/messages/de.json +3 -0
  25. package/i18n/messages/en.json +3 -0
  26. package/i18n/messages/es.json +3 -0
  27. package/i18n/messages/fr.json +3 -0
  28. package/i18n/messages/hi.json +3 -0
  29. package/i18n/messages/id.json +3 -0
  30. package/i18n/messages/it.json +3 -0
  31. package/i18n/messages/ja.json +3 -0
  32. package/i18n/messages/ko.json +3 -0
  33. package/i18n/messages/nl.json +3 -0
  34. package/i18n/messages/pl.json +3 -0
  35. package/i18n/messages/pt.json +3 -0
  36. package/i18n/messages/ru.json +3 -0
  37. package/i18n/messages/th.json +3 -0
  38. package/i18n/messages/tr.json +3 -0
  39. package/i18n/messages/vi.json +3 -0
  40. package/i18n/messages/zh-CN.json +3 -0
  41. package/i18n/messages/zh-TW.json +3 -0
  42. 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,9 +77,9 @@ 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' },
82
+ topToolbarThreshold: { control: 'number' },
83
83
  showBottomToolbar: { control: 'boolean' },
84
84
  pageSizeOptions: { control: 'object' },
85
85
  showPagination: { control: 'boolean' },
@@ -92,9 +92,9 @@ const meta = {
92
92
  columns,
93
93
  fetchMethod: mockFetch,
94
94
  autoFetch: true,
95
- data: [],
96
95
  filters: undefined,
97
96
  showTopToolbar: undefined,
97
+ topToolbarThreshold: 50,
98
98
  showBottomToolbar: true,
99
99
  pageSizeOptions: [ 10, 20, 50 ],
100
100
  showPagination: true,
@@ -11,12 +11,11 @@ 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,
18
+ topToolbarThreshold: 50,
20
19
  showBottomToolbar: true,
21
20
  pageSizeOptions: () => [ 10, 20, 50, 100 ],
22
21
  showPagination: true,
@@ -64,9 +63,6 @@ const sortState = ref<{ sortBy: string | null, sortOrder: number | null }>({
64
63
 
65
64
  // -- Computed --
66
65
 
67
- const useFetchMode = computed(() => !!props.fetchMethod)
68
- const tableData = computed(() => useFetchMode.value ? internalData.value : props.data)
69
-
70
66
  const showSelectionColumn = computed(() => props.selectable || props.batchActions.length > 0)
71
67
  const selectedCount = computed(() => props.selection?.length ?? 0)
72
68
  const hasBatchActions = computed(() => props.batchActions.length > 0)
@@ -76,7 +72,7 @@ const hasPaginationData = computed(() => pagination.value.total > 0)
76
72
 
77
73
  const shouldShowTopToolbar = computed(() => {
78
74
  if (props.showTopToolbar !== undefined) return props.showTopToolbar
79
- return pagination.value.size >= 50
75
+ return pagination.value.size >= props.topToolbarThreshold
80
76
  })
81
77
 
82
78
  const shouldShowBottomToolbar = computed(() => props.showBottomToolbar)
@@ -98,7 +94,6 @@ const batchMenuItems = computed<DropdownItem[]>(() =>
98
94
  // -- Data fetching --
99
95
 
100
96
  async function fetchData (page?: number, forceRefresh = false) {
101
- if (!props.fetchMethod) return
102
97
  if (loading.value && !forceRefresh) return
103
98
 
104
99
  const currentVersion = ++requestVersion.value
@@ -261,7 +256,7 @@ onMounted(() => {
261
256
  <!-- DataTable -->
262
257
  <DataTable
263
258
  :selection="selectionValue"
264
- :data="tableData"
259
+ :data="internalData"
265
260
  :columns="columns"
266
261
  :loading="loading"
267
262
  :selectionMode="showSelectionColumn ? 'multiple' : undefined"
@@ -18,18 +18,18 @@ 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
- /** Whether to show top toolbar (undefined = auto when page size >= 50) */
29
+ /** Whether to show top toolbar (undefined = auto when page size >= `topToolbarThreshold`) */
32
30
  showTopToolbar?: boolean
31
+ /** Page-size threshold that triggers the top toolbar when `showTopToolbar` is undefined (default: 50) */
32
+ topToolbarThreshold?: number
33
33
  /** Whether to show bottom toolbar (default: true) */
34
34
  showBottomToolbar?: boolean
35
35
  /** Available page size options */
@@ -182,6 +182,51 @@ export const ColumnTypes: Story = {
182
182
  }),
183
183
  }
184
184
 
185
+ /** `maxWidth` caps a column's width. With the default `wrap: false`, overflowing text is truncated with an ellipsis; `wrap: true` lets it wrap onto multiple lines instead. */
186
+ export const ColumnMaxWidth: Story = {
187
+ parameters: {
188
+ ...noControls,
189
+ docs: {
190
+ source: {
191
+ code: `
192
+ <template>
193
+ <DataTable :data="data" :columns="columns" />
194
+ </template>
195
+
196
+ <script setup>
197
+ const columns = [
198
+ { field: 'name', title: 'Name', width: '120px' },
199
+ { field: 'bio', title: 'Truncated bio (maxWidth)', maxWidth: '240px' },
200
+ { field: 'bio', title: 'Wrapped bio (maxWidth + wrap)', maxWidth: '240px', wrap: true },
201
+ ]
202
+ </script>
203
+ `.trim(),
204
+ },
205
+ },
206
+ },
207
+ render: () => ({
208
+ components: { DataTable: DataTable as any },
209
+ setup () {
210
+ const data = [
211
+ { name: 'Alice', bio: 'Staff engineer focused on developer tooling, build performance, and design systems at scale.' },
212
+ { name: 'Bob', bio: 'Short bio.' },
213
+ { name: 'Charlie', bio: 'Product designer who likes long, descriptive paragraphs that absolutely will not fit in one row.' },
214
+ ]
215
+ const columns: DataTableColumn[] = [
216
+ { field: 'name', title: 'Name', width: '120px' },
217
+ { field: 'bio', title: 'Truncated bio (maxWidth)', maxWidth: '240px' },
218
+ { field: 'bio', title: 'Wrapped bio (maxWidth + wrap)', maxWidth: '240px', wrap: true },
219
+ ]
220
+ return { data, columns }
221
+ },
222
+ template: `
223
+ <div class="w-full">
224
+ <DataTable :data="data" :columns="columns" />
225
+ </div>
226
+ `,
227
+ }),
228
+ }
229
+
185
230
  export const RowClick: Story = {
186
231
  parameters: {
187
232
  ...noControls,
@@ -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
@@ -239,6 +243,14 @@ function buildColumnClass (column: DataTableColumn, headerIndex?: number): strin
239
243
  )
240
244
  }
241
245
 
246
+ // Applied to an inner div, not the cell — keeps the cell `overflow: visible`
247
+ // so the frozen-column shadow ::before isn't clipped.
248
+ function buildCellContentClass (column: DataTableColumn): string | null {
249
+ if (column.wrap) return null
250
+ if (column.type === 'date' || column.type === 'unixDate') return null
251
+ return 'truncate'
252
+ }
253
+
242
254
  function buildFrozenShadow (column: DataTableColumn): FrozenShadow | undefined {
243
255
  if (column.field === lastLeftFrozenField.value && !atStart.value) return 'left'
244
256
  if (column.field === firstRightFrozenField.value && !atEnd.value) return 'right'
@@ -249,6 +261,7 @@ function buildColumnStyle (column: DataTableColumn): Record<string, string> {
249
261
  const style: Record<string, string> = {}
250
262
  if (column.width) style.width = column.width
251
263
  if (column.minWidth) style.minWidth = column.minWidth
264
+ if (column.maxWidth) style.maxWidth = column.maxWidth
252
265
 
253
266
  // Frozen column offset
254
267
  const offset = frozenOffsets.value.get(column.field)
@@ -353,7 +366,9 @@ defineExpose({
353
366
  column.align === 'right' && 'justify-end',
354
367
  )"
355
368
  >
356
- <span>{{ column.title }}</span>
369
+ <span :class="!column.wrap && 'min-w-0 truncate'">
370
+ {{ column.title }}
371
+ </span>
357
372
  <Icon
358
373
  v-if="getSortIcon(column)"
359
374
  :name="getSortIcon(column)!"
@@ -424,7 +439,9 @@ defineExpose({
424
439
  :empty="!formatCellValue(get(row, column.field), column)"
425
440
  >
426
441
  <template #default>
427
- {{ formatCellValue(get(row, column.field), column) }}
442
+ <div :class="buildCellContentClass(column)">
443
+ {{ formatCellValue(get(row, column.field), column) }}
444
+ </div>
428
445
  </template>
429
446
  <template #empty>
430
447
  <span :class="emptyCellClass" />
@@ -14,9 +14,11 @@ export interface DataTableColumn {
14
14
  width?: string
15
15
  /** Minimum column width (e.g., '100px', '10rem') */
16
16
  minWidth?: string
17
+ /** Maximum column width (e.g., '200px', '20rem') */
18
+ maxWidth?: string
17
19
  /** Fixed column position: left or right */
18
20
  fixed?: DataTableColumnFixed
19
- /** Whether text can wrap. Default: false (no wrap) */
21
+ /** Whether text can wrap. Default: false (truncate with ellipsis) */
20
22
  wrap?: boolean
21
23
  /** Text alignment. Default: 'left' */
22
24
  align?: DataTableColumnAlign
@@ -0,0 +1,3 @@
1
+ {
2
+ "actions": "Actions"
3
+ }
@@ -0,0 +1,233 @@
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
+ topToolbarThreshold: { control: 'number' },
76
+ showBottomToolbar: { control: 'boolean' },
77
+ pageSizeOptions: { control: 'object' },
78
+ showPagination: { control: 'boolean' },
79
+ selectable: { control: 'boolean' },
80
+ clickable: { control: 'boolean' },
81
+ batchActions: { control: 'object' },
82
+ selection: { control: 'object' },
83
+ },
84
+ args: {
85
+ data: allUsers,
86
+ columns,
87
+ sortMethod: undefined,
88
+ showTopToolbar: undefined,
89
+ topToolbarThreshold: 50,
90
+ showBottomToolbar: true,
91
+ pageSizeOptions: [ 10, 20, 50 ],
92
+ showPagination: true,
93
+ selectable: false,
94
+ clickable: false,
95
+ batchActions: [],
96
+ selection: [],
97
+ },
98
+ render: args => ({
99
+ components: { StaticDataTable },
100
+ setup: () => ({ args }),
101
+ template: '<StaticDataTable v-bind="args" />',
102
+ }),
103
+ } satisfies Meta<typeof StaticDataTable>
104
+
105
+ export default meta
106
+ type Story = StoryObj<typeof meta>
107
+
108
+ const noControls = { controls: { disable: true }} satisfies Story['parameters']
109
+
110
+ /** Local data with header-driven sorting and built-in pagination. */
111
+ export const Default: Story = {}
112
+
113
+ /** Batch actions with row selection and dual toolbars. */
114
+ export const WithBatchActions: Story = {
115
+ parameters: {
116
+ ...noControls,
117
+ docs: {
118
+ source: {
119
+ code: `
120
+ <template>
121
+ <StaticDataTable
122
+ :data="users"
123
+ :columns="columns"
124
+ :batchActions="batchActions"
125
+ v-model:selection="selection"
126
+ showTopToolbar
127
+ />
128
+ </template>
129
+ `.trim(),
130
+ },
131
+ },
132
+ },
133
+ render: () => ({
134
+ components: { StaticDataTable },
135
+ setup () {
136
+ const selection = ref<User[]>([])
137
+ return { users: allUsers, columns, selection, batchActions }
138
+ },
139
+ template: `
140
+ <StaticDataTable
141
+ :data="users"
142
+ :columns="columns"
143
+ :batchActions="batchActions"
144
+ v-model:selection="selection"
145
+ showTopToolbar
146
+ />
147
+ <div class="mt-2 text-sm text-muted-foreground">
148
+ Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
149
+ </div>
150
+ `,
151
+ }),
152
+ }
153
+
154
+ /** Custom toolbar slot with an action button. */
155
+ export const WithCustomToolbar: Story = {
156
+ parameters: {
157
+ ...noControls,
158
+ docs: {
159
+ source: {
160
+ code: `
161
+ <template>
162
+ <StaticDataTable :data="users" :columns="columns" showTopToolbar>
163
+ <template #toolbar>
164
+ <button class="rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground">
165
+ + Add User
166
+ </button>
167
+ </template>
168
+ </StaticDataTable>
169
+ </template>
170
+ `.trim(),
171
+ },
172
+ },
173
+ },
174
+ render: () => ({
175
+ components: { StaticDataTable },
176
+ setup: () => ({ users: allUsers, columns }),
177
+ template: `
178
+ <StaticDataTable
179
+ :data="users"
180
+ :columns="columns"
181
+ showTopToolbar
182
+ >
183
+ <template #toolbar>
184
+ <button class="rounded-md bg-primary px-3 py-1.5 text-sm text-primary-foreground">
185
+ + Add User
186
+ </button>
187
+ </template>
188
+ </StaticDataTable>
189
+ `,
190
+ }),
191
+ }
192
+
193
+ /** Override the default comparator — here `role` sorts by priority (Admin → Editor → User) instead of alphabetically. */
194
+ export const WithCustomSort: Story = {
195
+ parameters: {
196
+ ...noControls,
197
+ docs: {
198
+ source: {
199
+ code: `
200
+ <template>
201
+ <StaticDataTable
202
+ :data="users"
203
+ :columns="columns"
204
+ :sortMethod="rolePrioritySort"
205
+ />
206
+ </template>
207
+
208
+ <script setup>
209
+ const rolePrioritySort = (items, sortBy, sortOrder) => {
210
+ if (sortBy !== 'role') return defaultGenericSort(items, sortBy, sortOrder)
211
+ const rank = { Admin: 0, Editor: 1, User: 2 }
212
+ return [ ...items ].sort((a, b) => {
213
+ const diff = (rank[a.role] - rank[b.role]) * sortOrder
214
+ return diff !== 0 ? diff : a.name.localeCompare(b.name)
215
+ })
216
+ }
217
+ </script>
218
+ `.trim(),
219
+ },
220
+ },
221
+ },
222
+ render: () => ({
223
+ components: { StaticDataTable },
224
+ setup: () => ({ users: allUsers, columns, rolePrioritySort }),
225
+ template: `
226
+ <StaticDataTable
227
+ :data="users"
228
+ :columns="columns"
229
+ :sortMethod="rolePrioritySort"
230
+ />
231
+ `,
232
+ }),
233
+ }