compote-ui 0.52.6 → 0.53.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/components/data-table-v8/create-table.svelte.js +3 -1
- package/dist/components/data-table-v8/data-table-foot.svelte +96 -0
- package/dist/components/data-table-v8/data-table-foot.svelte.d.ts +33 -0
- package/dist/components/data-table-v8/data-table-utils.d.ts +1 -0
- package/dist/components/data-table-v8/data-table-utils.js +25 -0
- package/dist/components/data-table-v8/data-table.svelte +16 -0
- package/dist/components/data-table-v8/types.d.ts +4 -0
- package/dist/components/data-table-v8/virtual/data-table-virtualized.svelte +23 -0
- package/package.json +1 -1
|
@@ -110,7 +110,9 @@ function createColumns(columns, localeCtx) {
|
|
|
110
110
|
type: column.type,
|
|
111
111
|
formatOptions: column.formatOptions,
|
|
112
112
|
formatLocale: column.formatLocale,
|
|
113
|
-
grow: column.grow
|
|
113
|
+
grow: column.grow,
|
|
114
|
+
sum: column.sum,
|
|
115
|
+
footer: column.footer
|
|
114
116
|
}
|
|
115
117
|
};
|
|
116
118
|
if (typeof column.accessorFn === 'function') {
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import type { Column, Row, RowData } from '@tanstack/table-core';
|
|
3
|
+
import { useLocaleContext } from '@ark-ui/svelte/locale';
|
|
4
|
+
import { cn } from 'tailwind-variants';
|
|
5
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
6
|
+
import {
|
|
7
|
+
alignClass,
|
|
8
|
+
formatColumnFooter,
|
|
9
|
+
getColumnMeta,
|
|
10
|
+
getPinningStyle,
|
|
11
|
+
justifyClass,
|
|
12
|
+
joinStyles,
|
|
13
|
+
virtualColumnSizeStyle,
|
|
14
|
+
virtualGrowColumnSizeStyle,
|
|
15
|
+
virtualSelectionColumnSizeStyle
|
|
16
|
+
} from './data-table-utils';
|
|
17
|
+
|
|
18
|
+
type Props = {
|
|
19
|
+
table: DataTableInstance<T>;
|
|
20
|
+
visibleLeafColumns: Column<T, unknown>[];
|
|
21
|
+
rows: Row<T>[];
|
|
22
|
+
isRowSelectionEnabled: boolean;
|
|
23
|
+
hasGrowColumn: boolean;
|
|
24
|
+
isVirtual?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
let {
|
|
28
|
+
table,
|
|
29
|
+
visibleLeafColumns,
|
|
30
|
+
rows,
|
|
31
|
+
isRowSelectionEnabled,
|
|
32
|
+
hasGrowColumn,
|
|
33
|
+
isVirtual = false
|
|
34
|
+
}: Props = $props();
|
|
35
|
+
|
|
36
|
+
const localeCtx = useLocaleContext();
|
|
37
|
+
const locale = $derived(localeCtx().locale);
|
|
38
|
+
|
|
39
|
+
function footCellStyle(column: Column<T, unknown>) {
|
|
40
|
+
const meta = getColumnMeta(column.columnDef);
|
|
41
|
+
if (!isVirtual) return getPinningStyle(column, table, true, isRowSelectionEnabled);
|
|
42
|
+
return joinStyles(
|
|
43
|
+
meta?.grow ? virtualGrowColumnSizeStyle() : virtualColumnSizeStyle(column.getSize()),
|
|
44
|
+
getPinningStyle(column, table, true, isRowSelectionEnabled)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function selectionCellStyle() {
|
|
49
|
+
return isVirtual
|
|
50
|
+
? joinStyles(
|
|
51
|
+
virtualSelectionColumnSizeStyle(),
|
|
52
|
+
'min-width: 40px',
|
|
53
|
+
'max-width: 40px',
|
|
54
|
+
'position: sticky',
|
|
55
|
+
'left: 0',
|
|
56
|
+
'z-index: 15'
|
|
57
|
+
)
|
|
58
|
+
: 'width: 40px; min-width: 40px; max-width: 40px; position: sticky; left: 0; z-index: 15';
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<tfoot
|
|
63
|
+
class="sticky bottom-0 z-20 bg-surface-2 text-ink-dim"
|
|
64
|
+
style={isVirtual ? 'display: grid; position: sticky; bottom: 0; z-index: 20' : undefined}
|
|
65
|
+
>
|
|
66
|
+
<tr class="h-9" style={isVirtual ? 'display: flex; width: 100%' : undefined}>
|
|
67
|
+
{#if isRowSelectionEnabled}
|
|
68
|
+
<td
|
|
69
|
+
class={cn(
|
|
70
|
+
'h-9 border-t border-surface-3 bg-surface-2 px-3 py-0',
|
|
71
|
+
isVirtual && 'flex items-center'
|
|
72
|
+
)}
|
|
73
|
+
style={selectionCellStyle()}
|
|
74
|
+
></td>
|
|
75
|
+
{/if}
|
|
76
|
+
{#each visibleLeafColumns as column (column.id)}
|
|
77
|
+
{@const meta = getColumnMeta(column.columnDef)}
|
|
78
|
+
{@const values = rows.map((row) => row.getValue(column.id))}
|
|
79
|
+
{@const footerText = formatColumnFooter(meta ?? {}, values, locale)}
|
|
80
|
+
<td
|
|
81
|
+
class={cn(
|
|
82
|
+
'h-9 truncate border-t border-surface-3 bg-surface-2 px-3 py-0 align-middle text-sm font-medium',
|
|
83
|
+
alignClass(meta?.align),
|
|
84
|
+
isVirtual && 'flex items-center',
|
|
85
|
+
isVirtual && justifyClass(meta?.align)
|
|
86
|
+
)}
|
|
87
|
+
style={footCellStyle(column)}
|
|
88
|
+
>
|
|
89
|
+
{footerText ?? ''}
|
|
90
|
+
</td>
|
|
91
|
+
{/each}
|
|
92
|
+
{#if !isVirtual && !hasGrowColumn}
|
|
93
|
+
<td aria-hidden="true" class="h-9 border-t border-surface-3 bg-surface-2 p-0"></td>
|
|
94
|
+
{/if}
|
|
95
|
+
</tr>
|
|
96
|
+
</tfoot>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Column, Row, RowData } from '@tanstack/table-core';
|
|
2
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
3
|
+
declare function $$render<T extends RowData>(): {
|
|
4
|
+
props: {
|
|
5
|
+
table: DataTableInstance<T>;
|
|
6
|
+
visibleLeafColumns: Column<T, unknown>[];
|
|
7
|
+
rows: Row<T>[];
|
|
8
|
+
isRowSelectionEnabled: boolean;
|
|
9
|
+
hasGrowColumn: boolean;
|
|
10
|
+
isVirtual?: boolean;
|
|
11
|
+
};
|
|
12
|
+
exports: {};
|
|
13
|
+
bindings: "";
|
|
14
|
+
slots: {};
|
|
15
|
+
events: {};
|
|
16
|
+
};
|
|
17
|
+
declare class __sveltets_Render<T extends RowData> {
|
|
18
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
19
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
20
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
21
|
+
bindings(): "";
|
|
22
|
+
exports(): {};
|
|
23
|
+
}
|
|
24
|
+
interface $$IsomorphicComponent {
|
|
25
|
+
new <T extends RowData>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
26
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
27
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
28
|
+
<T extends RowData>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
29
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
30
|
+
}
|
|
31
|
+
declare const DataTableFoot: $$IsomorphicComponent;
|
|
32
|
+
type DataTableFoot<T extends RowData> = InstanceType<typeof DataTableFoot<T>>;
|
|
33
|
+
export default DataTableFoot;
|
|
@@ -29,3 +29,4 @@ export declare function getColumnMeta(columnDef: {
|
|
|
29
29
|
meta?: unknown;
|
|
30
30
|
}): DataTableColumnMeta | undefined;
|
|
31
31
|
export declare function joinStyles(...styles: Array<string | undefined>): string;
|
|
32
|
+
export declare function formatColumnFooter(meta: DataTableColumnMeta, values: unknown[], locale: string): string | undefined;
|
|
@@ -133,3 +133,28 @@ export function getColumnMeta(columnDef) {
|
|
|
133
133
|
export function joinStyles(...styles) {
|
|
134
134
|
return styles.filter(Boolean).join('; ');
|
|
135
135
|
}
|
|
136
|
+
const FOOTER_SUM_FORMAT_DEFAULTS = {
|
|
137
|
+
currency: { style: 'currency', currency: 'USD' },
|
|
138
|
+
percent: { style: 'percent' },
|
|
139
|
+
number: {}
|
|
140
|
+
};
|
|
141
|
+
export function formatColumnFooter(meta, values, locale) {
|
|
142
|
+
if (meta.footer) {
|
|
143
|
+
const result = meta.footer(values);
|
|
144
|
+
if (result === null || result === undefined)
|
|
145
|
+
return undefined;
|
|
146
|
+
return String(result);
|
|
147
|
+
}
|
|
148
|
+
if (meta.sum) {
|
|
149
|
+
const sum = values.reduce((acc, val) => acc + (typeof val === 'number' ? val : Number(val) || 0), 0);
|
|
150
|
+
const numDefaults = meta.type ? FOOTER_SUM_FORMAT_DEFAULTS[meta.type] : undefined;
|
|
151
|
+
if (numDefaults !== undefined) {
|
|
152
|
+
return new Intl.NumberFormat(meta.formatLocale ?? locale, {
|
|
153
|
+
...numDefaults,
|
|
154
|
+
...meta.formatOptions
|
|
155
|
+
}).format(sum);
|
|
156
|
+
}
|
|
157
|
+
return String(sum);
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { PhArrowSquareOut, PhCheck, PhX } from '../../icons';
|
|
6
6
|
import type { DataTableInstance } from './data-table-utils';
|
|
7
7
|
import DataTableHead from './data-table-head.svelte';
|
|
8
|
+
import DataTableFoot from './data-table-foot.svelte';
|
|
8
9
|
import FlexRender from './flex-render.svelte';
|
|
9
10
|
import {
|
|
10
11
|
alignClass,
|
|
@@ -105,6 +106,12 @@
|
|
|
105
106
|
return getSelectedRowCount(table);
|
|
106
107
|
});
|
|
107
108
|
const isColumnResizing = $derived(tableState.columnSizingInfo.isResizingColumn !== false);
|
|
109
|
+
const hasFooter = $derived(
|
|
110
|
+
visibleLeafColumns.some((col) => {
|
|
111
|
+
const meta = getColumnMeta(col.columnDef);
|
|
112
|
+
return !!(meta?.sum || meta?.footer);
|
|
113
|
+
})
|
|
114
|
+
);
|
|
108
115
|
</script>
|
|
109
116
|
|
|
110
117
|
<div
|
|
@@ -244,6 +251,15 @@
|
|
|
244
251
|
</tr>
|
|
245
252
|
{/each}
|
|
246
253
|
</tbody>
|
|
254
|
+
{#if hasFooter}
|
|
255
|
+
<DataTableFoot
|
|
256
|
+
{table}
|
|
257
|
+
{visibleLeafColumns}
|
|
258
|
+
rows={rowModel.rows}
|
|
259
|
+
{isRowSelectionEnabled}
|
|
260
|
+
{hasGrowColumn}
|
|
261
|
+
/>
|
|
262
|
+
{/if}
|
|
247
263
|
</table>
|
|
248
264
|
</div>
|
|
249
265
|
|
|
@@ -33,6 +33,8 @@ export type DataTableLeafColumnBase<T extends RowData> = DataTableColumnOptions<
|
|
|
33
33
|
formatLocale?: string;
|
|
34
34
|
pinned?: 'left' | 'right';
|
|
35
35
|
grow?: boolean;
|
|
36
|
+
sum?: boolean;
|
|
37
|
+
footer?: (values: unknown[]) => string | number | undefined;
|
|
36
38
|
columns?: never;
|
|
37
39
|
};
|
|
38
40
|
export type DataTableAccessorKeyColumn<T extends RowData> = DataTableLeafColumnBase<T> & {
|
|
@@ -66,4 +68,6 @@ export type DataTableColumnMeta = {
|
|
|
66
68
|
formatOptions?: Intl.NumberFormatOptions | Intl.DateTimeFormatOptions;
|
|
67
69
|
formatLocale?: string;
|
|
68
70
|
grow?: boolean;
|
|
71
|
+
sum?: boolean;
|
|
72
|
+
footer?: (values: unknown[]) => string | number | undefined;
|
|
69
73
|
};
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
import { cn, type ClassValue } from 'tailwind-variants';
|
|
5
5
|
import type { DataTableInstance } from '../data-table-utils';
|
|
6
6
|
import DataTableHead from '../data-table-head.svelte';
|
|
7
|
+
import DataTableFoot from '../data-table-foot.svelte';
|
|
7
8
|
import DataTableVirtualRows from './data-table-virtual-rows.svelte';
|
|
8
9
|
import {
|
|
9
10
|
getAllRowsSelectionState,
|
|
11
|
+
getColumnMeta,
|
|
10
12
|
getReactiveTableState,
|
|
11
13
|
getSelectedRowCount,
|
|
12
14
|
tableSizeStyle
|
|
@@ -69,6 +71,17 @@
|
|
|
69
71
|
return getSelectedRowCount(table);
|
|
70
72
|
});
|
|
71
73
|
const isColumnResizing = $derived(tableState.columnSizingInfo.isResizingColumn !== false);
|
|
74
|
+
const visibleLeafColumns = $derived.by(() => {
|
|
75
|
+
const { columnVisibility } = getReactiveTableState(table);
|
|
76
|
+
void columnVisibility;
|
|
77
|
+
return table.getVisibleLeafColumns();
|
|
78
|
+
});
|
|
79
|
+
const hasFooter = $derived(
|
|
80
|
+
visibleLeafColumns.some((col) => {
|
|
81
|
+
const meta = getColumnMeta(col.columnDef);
|
|
82
|
+
return !!(meta?.sum || meta?.footer);
|
|
83
|
+
})
|
|
84
|
+
);
|
|
72
85
|
</script>
|
|
73
86
|
|
|
74
87
|
<div
|
|
@@ -110,6 +123,16 @@
|
|
|
110
123
|
{onRowDoubleClick}
|
|
111
124
|
/>
|
|
112
125
|
{/if}
|
|
126
|
+
{#if hasFooter}
|
|
127
|
+
<DataTableFoot
|
|
128
|
+
{table}
|
|
129
|
+
{visibleLeafColumns}
|
|
130
|
+
rows={rowModel.rows}
|
|
131
|
+
{isRowSelectionEnabled}
|
|
132
|
+
hasGrowColumn={false}
|
|
133
|
+
isVirtual
|
|
134
|
+
/>
|
|
135
|
+
{/if}
|
|
113
136
|
</table>
|
|
114
137
|
</div>
|
|
115
138
|
|