compote-ui 0.35.1 → 0.36.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.
|
@@ -6,6 +6,8 @@ declare const dataTableFeatures: {
|
|
|
6
6
|
columnResizingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnResizingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
7
7
|
columnFilteringFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFilteringFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
8
8
|
columnFacetingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFacetingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
9
|
+
columnPinningFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnPinningFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
10
|
+
columnOrderingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnOrderingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
9
11
|
rowSelectionFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSelectionFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
10
12
|
rowSortingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSortingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
11
13
|
};
|
|
@@ -31,6 +33,8 @@ export declare function createTable<T extends RowData>(options: CreateDataTableO
|
|
|
31
33
|
columnResizingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnResizingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
32
34
|
columnFilteringFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFilteringFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
33
35
|
columnFacetingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnFacetingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
36
|
+
columnPinningFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnPinningFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
37
|
+
columnOrderingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").ColumnOrderingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
34
38
|
rowSelectionFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSelectionFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
35
39
|
rowSortingFeature: import("@tanstack/table-core").TableFeature<import("@tanstack/table-core").RowSortingFeatureConstructors<import("@tanstack/table-core").TableFeatures, RowData>>;
|
|
36
40
|
}, T, DataTableSelectedState>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { columnVisibilityFeature, columnResizingFeature, columnSizingFeature, columnFilteringFeature, columnFacetingFeature, createSortedRowModel, createFilteredRowModel, createFacetedRowModel, createFacetedMinMaxValues, createFacetedUniqueValues, createTable as createTanStackTable, filterFns, renderComponent, renderSnippet, rowSelectionFeature, rowSortingFeature, sortFns, tableFeatures } from '@tanstack/svelte-table';
|
|
1
|
+
import { columnVisibilityFeature, columnResizingFeature, columnSizingFeature, columnFilteringFeature, columnFacetingFeature, columnPinningFeature, columnOrderingFeature, createSortedRowModel, createFilteredRowModel, createFacetedRowModel, createFacetedMinMaxValues, createFacetedUniqueValues, createTable as createTanStackTable, filterFns, renderComponent, renderSnippet, rowSelectionFeature, rowSortingFeature, sortFns, tableFeatures } from '@tanstack/svelte-table';
|
|
2
2
|
import { useLocaleContext } from '@ark-ui/svelte/locale';
|
|
3
3
|
const dataTableFeatures = tableFeatures({
|
|
4
4
|
columnVisibilityFeature,
|
|
@@ -6,6 +6,8 @@ const dataTableFeatures = tableFeatures({
|
|
|
6
6
|
columnResizingFeature,
|
|
7
7
|
columnFilteringFeature,
|
|
8
8
|
columnFacetingFeature,
|
|
9
|
+
columnPinningFeature,
|
|
10
|
+
columnOrderingFeature,
|
|
9
11
|
rowSelectionFeature,
|
|
10
12
|
rowSortingFeature
|
|
11
13
|
});
|
|
@@ -39,6 +41,7 @@ export function createTable(options) {
|
|
|
39
41
|
initialState: {
|
|
40
42
|
columnVisibility: createColumnVisibility(options.columns),
|
|
41
43
|
columnSizing: createColumnSizing(options.columns),
|
|
44
|
+
columnPinning: createColumnPinning(options.columns),
|
|
42
45
|
rowSelection: options.initialRowSelection ?? {},
|
|
43
46
|
sorting: options.initialSorting ?? [],
|
|
44
47
|
columnFilters: options.initialColumnFilters ?? []
|
|
@@ -66,6 +69,13 @@ function createColumnSizing(columns) {
|
|
|
66
69
|
return sizes;
|
|
67
70
|
}, {});
|
|
68
71
|
}
|
|
72
|
+
function createColumnPinning(columns) {
|
|
73
|
+
const leafCols = getLeafColumns(columns);
|
|
74
|
+
return {
|
|
75
|
+
left: leafCols.filter((c) => c.pinned === 'left').map(getColumnId),
|
|
76
|
+
right: leafCols.filter((c) => c.pinned === 'right').map(getColumnId)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
69
79
|
function createColumns(columns, localeCtx) {
|
|
70
80
|
return columns.map((column) => {
|
|
71
81
|
if (isGroupColumn(column)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends RowData">
|
|
2
2
|
import { FlexRender } from '@tanstack/svelte-table';
|
|
3
|
-
import type { CellData, Header, RowData } from '@tanstack/svelte-table';
|
|
3
|
+
import type { CellData, ColumnPinningPosition, Header, RowData } from '@tanstack/svelte-table';
|
|
4
4
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
5
|
import { cn, type ClassValue } from 'tailwind-variants';
|
|
6
6
|
import { PhArrowSquareOut, PhCaretDown, PhCaretUp, PhCheck, PhX } from '../../icons';
|
|
@@ -110,6 +110,44 @@
|
|
|
110
110
|
return undefined;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// type PinPosition = 'center' | false | 'left' | 'right';
|
|
114
|
+
function getPinningStyle(
|
|
115
|
+
column: {
|
|
116
|
+
getIsPinned(): ColumnPinningPosition;
|
|
117
|
+
getStart(position?: ColumnPinningPosition): number;
|
|
118
|
+
getAfter(position?: ColumnPinningPosition): number;
|
|
119
|
+
getIsLastColumn(position?: ColumnPinningPosition): boolean;
|
|
120
|
+
getIsFirstColumn(position?: ColumnPinningPosition): boolean;
|
|
121
|
+
},
|
|
122
|
+
isHeader = false
|
|
123
|
+
): string | undefined {
|
|
124
|
+
const isPinned = column.getIsPinned();
|
|
125
|
+
if (!isPinned) return undefined;
|
|
126
|
+
|
|
127
|
+
const zIndex = isHeader ? 15 : 1;
|
|
128
|
+
const selectionOffset = isRowSelectionEnabled ? 40 : 0;
|
|
129
|
+
|
|
130
|
+
if (isPinned === 'left') {
|
|
131
|
+
const left = column.getStart('left') + selectionOffset;
|
|
132
|
+
const shadow =
|
|
133
|
+
!isHeader && column.getIsLastColumn('left')
|
|
134
|
+
? 'box-shadow: -4px 0 4px -4px var(--compote-border) inset'
|
|
135
|
+
: undefined;
|
|
136
|
+
return ['position: sticky', `z-index: ${zIndex}`, `left: ${left}px`, shadow]
|
|
137
|
+
.filter(Boolean)
|
|
138
|
+
.join('; ');
|
|
139
|
+
} else {
|
|
140
|
+
const right = column.getAfter('right');
|
|
141
|
+
const shadow =
|
|
142
|
+
!isHeader && column.getIsFirstColumn('right')
|
|
143
|
+
? 'box-shadow: 4px 0 4px -4px var(--compote-border) inset'
|
|
144
|
+
: undefined;
|
|
145
|
+
return ['position: sticky', `z-index: ${zIndex}`, `right: ${right}px`, shadow]
|
|
146
|
+
.filter(Boolean)
|
|
147
|
+
.join('; ');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
113
151
|
function getUrlCellValue(value: unknown) {
|
|
114
152
|
if (typeof value !== 'string' || value.trim() === '') return undefined;
|
|
115
153
|
return value;
|
|
@@ -205,6 +243,7 @@
|
|
|
205
243
|
{#if isRowSelectionEnabled && headerGroupIndex === 0}
|
|
206
244
|
<th
|
|
207
245
|
class="border-b border-surface-3 bg-surface-2 px-3 py-2 text-center align-middle font-medium"
|
|
246
|
+
style="position: sticky; left: 0; z-index: 15"
|
|
208
247
|
rowspan={headerGroupCount}
|
|
209
248
|
>
|
|
210
249
|
{#if isMultiRowSelectionEnabled}
|
|
@@ -230,6 +269,7 @@
|
|
|
230
269
|
aria-sort={header.column.getCanSort()
|
|
231
270
|
? getHeaderAriaSort(sortDirection)
|
|
232
271
|
: undefined}
|
|
272
|
+
style={getPinningStyle(header.column, true)}
|
|
233
273
|
>
|
|
234
274
|
{#if !header.isPlaceholder}
|
|
235
275
|
{#if header.column.getCanSort()}
|
|
@@ -281,12 +321,18 @@
|
|
|
281
321
|
{@const rowSelected = getRowSelectionState(table.store.state.rowSelection, row.id)}
|
|
282
322
|
<tr
|
|
283
323
|
class={cn(
|
|
284
|
-
'border-b border-surface-3 last:border-b-0
|
|
285
|
-
|
|
324
|
+
'group/row border-b border-surface-3 last:border-b-0',
|
|
325
|
+
'[--row-bg:var(--compote-surface-1)]',
|
|
326
|
+
'hover:bg-well/60 hover:[--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]',
|
|
327
|
+
rowSelected &&
|
|
328
|
+
'bg-well/60 [--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]'
|
|
286
329
|
)}
|
|
287
330
|
>
|
|
288
331
|
{#if isRowSelectionEnabled}
|
|
289
|
-
<td
|
|
332
|
+
<td
|
|
333
|
+
class="bg-(--row-bg) px-3 py-2 text-center align-middle"
|
|
334
|
+
style="position: sticky; left: 0; z-index: 1"
|
|
335
|
+
>
|
|
290
336
|
<Checkbox
|
|
291
337
|
size="sm"
|
|
292
338
|
aria-label="Select row"
|
|
@@ -299,7 +345,14 @@
|
|
|
299
345
|
{/if}
|
|
300
346
|
{#each row.getVisibleCells() as cell (cell.id)}
|
|
301
347
|
{@const columnDef = findColumnById(cell.column.id, columns)}
|
|
302
|
-
<td
|
|
348
|
+
<td
|
|
349
|
+
class={cn(
|
|
350
|
+
'truncate px-3 py-2',
|
|
351
|
+
alignClass(columnDef?.align),
|
|
352
|
+
cell.column.getIsPinned() && 'bg-(--row-bg)'
|
|
353
|
+
)}
|
|
354
|
+
style={getPinningStyle(cell.column)}
|
|
355
|
+
>
|
|
303
356
|
{#if columnDef?.type === 'boolean'}
|
|
304
357
|
{@const value = getBooleanCellValue(cell.getValue())}
|
|
305
358
|
{#if value === true}
|
|
@@ -21,6 +21,7 @@ export type DataTableLeafColumnBase<T extends RowData> = DataTableColumnOptions<
|
|
|
21
21
|
type?: DataTableColumnType;
|
|
22
22
|
formatOptions?: Intl.NumberFormatOptions;
|
|
23
23
|
formatLocale?: string;
|
|
24
|
+
pinned?: 'left' | 'right';
|
|
24
25
|
columns?: never;
|
|
25
26
|
};
|
|
26
27
|
export type DataTableAccessorKeyColumn<T extends RowData> = DataTableLeafColumnBase<T> & {
|