@aleph-alpha/ui-library 2.2.0 → 2.3.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/dist/system/components/UiToggle/UiToggle.vue.d.ts +5 -0
- package/dist/system/components/UiToggle/types.d.ts +13 -0
- package/dist/system/lib/heightTransition.d.ts +5 -0
- package/dist/system/lib/useDrag.d.ts +52 -0
- package/dist/system/lib.js +16727 -16225
- package/dist/system/patterns/UiDataTable/UiDataTable.vue.d.ts +22 -3
- package/dist/system/patterns/UiDataTable/UiDataTableColumnFilter.vue.d.ts +14 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +13 -0
- package/dist/system/patterns/UiDataTable/index.d.ts +2 -0
- package/dist/system/patterns/UiDataTable/types.d.ts +32 -1
- package/package.json +1 -1
- package/src/components/UiTable/__tests__/UiTableRow.test.ts +14 -5
- package/src/components/UiToggle/UiToggle.vue +18 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +33 -3
- package/src/components/UiToggle/types.ts +13 -0
- package/src/components/core/accordion/AccordionContent.vue +36 -1
- package/src/components/core/table/TableRow.vue +1 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/lib/heightTransition.ts +27 -0
- package/src/lib/useDrag.stories.ts +295 -0
- package/src/lib/useDrag.ts +212 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +348 -0
- package/src/patterns/UiDataTable/UiDataTable.vue +558 -22
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +83 -0
- package/src/patterns/UiDataTable/UiDataTableColumnHeader.vue +4 -13
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +329 -0
- package/src/patterns/UiDataTable/__tests__/UiDataTableColumnFilter.test.ts +194 -0
- package/src/patterns/UiDataTable/__tests__/UiDataTableColumnHeader.test.ts +11 -0
- package/src/patterns/UiDataTable/constants.ts +15 -0
- package/src/patterns/UiDataTable/index.ts +2 -0
- package/src/patterns/UiDataTable/types.ts +33 -0
- package/src/patterns/UiSidebar/UiSidebarGroupContent.vue +13 -36
|
@@ -3,6 +3,7 @@ import type { ColumnDef } from '@tanstack/vue-table';
|
|
|
3
3
|
import { computed, h, ref } from 'vue';
|
|
4
4
|
import {
|
|
5
5
|
UiDataTable,
|
|
6
|
+
UiDataTableColumnFilter,
|
|
6
7
|
UiDataTableColumnHeader,
|
|
7
8
|
UiDataTablePagination,
|
|
8
9
|
UiDataTableToolbar,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
import { UiCheckbox } from '@/components/UiCheckbox';
|
|
11
12
|
import { UiButton } from '@/components/UiButton';
|
|
12
13
|
import { UiIcon } from '@/components/UiIcon';
|
|
14
|
+
import { UiInput } from '@/components/UiInput';
|
|
13
15
|
import {
|
|
14
16
|
UiDropdownMenu,
|
|
15
17
|
UiDropdownMenuContent,
|
|
@@ -383,6 +385,63 @@ const table = computed(() => tableRef.value?.table);
|
|
|
383
385
|
</div>
|
|
384
386
|
</template>`;
|
|
385
387
|
|
|
388
|
+
const WithColumnsFilterTemplateSource = `<script setup lang="ts">
|
|
389
|
+
import { computed, h, ref } from 'vue';
|
|
390
|
+
import { UiDataTable, UiDataTableColumnFilter, UiDataTableColumnHeader, UiInput } from '@aleph-alpha/ui-library';
|
|
391
|
+
import type { ColumnDef } from '@tanstack/vue-table';
|
|
392
|
+
|
|
393
|
+
interface Payment {
|
|
394
|
+
id: string;
|
|
395
|
+
amount: number;
|
|
396
|
+
status: string;
|
|
397
|
+
email: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const data: Payment[] = [
|
|
401
|
+
{ id: '1', amount: 316, status: 'success', email: 'ken99@yahoo.com' },
|
|
402
|
+
{ id: '2', amount: 242, status: 'success', email: 'abe45@gmail.com' },
|
|
403
|
+
{ id: '3', amount: 837, status: 'processing', email: 'monserrat44@gmail.com' },
|
|
404
|
+
];
|
|
405
|
+
|
|
406
|
+
const columns: ColumnDef<Payment>[] = [
|
|
407
|
+
{
|
|
408
|
+
accessorKey: 'status',
|
|
409
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Status' }),
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
accessorKey: 'email',
|
|
413
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Email' }),
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
accessorKey: 'amount',
|
|
417
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Amount' }),
|
|
418
|
+
},
|
|
419
|
+
];
|
|
420
|
+
|
|
421
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
422
|
+
const table = computed(() => tableRef.value?.table);
|
|
423
|
+
const emailFilter = computed({
|
|
424
|
+
get: () => (table.value?.getColumn('email')?.getFilterValue() as string) ?? '',
|
|
425
|
+
set: (value) => table.value?.getColumn('email')?.setFilterValue(value),
|
|
426
|
+
});
|
|
427
|
+
</script>
|
|
428
|
+
|
|
429
|
+
<template>
|
|
430
|
+
<div class="space-y-4">
|
|
431
|
+
<div class="flex items-center justify-between gap-2">
|
|
432
|
+
<UiInput
|
|
433
|
+
v-model="emailFilter"
|
|
434
|
+
name="email-filter"
|
|
435
|
+
placeholder="Filter emails..."
|
|
436
|
+
aria-label="Filter emails"
|
|
437
|
+
class="h-8 max-w-sm"
|
|
438
|
+
/>
|
|
439
|
+
<UiDataTableColumnFilter v-if="table" :table="table" />
|
|
440
|
+
</div>
|
|
441
|
+
<UiDataTable ref="tableRef" :data="data" :columns="columns" />
|
|
442
|
+
</div>
|
|
443
|
+
</template>`;
|
|
444
|
+
|
|
386
445
|
const fullExampleTemplateSource = `<script setup lang="ts">
|
|
387
446
|
import { h, ref, computed } from 'vue';
|
|
388
447
|
import {
|
|
@@ -583,6 +642,158 @@ const table = computed(() => tableRef.value?.table);
|
|
|
583
642
|
</div>
|
|
584
643
|
</template>`;
|
|
585
644
|
|
|
645
|
+
const withDraggableColumnsTemplateSource = `<script setup lang="ts">
|
|
646
|
+
import { h, ref } from 'vue';
|
|
647
|
+
import { UiDataTable, UiDataTableColumnHeader } from '@aleph-alpha/ui-library';
|
|
648
|
+
import type { ColumnDef } from '@tanstack/vue-table';
|
|
649
|
+
|
|
650
|
+
interface Payment {
|
|
651
|
+
id: string;
|
|
652
|
+
amount: number;
|
|
653
|
+
status: string;
|
|
654
|
+
email: string;
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
const data: Payment[] = [
|
|
658
|
+
{ id: '1', amount: 316, status: 'success', email: 'ken99@yahoo.com' },
|
|
659
|
+
{ id: '2', amount: 242, status: 'success', email: 'abe45@gmail.com' },
|
|
660
|
+
{ id: '3', amount: 837, status: 'processing', email: 'monserrat44@gmail.com' },
|
|
661
|
+
];
|
|
662
|
+
|
|
663
|
+
const columns: ColumnDef<Payment>[] = [
|
|
664
|
+
{
|
|
665
|
+
accessorKey: 'status',
|
|
666
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Status' }),
|
|
667
|
+
size: 120,
|
|
668
|
+
},
|
|
669
|
+
{
|
|
670
|
+
accessorKey: 'email',
|
|
671
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Email' }),
|
|
672
|
+
size: 250,
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
accessorKey: 'amount',
|
|
676
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Amount' }),
|
|
677
|
+
size: 120,
|
|
678
|
+
},
|
|
679
|
+
];
|
|
680
|
+
|
|
681
|
+
const columnOrder = ref<string[]>([]);
|
|
682
|
+
|
|
683
|
+
function handleColumnOrderChange(nextOrder: string[]) {
|
|
684
|
+
columnOrder.value = nextOrder;
|
|
685
|
+
}
|
|
686
|
+
</script>
|
|
687
|
+
|
|
688
|
+
<template>
|
|
689
|
+
<div class="space-y-3">
|
|
690
|
+
<UiDataTable
|
|
691
|
+
:data="data"
|
|
692
|
+
:columns="columns"
|
|
693
|
+
draggable-columns
|
|
694
|
+
:on-column-order-change="handleColumnOrderChange"
|
|
695
|
+
/>
|
|
696
|
+
<p class="text-muted-foreground text-sm">
|
|
697
|
+
Drag a column header to reorder columns.
|
|
698
|
+
<span v-if="columnOrder.length">
|
|
699
|
+
Current order: {{ columnOrder.join(', ') }}
|
|
700
|
+
</span>
|
|
701
|
+
</p>
|
|
702
|
+
</div>
|
|
703
|
+
</template>`;
|
|
704
|
+
|
|
705
|
+
const expandableColumns: ColumnDef<Payment>[] = [
|
|
706
|
+
...sortableColumns,
|
|
707
|
+
{
|
|
708
|
+
id: 'expand',
|
|
709
|
+
header: () => h('span', { class: 'sr-only' }, 'Expand row'),
|
|
710
|
+
cell: ({ row }) =>
|
|
711
|
+
h(
|
|
712
|
+
UiButton,
|
|
713
|
+
{
|
|
714
|
+
variant: 'ghost',
|
|
715
|
+
size: 'icon',
|
|
716
|
+
class: 'h-8 w-8',
|
|
717
|
+
'aria-expanded': row.getIsExpanded(),
|
|
718
|
+
'aria-label': row.getIsExpanded() ? 'Collapse row' : 'Expand row',
|
|
719
|
+
onClick: () => row.toggleExpanded(),
|
|
720
|
+
},
|
|
721
|
+
() =>
|
|
722
|
+
h(UiIcon, {
|
|
723
|
+
name: row.getIsExpanded() ? 'chevron-down' : 'chevron-right',
|
|
724
|
+
size: 16,
|
|
725
|
+
'aria-hidden': true,
|
|
726
|
+
}),
|
|
727
|
+
),
|
|
728
|
+
enableSorting: false,
|
|
729
|
+
enableHiding: false,
|
|
730
|
+
size: 48,
|
|
731
|
+
},
|
|
732
|
+
];
|
|
733
|
+
|
|
734
|
+
const withExpandableRowsTemplateSource = `<script setup lang="ts">
|
|
735
|
+
import { h } from 'vue';
|
|
736
|
+
import { UiButton, UiDataTable, UiDataTableColumnHeader, UiIcon } from '@aleph-alpha/ui-library';
|
|
737
|
+
import type { ColumnDef } from '@tanstack/vue-table';
|
|
738
|
+
|
|
739
|
+
interface Payment {
|
|
740
|
+
id: string;
|
|
741
|
+
amount: number;
|
|
742
|
+
status: string;
|
|
743
|
+
email: string;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
const data: Payment[] = [
|
|
747
|
+
{ id: '1', amount: 316, status: 'success', email: 'ken99@yahoo.com' },
|
|
748
|
+
{ id: '2', amount: 242, status: 'success', email: 'abe45@gmail.com' },
|
|
749
|
+
{ id: '3', amount: 837, status: 'processing', email: 'monserrat44@gmail.com' },
|
|
750
|
+
];
|
|
751
|
+
|
|
752
|
+
const columns: ColumnDef<Payment>[] = [
|
|
753
|
+
{
|
|
754
|
+
accessorKey: 'status',
|
|
755
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Status' }),
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
accessorKey: 'email',
|
|
759
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Email' }),
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
accessorKey: 'amount',
|
|
763
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Amount' }),
|
|
764
|
+
},
|
|
765
|
+
{
|
|
766
|
+
id: 'expand',
|
|
767
|
+
header: () => h('span', { class: 'sr-only' }, 'Expand row'),
|
|
768
|
+
cell: ({ row }) => h(UiButton, {
|
|
769
|
+
variant: 'ghost',
|
|
770
|
+
size: 'icon',
|
|
771
|
+
class: 'h-8 w-8',
|
|
772
|
+
'aria-expanded': row.getIsExpanded(),
|
|
773
|
+
'aria-label': row.getIsExpanded() ? 'Collapse row' : 'Expand row',
|
|
774
|
+
onClick: () => row.toggleExpanded(),
|
|
775
|
+
}, () => h(UiIcon, {
|
|
776
|
+
name: row.getIsExpanded() ? 'chevron-down' : 'chevron-right',
|
|
777
|
+
size: 16,
|
|
778
|
+
'aria-hidden': true,
|
|
779
|
+
})),
|
|
780
|
+
enableSorting: false,
|
|
781
|
+
enableHiding: false,
|
|
782
|
+
size: 48,
|
|
783
|
+
},
|
|
784
|
+
];
|
|
785
|
+
</script>
|
|
786
|
+
|
|
787
|
+
<template>
|
|
788
|
+
<UiDataTable :data="data" :columns="columns" :get-row-can-expand="() => true">
|
|
789
|
+
<template #expanded-row="{ row }">
|
|
790
|
+
<div class="rounded-md bg-background-surface-muted p-4 text-sm">
|
|
791
|
+
Payment {{ row.original.id }} belongs to {{ row.original.email }}.
|
|
792
|
+
</div>
|
|
793
|
+
</template>
|
|
794
|
+
</UiDataTable>
|
|
795
|
+
</template>`;
|
|
796
|
+
|
|
586
797
|
const customEmptyStateTemplateSource = `<script setup lang="ts">
|
|
587
798
|
import { UiDataTable } from '@aleph-alpha/ui-library';
|
|
588
799
|
import type { ColumnDef } from '@tanstack/vue-table';
|
|
@@ -801,6 +1012,55 @@ export const WithToolbar: Story = {
|
|
|
801
1012
|
}),
|
|
802
1013
|
};
|
|
803
1014
|
|
|
1015
|
+
/**
|
|
1016
|
+
* Table header controls with a focused email filter and a column visibility menu.
|
|
1017
|
+
*
|
|
1018
|
+
* Use `UiDataTableColumnFilter` with a table instance to show/hide hideable
|
|
1019
|
+
* columns from a checklist dropdown.
|
|
1020
|
+
*/
|
|
1021
|
+
export const WithColumnsFilter: Story = {
|
|
1022
|
+
args: {
|
|
1023
|
+
data: payments,
|
|
1024
|
+
columns: sortableColumns,
|
|
1025
|
+
},
|
|
1026
|
+
parameters: {
|
|
1027
|
+
docs: {
|
|
1028
|
+
source: {
|
|
1029
|
+
code: WithColumnsFilterTemplateSource,
|
|
1030
|
+
},
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
render: (args) => ({
|
|
1034
|
+
components: { UiDataTable, UiDataTableColumnFilter, UiInput },
|
|
1035
|
+
setup() {
|
|
1036
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
1037
|
+
const table = computed(() => tableRef.value?.table);
|
|
1038
|
+
const emailFilter = computed({
|
|
1039
|
+
get: () =>
|
|
1040
|
+
(table.value?.getColumn('email')?.getFilterValue() as string) ?? '',
|
|
1041
|
+
set: (value) => table.value?.getColumn('email')?.setFilterValue(value),
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
return { args, emailFilter, table, tableRef };
|
|
1045
|
+
},
|
|
1046
|
+
template: `
|
|
1047
|
+
<div class="space-y-4">
|
|
1048
|
+
<div class="flex items-center justify-between gap-2">
|
|
1049
|
+
<UiInput
|
|
1050
|
+
v-model="emailFilter"
|
|
1051
|
+
name="email-filter"
|
|
1052
|
+
placeholder="Filter emails..."
|
|
1053
|
+
aria-label="Filter emails"
|
|
1054
|
+
class="h-8 max-w-sm"
|
|
1055
|
+
/>
|
|
1056
|
+
<UiDataTableColumnFilter v-if="table" :table="table" />
|
|
1057
|
+
</div>
|
|
1058
|
+
<UiDataTable ref="tableRef" v-bind="args" />
|
|
1059
|
+
</div>
|
|
1060
|
+
`,
|
|
1061
|
+
}),
|
|
1062
|
+
};
|
|
1063
|
+
|
|
804
1064
|
/**
|
|
805
1065
|
* Table with global search across all columns.
|
|
806
1066
|
*
|
|
@@ -879,6 +1139,94 @@ export const WithRowSelection: Story = {
|
|
|
879
1139
|
}),
|
|
880
1140
|
};
|
|
881
1141
|
|
|
1142
|
+
/**
|
|
1143
|
+
* Table with draggable columns.
|
|
1144
|
+
*
|
|
1145
|
+
* Enable `draggable-columns` to let users reorder columns by dragging header cells.
|
|
1146
|
+
* The drag-and-drop helpers are exported from the UiDataTable module for reuse in
|
|
1147
|
+
* custom table interactions.
|
|
1148
|
+
*/
|
|
1149
|
+
export const WithDraggableColumns: Story = {
|
|
1150
|
+
args: {
|
|
1151
|
+
data: payments,
|
|
1152
|
+
columns: sortableColumns,
|
|
1153
|
+
draggableColumns: true,
|
|
1154
|
+
},
|
|
1155
|
+
parameters: {
|
|
1156
|
+
docs: {
|
|
1157
|
+
source: {
|
|
1158
|
+
code: withDraggableColumnsTemplateSource,
|
|
1159
|
+
},
|
|
1160
|
+
},
|
|
1161
|
+
},
|
|
1162
|
+
render: (args) => ({
|
|
1163
|
+
components: { UiDataTable },
|
|
1164
|
+
setup() {
|
|
1165
|
+
const columnOrder = ref<string[]>([]);
|
|
1166
|
+
return {
|
|
1167
|
+
args,
|
|
1168
|
+
columnOrder,
|
|
1169
|
+
handleColumnOrderChange: (nextOrder: string[]) => {
|
|
1170
|
+
columnOrder.value = nextOrder;
|
|
1171
|
+
},
|
|
1172
|
+
};
|
|
1173
|
+
},
|
|
1174
|
+
template: `
|
|
1175
|
+
<div class="space-y-3">
|
|
1176
|
+
<UiDataTable
|
|
1177
|
+
v-bind="args"
|
|
1178
|
+
:on-column-order-change="handleColumnOrderChange"
|
|
1179
|
+
/>
|
|
1180
|
+
<p class="text-muted-foreground text-sm">
|
|
1181
|
+
Drag a column header to reorder columns.
|
|
1182
|
+
<span v-if="columnOrder.length">
|
|
1183
|
+
Current order: {{ columnOrder.join(', ') }}
|
|
1184
|
+
</span>
|
|
1185
|
+
</p>
|
|
1186
|
+
</div>
|
|
1187
|
+
`,
|
|
1188
|
+
}),
|
|
1189
|
+
};
|
|
1190
|
+
|
|
1191
|
+
/**
|
|
1192
|
+
* Table with expandable rows.
|
|
1193
|
+
*
|
|
1194
|
+
* The expanded content is rendered in its own table row via the `expanded-row`
|
|
1195
|
+
* slot, keeping the table structure valid for screen readers and browsers.
|
|
1196
|
+
*/
|
|
1197
|
+
export const WithExpandableRows: Story = {
|
|
1198
|
+
args: {
|
|
1199
|
+
data: payments,
|
|
1200
|
+
columns: expandableColumns,
|
|
1201
|
+
getRowCanExpand: () => true,
|
|
1202
|
+
},
|
|
1203
|
+
parameters: {
|
|
1204
|
+
docs: {
|
|
1205
|
+
source: {
|
|
1206
|
+
code: withExpandableRowsTemplateSource,
|
|
1207
|
+
},
|
|
1208
|
+
},
|
|
1209
|
+
},
|
|
1210
|
+
render: (args) => ({
|
|
1211
|
+
components: { UiDataTable },
|
|
1212
|
+
setup() {
|
|
1213
|
+
return { args };
|
|
1214
|
+
},
|
|
1215
|
+
template: `
|
|
1216
|
+
<UiDataTable v-bind="args">
|
|
1217
|
+
<template #expanded-row="{ row }">
|
|
1218
|
+
<div class="rounded-md bg-background-surface-muted p-4 text-sm">
|
|
1219
|
+
<p class="font-medium">Payment {{ row.original.id }}</p>
|
|
1220
|
+
<p class="text-muted-foreground">
|
|
1221
|
+
Customer: {{ row.original.email }} - Status: {{ row.original.status }}
|
|
1222
|
+
</p>
|
|
1223
|
+
</div>
|
|
1224
|
+
</template>
|
|
1225
|
+
</UiDataTable>
|
|
1226
|
+
`,
|
|
1227
|
+
}),
|
|
1228
|
+
};
|
|
1229
|
+
|
|
882
1230
|
/**
|
|
883
1231
|
* Complete example combining all DataTable features.
|
|
884
1232
|
*
|