@bjj/nuxt-layer-shadcn-ui 0.11.0 → 0.11.2
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/AdminLayout/Navbar.vue +4 -4
- package/app/components/ui/AsyncDataTable/index.stories.ts +2 -0
- package/app/components/ui/AsyncDataTable/index.vue +2 -1
- package/app/components/ui/AsyncDataTable/types.ts +3 -1
- package/app/components/ui/DataTable/index.stories.ts +45 -0
- package/app/components/ui/DataTable/index.vue +15 -2
- package/app/components/ui/DataTable/types.ts +3 -1
- package/app/components/ui/StaticDataTable/index.stories.ts +2 -0
- package/app/components/ui/StaticDataTable/index.vue +2 -1
- package/app/components/ui/StaticDataTable/types.ts +3 -1
- package/package.json +2 -2
|
@@ -5,15 +5,15 @@ import { SidebarTrigger } from '../../shadcn/sidebar'
|
|
|
5
5
|
<template>
|
|
6
6
|
<header
|
|
7
7
|
class="
|
|
8
|
-
|
|
9
|
-
bg-card px-4 text-card-foreground transition-[width,height] ease-linear
|
|
8
|
+
h-14 gap-3 border-sidebar-border bg-card px-4 text-card-foreground
|
|
10
9
|
group-has-data-[collapsible=icon]/sidebar-wrapper:h-12
|
|
10
|
+
flex shrink-0 items-center border-b transition-[width,height] ease-linear
|
|
11
11
|
"
|
|
12
12
|
>
|
|
13
|
-
<SidebarTrigger class="-
|
|
13
|
+
<SidebarTrigger class="-mx-1" />
|
|
14
14
|
<Divider
|
|
15
15
|
type="vertical"
|
|
16
|
-
class="
|
|
16
|
+
class="h-4!"
|
|
17
17
|
/>
|
|
18
18
|
<div class="flex flex-1 items-center">
|
|
19
19
|
<slot />
|
|
@@ -79,6 +79,7 @@ const meta = {
|
|
|
79
79
|
autoFetch: { control: 'boolean' },
|
|
80
80
|
filters: { control: 'object' },
|
|
81
81
|
showTopToolbar: { control: 'boolean' },
|
|
82
|
+
topToolbarThreshold: { control: 'number' },
|
|
82
83
|
showBottomToolbar: { control: 'boolean' },
|
|
83
84
|
pageSizeOptions: { control: 'object' },
|
|
84
85
|
showPagination: { control: 'boolean' },
|
|
@@ -93,6 +94,7 @@ const meta = {
|
|
|
93
94
|
autoFetch: true,
|
|
94
95
|
filters: undefined,
|
|
95
96
|
showTopToolbar: undefined,
|
|
97
|
+
topToolbarThreshold: 50,
|
|
96
98
|
showBottomToolbar: true,
|
|
97
99
|
pageSizeOptions: [ 10, 20, 50 ],
|
|
98
100
|
showPagination: true,
|
|
@@ -15,6 +15,7 @@ const props = withDefaults(defineProps<AsyncDataTableProps<TData>>(), {
|
|
|
15
15
|
columns: () => [],
|
|
16
16
|
filters: undefined,
|
|
17
17
|
showTopToolbar: undefined,
|
|
18
|
+
topToolbarThreshold: 50,
|
|
18
19
|
showBottomToolbar: true,
|
|
19
20
|
pageSizeOptions: () => [ 10, 20, 50, 100 ],
|
|
20
21
|
showPagination: true,
|
|
@@ -71,7 +72,7 @@ const hasPaginationData = computed(() => pagination.value.total > 0)
|
|
|
71
72
|
|
|
72
73
|
const shouldShowTopToolbar = computed(() => {
|
|
73
74
|
if (props.showTopToolbar !== undefined) return props.showTopToolbar
|
|
74
|
-
return pagination.value.size >=
|
|
75
|
+
return pagination.value.size >= props.topToolbarThreshold
|
|
75
76
|
})
|
|
76
77
|
|
|
77
78
|
const shouldShowBottomToolbar = computed(() => props.showBottomToolbar)
|
|
@@ -26,8 +26,10 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
26
26
|
columns?: DataTableColumn[]
|
|
27
27
|
/** External filter state */
|
|
28
28
|
filters?: Record<string, any>
|
|
29
|
-
/** Whether to show top toolbar (undefined = auto when page size >=
|
|
29
|
+
/** Whether to show top toolbar (undefined = auto when page size >= `topToolbarThreshold`) */
|
|
30
30
|
showTopToolbar?: boolean
|
|
31
|
+
/** Page-size threshold that triggers the top toolbar when `showTopToolbar` is undefined (default: 50) */
|
|
32
|
+
topToolbarThreshold?: number
|
|
31
33
|
/** Whether to show bottom toolbar (default: true) */
|
|
32
34
|
showBottomToolbar?: boolean
|
|
33
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,
|
|
@@ -243,6 +243,14 @@ function buildColumnClass (column: DataTableColumn, headerIndex?: number): strin
|
|
|
243
243
|
)
|
|
244
244
|
}
|
|
245
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
|
+
|
|
246
254
|
function buildFrozenShadow (column: DataTableColumn): FrozenShadow | undefined {
|
|
247
255
|
if (column.field === lastLeftFrozenField.value && !atStart.value) return 'left'
|
|
248
256
|
if (column.field === firstRightFrozenField.value && !atEnd.value) return 'right'
|
|
@@ -253,6 +261,7 @@ function buildColumnStyle (column: DataTableColumn): Record<string, string> {
|
|
|
253
261
|
const style: Record<string, string> = {}
|
|
254
262
|
if (column.width) style.width = column.width
|
|
255
263
|
if (column.minWidth) style.minWidth = column.minWidth
|
|
264
|
+
if (column.maxWidth) style.maxWidth = column.maxWidth
|
|
256
265
|
|
|
257
266
|
// Frozen column offset
|
|
258
267
|
const offset = frozenOffsets.value.get(column.field)
|
|
@@ -357,7 +366,9 @@ defineExpose({
|
|
|
357
366
|
column.align === 'right' && 'justify-end',
|
|
358
367
|
)"
|
|
359
368
|
>
|
|
360
|
-
<span
|
|
369
|
+
<span :class="!column.wrap && 'min-w-0 truncate'">
|
|
370
|
+
{{ column.title }}
|
|
371
|
+
</span>
|
|
361
372
|
<Icon
|
|
362
373
|
v-if="getSortIcon(column)"
|
|
363
374
|
:name="getSortIcon(column)!"
|
|
@@ -428,7 +439,9 @@ defineExpose({
|
|
|
428
439
|
:empty="!formatCellValue(get(row, column.field), column)"
|
|
429
440
|
>
|
|
430
441
|
<template #default>
|
|
431
|
-
|
|
442
|
+
<div :class="buildCellContentClass(column)">
|
|
443
|
+
{{ formatCellValue(get(row, column.field), column) }}
|
|
444
|
+
</div>
|
|
432
445
|
</template>
|
|
433
446
|
<template #empty>
|
|
434
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 (
|
|
21
|
+
/** Whether text can wrap. Default: false (truncate with ellipsis) */
|
|
20
22
|
wrap?: boolean
|
|
21
23
|
/** Text alignment. Default: 'left' */
|
|
22
24
|
align?: DataTableColumnAlign
|
|
@@ -72,6 +72,7 @@ const meta = {
|
|
|
72
72
|
columns: { control: 'object' },
|
|
73
73
|
sortMethod: { control: false },
|
|
74
74
|
showTopToolbar: { control: 'boolean' },
|
|
75
|
+
topToolbarThreshold: { control: 'number' },
|
|
75
76
|
showBottomToolbar: { control: 'boolean' },
|
|
76
77
|
pageSizeOptions: { control: 'object' },
|
|
77
78
|
showPagination: { control: 'boolean' },
|
|
@@ -85,6 +86,7 @@ const meta = {
|
|
|
85
86
|
columns,
|
|
86
87
|
sortMethod: undefined,
|
|
87
88
|
showTopToolbar: undefined,
|
|
89
|
+
topToolbarThreshold: 50,
|
|
88
90
|
showBottomToolbar: true,
|
|
89
91
|
pageSizeOptions: [ 10, 20, 50 ],
|
|
90
92
|
showPagination: true,
|
|
@@ -11,6 +11,7 @@ const props = withDefaults(defineProps<StaticDataTableProps<TData>>(), {
|
|
|
11
11
|
columns: () => [],
|
|
12
12
|
sortMethod: undefined,
|
|
13
13
|
showTopToolbar: undefined,
|
|
14
|
+
topToolbarThreshold: 50,
|
|
14
15
|
showBottomToolbar: true,
|
|
15
16
|
pageSizeOptions: () => [ 10, 20, 50, 100 ],
|
|
16
17
|
showPagination: true,
|
|
@@ -99,7 +100,7 @@ const hasPaginationData = computed(() => totalCount.value > 0)
|
|
|
99
100
|
|
|
100
101
|
const shouldShowTopToolbar = computed(() => {
|
|
101
102
|
if (props.showTopToolbar !== undefined) return props.showTopToolbar
|
|
102
|
-
return pagination.value.size >=
|
|
103
|
+
return pagination.value.size >= props.topToolbarThreshold
|
|
103
104
|
})
|
|
104
105
|
|
|
105
106
|
const shouldShowBottomToolbar = computed(() => props.showBottomToolbar)
|
|
@@ -16,8 +16,10 @@ export interface StaticDataTableProps<T = Record<string, any>> {
|
|
|
16
16
|
columns?: DataTableColumn[]
|
|
17
17
|
/** Custom sort implementation. Receives the data and the current sort state; should return sorted items. Defaults to a generic comparator on `row[sortBy]`. */
|
|
18
18
|
sortMethod?: StaticDataTableSortMethod<T>
|
|
19
|
-
/** Whether to show top toolbar (undefined = auto when page size >=
|
|
19
|
+
/** Whether to show top toolbar (undefined = auto when page size >= `topToolbarThreshold`) */
|
|
20
20
|
showTopToolbar?: boolean
|
|
21
|
+
/** Page-size threshold that triggers the top toolbar when `showTopToolbar` is undefined (default: 50) */
|
|
22
|
+
topToolbarThreshold?: number
|
|
21
23
|
/** Whether to show bottom toolbar (default: true) */
|
|
22
24
|
showBottomToolbar?: boolean
|
|
23
25
|
/** Available page size options */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
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": "4dcf9b4b5d9697cf2698778f3d2623db8cbceec9"
|
|
46
46
|
}
|