@invopop/popui 0.1.4-beta.21 → 0.1.4-beta.22
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.
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import type { TableSortBy, DrawerOption, BaseTableHeaderOrderByProps } from './types.js'
|
|
4
4
|
import DrawerContext from './DrawerContext.svelte'
|
|
5
5
|
|
|
6
|
-
let { isActive = false, sortDirection, onOrderBy, onHide, onFilter, onFreeze, isFrozen = false, showSortOptions = true }: BaseTableHeaderOrderByProps = $props()
|
|
6
|
+
let { isActive = false, sortDirection, onOrderBy, onHide, onFilter, onFreeze, isFrozen = false, showSortOptions = true, showFilterOption = true }: BaseTableHeaderOrderByProps = $props()
|
|
7
7
|
|
|
8
8
|
let items = $derived([
|
|
9
9
|
...(showSortOptions ? [
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
{ label: '', value: 'sep-1', separator: true }
|
|
23
23
|
] : []),
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
...(showFilterOption ? [
|
|
25
|
+
{ icon: Filter, label: 'Filter by column', value: 'filter' },
|
|
26
|
+
{ label: '', value: 'sep-2', separator: true }
|
|
27
|
+
] : []),
|
|
26
28
|
{ icon: Lock, label: isFrozen ? 'Unfreeze column' : 'Freeze column', value: 'freeze' },
|
|
27
29
|
{ label: '', value: 'sep-3', separator: true },
|
|
28
30
|
{ icon: Preview, label: 'Hide column', value: 'hide' }
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
let { table, filters, frozenColumns }: { table: Table<TData>; filters?: Snippet; frozenColumns: Set<string> } = $props()
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
-
<div class="flex items-center justify-between px-4 py-
|
|
9
|
+
<div class="flex items-center justify-between px-4 py-3">
|
|
10
10
|
{#if filters}
|
|
11
11
|
<div class="flex-1">
|
|
12
12
|
{@render filters()}
|
|
@@ -58,6 +58,8 @@ export interface DataTableProps<TData> {
|
|
|
58
58
|
onRowAction?: (action: AnyProp, row: TData) => void;
|
|
59
59
|
initialPageSize?: number;
|
|
60
60
|
initialPage?: number;
|
|
61
|
+
initialSortColumn?: string;
|
|
62
|
+
initialSortDirection?: 'asc' | 'desc';
|
|
61
63
|
pageSizeOptions?: number[];
|
|
62
64
|
emptyState?: Omit<EmptyStateProps, 'children' | 'check'>;
|
|
63
65
|
onRowClick?: (row: TData) => void;
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
onRowAction,
|
|
39
39
|
initialPageSize = 10,
|
|
40
40
|
initialPage = 0,
|
|
41
|
+
initialSortColumn,
|
|
42
|
+
initialSortDirection,
|
|
41
43
|
emptyState = {
|
|
42
44
|
iconSource: Search,
|
|
43
45
|
title: 'No results',
|
|
@@ -64,7 +66,11 @@
|
|
|
64
66
|
|
|
65
67
|
let rowSelection = $state<RowSelectionState>({})
|
|
66
68
|
let columnVisibility = $state<VisibilityState>({})
|
|
67
|
-
let sorting = $state<SortingState>(
|
|
69
|
+
let sorting = $state<SortingState>(
|
|
70
|
+
initialSortColumn && initialSortDirection
|
|
71
|
+
? [{ id: initialSortColumn, desc: initialSortDirection === 'desc' }]
|
|
72
|
+
: []
|
|
73
|
+
)
|
|
68
74
|
let pagination = $state<PaginationState>({ pageIndex: initialPage, pageSize: initialPageSize })
|
|
69
75
|
let columnSizing = $state<ColumnSizingState>({})
|
|
70
76
|
let columnSizingInfo = $state<ColumnSizingInfoState>({
|
|
@@ -272,6 +278,7 @@
|
|
|
272
278
|
isActive={column.getIsSorted() !== false}
|
|
273
279
|
isFrozen={frozenColumns.has(column.id)}
|
|
274
280
|
showSortOptions={column.getCanSort()}
|
|
281
|
+
showFilterOption={!column.columnDef.disableColumnFilter}
|
|
275
282
|
onOrderBy={(direction) => {
|
|
276
283
|
column.toggleSorting(direction === 'desc')
|
|
277
284
|
// Reset to first page when sorting changes (same as page size change)
|
|
@@ -305,15 +312,24 @@
|
|
|
305
312
|
<div class="flex flex-col h-full">
|
|
306
313
|
<DataTableToolbar {table} {filters} {frozenColumns} />
|
|
307
314
|
<div class="flex-1 overflow-hidden flex flex-col">
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
315
|
+
{#if data.length === 0}
|
|
316
|
+
<div class="flex-1 flex items-center justify-center bg-background">
|
|
317
|
+
<EmptyState
|
|
318
|
+
iconSource={emptyState.iconSource}
|
|
319
|
+
title={emptyState.title}
|
|
320
|
+
description={emptyState.description}
|
|
321
|
+
/>
|
|
322
|
+
</div>
|
|
323
|
+
{:else}
|
|
324
|
+
<div
|
|
325
|
+
bind:this={containerRef}
|
|
326
|
+
class="relative bg-background flex-1 overflow-auto"
|
|
327
|
+
style="overscroll-behavior-x: none;"
|
|
328
|
+
>
|
|
329
|
+
<Table.Root>
|
|
330
|
+
<Table.Header>
|
|
331
|
+
{#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
|
|
332
|
+
<Table.Row class="hover:!bg-transparent border-t border-b border-border">
|
|
317
333
|
{#each headerGroup.headers as header, index (header.id)}
|
|
318
334
|
{@const isLastScrollable = index === headerGroup.headers.length - 2}
|
|
319
335
|
{@const isFirstHeader = index === 0}
|
|
@@ -341,13 +357,6 @@
|
|
|
341
357
|
{/if}
|
|
342
358
|
<!-- Left resize handler (resizes previous column) -->
|
|
343
359
|
{#if prevHeader && prevHeader.column.getCanResize()}
|
|
344
|
-
<!-- Always visible vertical border on left -->
|
|
345
|
-
<div
|
|
346
|
-
class={cn(
|
|
347
|
-
'absolute left-0 top-1/2 -translate-y-1/2 h-3 w-px bg-background-default-tertiary',
|
|
348
|
-
prevHeader.column.getIsResizing() && 'opacity-0'
|
|
349
|
-
)}
|
|
350
|
-
></div>
|
|
351
360
|
<!-- Left resize handler -->
|
|
352
361
|
<div
|
|
353
362
|
role="button"
|
|
@@ -366,13 +375,6 @@
|
|
|
366
375
|
</div>
|
|
367
376
|
{/if}
|
|
368
377
|
{#if header.column.getCanResize()}
|
|
369
|
-
<!-- Always visible vertical border -->
|
|
370
|
-
<div
|
|
371
|
-
class={cn(
|
|
372
|
-
'absolute right-0 top-1/2 -translate-y-1/2 h-3 w-px bg-background-default-tertiary',
|
|
373
|
-
header.column.getIsResizing() && 'opacity-0'
|
|
374
|
-
)}
|
|
375
|
-
></div>
|
|
376
378
|
<!-- Resize handler (larger interactive area, enhanced on hover) -->
|
|
377
379
|
<div
|
|
378
380
|
role="button"
|
|
@@ -457,22 +459,11 @@
|
|
|
457
459
|
</Table.Cell>
|
|
458
460
|
{/each}
|
|
459
461
|
</Table.Row>
|
|
460
|
-
{:else}
|
|
461
|
-
<Table.Row class="hover:!bg-transparent h-full">
|
|
462
|
-
<Table.Cell colspan={columns.length} class="h-full !p-0">
|
|
463
|
-
<div class="flex items-center justify-center h-full w-full">
|
|
464
|
-
<EmptyState
|
|
465
|
-
iconSource={emptyState.iconSource}
|
|
466
|
-
title={emptyState.title}
|
|
467
|
-
description={emptyState.description}
|
|
468
|
-
/>
|
|
469
|
-
</div>
|
|
470
|
-
</Table.Cell>
|
|
471
|
-
</Table.Row>
|
|
472
462
|
{/each}
|
|
473
463
|
</Table.Body>
|
|
474
464
|
</Table.Root>
|
|
475
465
|
</div>
|
|
466
|
+
{/if}
|
|
476
467
|
{#if enablePagination}
|
|
477
468
|
<DataTablePagination
|
|
478
469
|
{table}
|
package/dist/types.d.ts
CHANGED