@shotleybuilder/svelte-table-kit 0.2.0 → 0.5.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/README.md +121 -8
- package/dist/TableKit.svelte +255 -50
- package/dist/TableKit.svelte.d.ts +1 -0
- package/dist/components/ColumnMenu.svelte +271 -0
- package/dist/components/ColumnMenu.svelte.d.ts +29 -0
- package/dist/components/FilterBar.svelte +12 -5
- package/dist/components/FilterBar.svelte.d.ts +2 -0
- package/dist/components/GroupBar.svelte +12 -5
- package/dist/components/GroupBar.svelte.d.ts +2 -0
- package/dist/components/SortBar.svelte +239 -0
- package/dist/components/SortBar.svelte.d.ts +22 -0
- package/dist/components/SortCondition.svelte +131 -0
- package/dist/components/SortCondition.svelte.d.ts +25 -0
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script>export let columnId;
|
|
2
|
+
export let desc;
|
|
3
|
+
export let columns;
|
|
4
|
+
export let sorting;
|
|
5
|
+
export let onUpdate;
|
|
6
|
+
export let onRemove;
|
|
7
|
+
const directionOptions = [
|
|
8
|
+
{ value: "asc", label: "A \u2192 Z", icon: "\u2191" },
|
|
9
|
+
{ value: "desc", label: "Z \u2192 A", icon: "\u2193" }
|
|
10
|
+
];
|
|
11
|
+
function handleColumnChange(event) {
|
|
12
|
+
const newColumnId = event.target.value;
|
|
13
|
+
onUpdate(newColumnId, desc);
|
|
14
|
+
}
|
|
15
|
+
function handleDirectionChange(event) {
|
|
16
|
+
const direction = event.target.value;
|
|
17
|
+
onUpdate(columnId, direction === "desc");
|
|
18
|
+
}
|
|
19
|
+
function getColumnId(col) {
|
|
20
|
+
return col.accessorKey || col.id;
|
|
21
|
+
}
|
|
22
|
+
$: availableColumns = columns.filter((col) => {
|
|
23
|
+
const colId = getColumnId(col);
|
|
24
|
+
if (!colId || col.enableSorting === false) return false;
|
|
25
|
+
return colId === columnId || !sorting.some((s) => s.id === colId);
|
|
26
|
+
});
|
|
27
|
+
$: columnOptions = availableColumns.map((col) => ({
|
|
28
|
+
id: getColumnId(col) || "",
|
|
29
|
+
label: col.header || getColumnId(col) || ""
|
|
30
|
+
}));
|
|
31
|
+
$: currentDirection = desc ? "desc" : "asc";
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<div class="sort-condition">
|
|
35
|
+
<select class="field-select" value={columnId} on:change={handleColumnChange}>
|
|
36
|
+
<option value="">Select field...</option>
|
|
37
|
+
{#each columnOptions as option}
|
|
38
|
+
<option value={option.id}>
|
|
39
|
+
{option.label}
|
|
40
|
+
</option>
|
|
41
|
+
{/each}
|
|
42
|
+
</select>
|
|
43
|
+
|
|
44
|
+
<select
|
|
45
|
+
class="direction-select"
|
|
46
|
+
value={currentDirection}
|
|
47
|
+
on:change={handleDirectionChange}
|
|
48
|
+
disabled={!columnId}
|
|
49
|
+
>
|
|
50
|
+
{#each directionOptions as option}
|
|
51
|
+
<option value={option.value}>
|
|
52
|
+
{option.icon} {option.label}
|
|
53
|
+
</option>
|
|
54
|
+
{/each}
|
|
55
|
+
</select>
|
|
56
|
+
|
|
57
|
+
<button class="remove-btn" on:click={onRemove} title="Remove sort">
|
|
58
|
+
<svg class="icon" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
|
59
|
+
<path
|
|
60
|
+
stroke-linecap="round"
|
|
61
|
+
stroke-linejoin="round"
|
|
62
|
+
stroke-width="2"
|
|
63
|
+
d="M6 18L18 6M6 6l12 12"
|
|
64
|
+
/>
|
|
65
|
+
</svg>
|
|
66
|
+
</button>
|
|
67
|
+
</div>
|
|
68
|
+
|
|
69
|
+
<style>
|
|
70
|
+
.sort-condition {
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: 0.5rem;
|
|
74
|
+
padding: 0.5rem;
|
|
75
|
+
background: #f9fafb;
|
|
76
|
+
border-radius: 0.375rem;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.field-select,
|
|
80
|
+
.direction-select {
|
|
81
|
+
padding: 0.375rem 0.75rem;
|
|
82
|
+
font-size: 0.875rem;
|
|
83
|
+
border: 1px solid #d1d5db;
|
|
84
|
+
border-radius: 0.375rem;
|
|
85
|
+
background: white;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.field-select {
|
|
89
|
+
flex: 1;
|
|
90
|
+
min-width: 150px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.direction-select {
|
|
94
|
+
flex: 0.7;
|
|
95
|
+
min-width: 120px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.direction-select:disabled {
|
|
99
|
+
background: #f3f4f6;
|
|
100
|
+
color: #9ca3af;
|
|
101
|
+
cursor: not-allowed;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.field-select:focus,
|
|
105
|
+
.direction-select:focus {
|
|
106
|
+
outline: none;
|
|
107
|
+
border-color: #f59e0b;
|
|
108
|
+
box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.remove-btn {
|
|
112
|
+
flex-shrink: 0;
|
|
113
|
+
padding: 0.375rem;
|
|
114
|
+
background: none;
|
|
115
|
+
border: none;
|
|
116
|
+
color: #6b7280;
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
border-radius: 0.25rem;
|
|
119
|
+
transition: all 0.2s;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
.remove-btn:hover {
|
|
123
|
+
background: #fee2e2;
|
|
124
|
+
color: #dc2626;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.icon {
|
|
128
|
+
width: 1rem;
|
|
129
|
+
height: 1rem;
|
|
130
|
+
}
|
|
131
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { ColumnDef } from '@tanstack/svelte-table';
|
|
3
|
+
import type { SortingState } from '@tanstack/svelte-table';
|
|
4
|
+
declare const __propDef: {
|
|
5
|
+
props: {
|
|
6
|
+
columnId: string;
|
|
7
|
+
desc: boolean;
|
|
8
|
+
columns: ColumnDef<any>[];
|
|
9
|
+
sorting: SortingState;
|
|
10
|
+
onUpdate: (columnId: string, desc: boolean) => void;
|
|
11
|
+
onRemove: () => void;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {};
|
|
17
|
+
exports?: {} | undefined;
|
|
18
|
+
bindings?: string | undefined;
|
|
19
|
+
};
|
|
20
|
+
export type SortConditionProps = typeof __propDef.props;
|
|
21
|
+
export type SortConditionEvents = typeof __propDef.events;
|
|
22
|
+
export type SortConditionSlots = typeof __propDef.slots;
|
|
23
|
+
export default class SortCondition extends SvelteComponent<SortConditionProps, SortConditionEvents, SortConditionSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export interface TableFeatures {
|
|
|
21
21
|
columnReordering?: boolean;
|
|
22
22
|
filtering?: boolean;
|
|
23
23
|
sorting?: boolean;
|
|
24
|
+
sortingMode?: 'header' | 'control';
|
|
24
25
|
pagination?: boolean;
|
|
25
26
|
rowSelection?: boolean;
|
|
26
27
|
grouping?: boolean;
|
|
@@ -37,6 +38,7 @@ export interface TableConfig {
|
|
|
37
38
|
right?: string[];
|
|
38
39
|
};
|
|
39
40
|
defaultFilters?: FilterCondition[];
|
|
41
|
+
filterLogic?: FilterLogic;
|
|
40
42
|
defaultSorting?: SortConfig[];
|
|
41
43
|
pagination?: {
|
|
42
44
|
pageSize: number;
|
package/package.json
CHANGED