@bjj/nuxt-layer-shadcn-ui 0.16.1 → 0.17.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.
- package/app/components/ui/AsyncDataTable/index.stories.ts +43 -0
- package/app/components/ui/AsyncDataTable/index.vue +2 -0
- package/app/components/ui/AsyncDataTable/types.ts +2 -0
- package/app/components/ui/DataTable/index.stories.ts +46 -0
- package/app/components/ui/DataTable/index.vue +19 -5
- package/app/components/ui/DataTable/types.ts +2 -0
- package/app/components/ui/StaticDataTable/index.stories.ts +43 -0
- package/app/components/ui/StaticDataTable/index.vue +2 -0
- package/app/components/ui/StaticDataTable/types.ts +2 -0
- package/package.json +2 -2
|
@@ -92,6 +92,7 @@ const meta = {
|
|
|
92
92
|
showPagination: { control: 'boolean' },
|
|
93
93
|
selectable: { control: 'boolean' },
|
|
94
94
|
rowSelectable: { control: false },
|
|
95
|
+
selectOnRowClick: { control: 'boolean' },
|
|
95
96
|
clickable: { control: 'boolean' },
|
|
96
97
|
hoverable: { control: 'boolean' },
|
|
97
98
|
batchActions: { control: 'object' },
|
|
@@ -109,6 +110,7 @@ const meta = {
|
|
|
109
110
|
showPagination: true,
|
|
110
111
|
selectable: false,
|
|
111
112
|
rowSelectable: undefined,
|
|
113
|
+
selectOnRowClick: false,
|
|
112
114
|
clickable: false,
|
|
113
115
|
hoverable: true,
|
|
114
116
|
batchActions: [],
|
|
@@ -173,6 +175,47 @@ export const WithBatchActions: Story = {
|
|
|
173
175
|
}),
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
179
|
+
export const SelectOnRowClick: Story = {
|
|
180
|
+
parameters: {
|
|
181
|
+
...noControls,
|
|
182
|
+
docs: {
|
|
183
|
+
source: {
|
|
184
|
+
code: `
|
|
185
|
+
<template>
|
|
186
|
+
<AsyncDataTable
|
|
187
|
+
:columns="columns"
|
|
188
|
+
:fetchMethod="mockFetch"
|
|
189
|
+
v-model:selection="selection"
|
|
190
|
+
selectable
|
|
191
|
+
selectOnRowClick
|
|
192
|
+
/>
|
|
193
|
+
</template>
|
|
194
|
+
`.trim(),
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
render: () => ({
|
|
199
|
+
components: { AsyncDataTable },
|
|
200
|
+
setup () {
|
|
201
|
+
const selection = ref<User[]>([])
|
|
202
|
+
return { columns, mockFetch, selection }
|
|
203
|
+
},
|
|
204
|
+
template: `
|
|
205
|
+
<AsyncDataTable
|
|
206
|
+
:columns="columns"
|
|
207
|
+
:fetchMethod="mockFetch"
|
|
208
|
+
v-model:selection="selection"
|
|
209
|
+
selectable
|
|
210
|
+
selectOnRowClick
|
|
211
|
+
/>
|
|
212
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
213
|
+
Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
214
|
+
</div>
|
|
215
|
+
`,
|
|
216
|
+
}),
|
|
217
|
+
}
|
|
218
|
+
|
|
176
219
|
/** `rowSelectable` locks individual rows out of selection: their checkbox is disabled and "select all" skips them. */
|
|
177
220
|
export const DisabledRows: Story = {
|
|
178
221
|
parameters: {
|
|
@@ -18,6 +18,7 @@ const props = withDefaults(defineProps<AsyncDataTableProps<TData>>(), {
|
|
|
18
18
|
showPagination: true,
|
|
19
19
|
selectable: false,
|
|
20
20
|
rowSelectable: undefined,
|
|
21
|
+
selectOnRowClick: false,
|
|
21
22
|
clickable: false,
|
|
22
23
|
hoverable: true,
|
|
23
24
|
batchActions: () => [],
|
|
@@ -338,6 +339,7 @@ onMounted(() => {
|
|
|
338
339
|
:loading
|
|
339
340
|
:selectionMode="showSelectionColumn ? 'multiple' : undefined"
|
|
340
341
|
:rowSelectable
|
|
342
|
+
:selectOnRowClick
|
|
341
343
|
:clickable
|
|
342
344
|
:hoverable
|
|
343
345
|
:sortBy="sortState.sortBy"
|
|
@@ -46,6 +46,8 @@ export interface AsyncDataTableProps<T = Record<string, any>> {
|
|
|
46
46
|
selectable?: boolean
|
|
47
47
|
/** Per-row selection gate; `index` is relative to the current page. Rows returning false get a disabled checkbox and are skipped by "select all". */
|
|
48
48
|
rowSelectable?: DataTableRowSelectable<T>
|
|
49
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
50
|
+
selectOnRowClick?: boolean
|
|
49
51
|
/** Whether rows are clickable (shows pointer cursor and pairs with `@rowClick`) */
|
|
50
52
|
clickable?: boolean
|
|
51
53
|
/** Row hover highlight. Default: true. Turn it off where the cells hold form controls — a tinted row reads as "not editable" there. Selected and active rows keep their highlight either way. */
|
|
@@ -79,6 +79,7 @@ const meta = {
|
|
|
79
79
|
argTypes: {
|
|
80
80
|
selectionMode: { control: 'select', options: [ undefined, 'single', 'multiple' ]},
|
|
81
81
|
rowSelectable: { control: false },
|
|
82
|
+
selectOnRowClick: { control: 'boolean' },
|
|
82
83
|
loading: { control: 'boolean' },
|
|
83
84
|
clickable: { control: 'boolean' },
|
|
84
85
|
hoverable: { control: 'boolean' },
|
|
@@ -87,6 +88,7 @@ const meta = {
|
|
|
87
88
|
args: {
|
|
88
89
|
selectionMode: undefined,
|
|
89
90
|
rowSelectable: undefined,
|
|
91
|
+
selectOnRowClick: false,
|
|
90
92
|
loading: false,
|
|
91
93
|
clickable: false,
|
|
92
94
|
hoverable: true,
|
|
@@ -530,6 +532,50 @@ export const DisabledRows: Story = {
|
|
|
530
532
|
}),
|
|
531
533
|
}
|
|
532
534
|
|
|
535
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
536
|
+
export const SelectOnRowClick: Story = {
|
|
537
|
+
parameters: {
|
|
538
|
+
...noControls,
|
|
539
|
+
docs: {
|
|
540
|
+
source: {
|
|
541
|
+
code: `
|
|
542
|
+
<template>
|
|
543
|
+
<DataTable
|
|
544
|
+
:data="data"
|
|
545
|
+
:columns="columns"
|
|
546
|
+
selectionMode="multiple"
|
|
547
|
+
selectOnRowClick
|
|
548
|
+
v-model:selection="selection"
|
|
549
|
+
/>
|
|
550
|
+
</template>
|
|
551
|
+
`.trim(),
|
|
552
|
+
},
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
render: () => ({
|
|
556
|
+
components: { DataTable: DataTable as any },
|
|
557
|
+
setup () {
|
|
558
|
+
const selection = ref<User[]>([])
|
|
559
|
+
return { data: sampleData, basicColumns, selection }
|
|
560
|
+
},
|
|
561
|
+
template: `
|
|
562
|
+
<div class="w-full">
|
|
563
|
+
<DataTable
|
|
564
|
+
:data="data"
|
|
565
|
+
:columns="basicColumns"
|
|
566
|
+
selectionMode="multiple"
|
|
567
|
+
selectOnRowClick
|
|
568
|
+
v-model:selection="selection"
|
|
569
|
+
/>
|
|
570
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
571
|
+
Click anywhere on a row — Selected:
|
|
572
|
+
{{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
573
|
+
</div>
|
|
574
|
+
</div>
|
|
575
|
+
`,
|
|
576
|
+
}),
|
|
577
|
+
}
|
|
578
|
+
|
|
533
579
|
export const FrozenColumns: Story = {
|
|
534
580
|
parameters: {
|
|
535
581
|
...noControls,
|
|
@@ -23,6 +23,7 @@ const props = withDefaults(defineProps<DataTableProps<TData>>(), {
|
|
|
23
23
|
columns: () => [],
|
|
24
24
|
selectionMode: undefined,
|
|
25
25
|
rowSelectable: undefined,
|
|
26
|
+
selectOnRowClick: false,
|
|
26
27
|
sortBy: undefined,
|
|
27
28
|
sortOrder: undefined,
|
|
28
29
|
loading: false,
|
|
@@ -100,9 +101,12 @@ function isRowSelected (row: TData): boolean {
|
|
|
100
101
|
return toRaw(selection.value) === toRaw(row)
|
|
101
102
|
}
|
|
102
103
|
|
|
103
|
-
//
|
|
104
|
+
// Whether a click on the row body toggles the row's selection.
|
|
105
|
+
const rowClickSelects = computed(() => showSelectionColumn.value && props.selectOnRowClick)
|
|
106
|
+
|
|
107
|
+
// Both row-click selection and the `clickable` contract make a row respond to a click.
|
|
104
108
|
function isRowClickable (row: TData, index: number): boolean {
|
|
105
|
-
return props.clickable || (
|
|
109
|
+
return props.clickable || (rowClickSelects.value && isRowSelectable(row, index))
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
function isRowActive (row: TData): boolean {
|
|
@@ -124,7 +128,13 @@ function toggleRow (row: TData, index: number) {
|
|
|
124
128
|
|
|
125
129
|
function onRowClick (row: TData, index: number, event: MouseEvent) {
|
|
126
130
|
emit('rowClick', row, index, event)
|
|
127
|
-
if (
|
|
131
|
+
if (rowClickSelects.value) toggleRow(row, index)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// The whole selection cell is the hit target, not just the 16px checkbox.
|
|
135
|
+
// A click on the checkbox itself is already handled by its own update event.
|
|
136
|
+
function onSelectionCellClick (row: TData, index: number, event: MouseEvent) {
|
|
137
|
+
if (event.target === event.currentTarget) toggleRow(row, index)
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
// -- Sorting --
|
|
@@ -440,10 +450,14 @@ defineExpose({
|
|
|
440
450
|
<!-- Selection cell: stop click to prevent double toggle with row click -->
|
|
441
451
|
<TableCell
|
|
442
452
|
v-if="showSelectionColumn"
|
|
443
|
-
:class="cn(
|
|
453
|
+
:class="cn(
|
|
454
|
+
stickyLeftClass,
|
|
455
|
+
selectionColumnClass,
|
|
456
|
+
isRowSelectable(row, index) && 'cursor-pointer',
|
|
457
|
+
)"
|
|
444
458
|
:style="selectionColumnStyle"
|
|
445
459
|
:data-shadow="selectionColumnShadowDir"
|
|
446
|
-
@click.stop
|
|
460
|
+
@click.stop="onSelectionCellClick(row, index, $event)"
|
|
447
461
|
>
|
|
448
462
|
<Checkbox
|
|
449
463
|
:modelValue="isRowSelected(row)"
|
|
@@ -46,6 +46,8 @@ export interface DataTableProps<T = Record<string, any>> {
|
|
|
46
46
|
selectionMode?: DataTableSelectionMode
|
|
47
47
|
/** Per-row selection gate. Rows returning false get a disabled checkbox and ignore row-click selection; a selection they already hold is left untouched. */
|
|
48
48
|
rowSelectable?: DataTableRowSelectable<T>
|
|
49
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
50
|
+
selectOnRowClick?: boolean
|
|
49
51
|
/** Row to highlight as active. Independent from selection; uses the same highlight style. */
|
|
50
52
|
active?: T | null
|
|
51
53
|
/** Current sort field */
|
|
@@ -78,6 +78,7 @@ const meta = {
|
|
|
78
78
|
showPagination: { control: 'boolean' },
|
|
79
79
|
selectable: { control: 'boolean' },
|
|
80
80
|
rowSelectable: { control: false },
|
|
81
|
+
selectOnRowClick: { control: 'boolean' },
|
|
81
82
|
clickable: { control: 'boolean' },
|
|
82
83
|
hoverable: { control: 'boolean' },
|
|
83
84
|
batchActions: { control: 'object' },
|
|
@@ -94,6 +95,7 @@ const meta = {
|
|
|
94
95
|
showPagination: true,
|
|
95
96
|
selectable: false,
|
|
96
97
|
rowSelectable: undefined,
|
|
98
|
+
selectOnRowClick: false,
|
|
97
99
|
clickable: false,
|
|
98
100
|
hoverable: true,
|
|
99
101
|
batchActions: [],
|
|
@@ -155,6 +157,47 @@ export const WithBatchActions: Story = {
|
|
|
155
157
|
}),
|
|
156
158
|
}
|
|
157
159
|
|
|
160
|
+
/** `selectOnRowClick` lets a click anywhere on a row toggle its selection, not just the checkbox cell. */
|
|
161
|
+
export const SelectOnRowClick: Story = {
|
|
162
|
+
parameters: {
|
|
163
|
+
...noControls,
|
|
164
|
+
docs: {
|
|
165
|
+
source: {
|
|
166
|
+
code: `
|
|
167
|
+
<template>
|
|
168
|
+
<StaticDataTable
|
|
169
|
+
:data="users"
|
|
170
|
+
:columns="columns"
|
|
171
|
+
v-model:selection="selection"
|
|
172
|
+
selectable
|
|
173
|
+
selectOnRowClick
|
|
174
|
+
/>
|
|
175
|
+
</template>
|
|
176
|
+
`.trim(),
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
render: () => ({
|
|
181
|
+
components: { StaticDataTable },
|
|
182
|
+
setup () {
|
|
183
|
+
const selection = ref<User[]>([])
|
|
184
|
+
return { users: allUsers, columns, selection }
|
|
185
|
+
},
|
|
186
|
+
template: `
|
|
187
|
+
<StaticDataTable
|
|
188
|
+
:data="users"
|
|
189
|
+
:columns="columns"
|
|
190
|
+
v-model:selection="selection"
|
|
191
|
+
selectable
|
|
192
|
+
selectOnRowClick
|
|
193
|
+
/>
|
|
194
|
+
<div class="mt-2 text-sm text-muted-foreground">
|
|
195
|
+
Selected: {{ selection.length > 0 ? selection.map(r => r.name).join(', ') : 'none' }}
|
|
196
|
+
</div>
|
|
197
|
+
`,
|
|
198
|
+
}),
|
|
199
|
+
}
|
|
200
|
+
|
|
158
201
|
/** `rowSelectable` locks individual rows out of selection: their checkbox is disabled and "select all" skips them. */
|
|
159
202
|
export const DisabledRows: Story = {
|
|
160
203
|
parameters: {
|
|
@@ -17,6 +17,7 @@ const props = withDefaults(defineProps<StaticDataTableProps<TData>>(), {
|
|
|
17
17
|
showPagination: true,
|
|
18
18
|
selectable: false,
|
|
19
19
|
rowSelectable: undefined,
|
|
20
|
+
selectOnRowClick: false,
|
|
20
21
|
clickable: false,
|
|
21
22
|
hoverable: true,
|
|
22
23
|
batchActions: () => [],
|
|
@@ -205,6 +206,7 @@ function onSortOrderUpdate (value: number | null) {
|
|
|
205
206
|
:columns="columns"
|
|
206
207
|
:selectionMode="showSelectionColumn ? 'multiple' : undefined"
|
|
207
208
|
:rowSelectable="rowSelectable"
|
|
209
|
+
:selectOnRowClick="selectOnRowClick"
|
|
208
210
|
:clickable="clickable"
|
|
209
211
|
:hoverable="hoverable"
|
|
210
212
|
:sortBy="sortState.sortBy"
|
|
@@ -30,6 +30,8 @@ export interface StaticDataTableProps<T = Record<string, any>> {
|
|
|
30
30
|
selectable?: boolean
|
|
31
31
|
/** Per-row selection gate; `index` is relative to the current page. Rows returning false get a disabled checkbox and are skipped by "select all". */
|
|
32
32
|
rowSelectable?: DataTableRowSelectable<T>
|
|
33
|
+
/** Whether clicking anywhere on a row toggles its selection. Default: false — selection toggles only from the selection cell, leaving row clicks to `@rowClick`. */
|
|
34
|
+
selectOnRowClick?: boolean
|
|
33
35
|
/** Whether rows are clickable (shows pointer cursor and pairs with `@rowClick`) */
|
|
34
36
|
clickable?: boolean
|
|
35
37
|
/** Row hover highlight. Default: true. Turn it off where the cells hold form controls — a tinted row reads as "not editable" there. Selected and active rows keep their highlight either way. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bjj/nuxt-layer-shadcn-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
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": "baefb8dd7a1d57a9a3b34fe53bda45a845153b2c"
|
|
46
46
|
}
|