@zhangt58/svelte-vtable 0.1.4 → 0.3.1
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 +177 -44
- package/dist/components/DataTable.svelte +489 -0
- package/dist/components/DataTable.svelte.d.ts +31 -0
- package/dist/components/DataTableControls.svelte +576 -0
- package/dist/components/DataTableControls.svelte.d.ts +39 -0
- package/dist/components/DataTableFilters.svelte +215 -0
- package/dist/components/DataTableFilters.svelte.d.ts +37 -0
- package/dist/components/FiltersModal.svelte +65 -0
- package/dist/components/FiltersModal.svelte.d.ts +25 -0
- package/dist/components/PaginationBar.svelte +86 -0
- package/dist/components/PaginationBar.svelte.d.ts +15 -0
- package/dist/components/filters/FilterColumn.svelte +53 -0
- package/dist/components/filters/FilterColumn.svelte.d.ts +19 -0
- package/dist/components/filters/FilterDateRange.svelte +341 -0
- package/dist/components/filters/FilterDateRange.svelte.d.ts +19 -0
- package/dist/components/filters/FilterValueList.svelte +437 -0
- package/dist/components/filters/FilterValueList.svelte.d.ts +33 -0
- package/dist/components/filters/useFilterState.svelte.d.ts +25 -0
- package/dist/components/filters/useFilterState.svelte.js +132 -0
- package/dist/components/flowbite/DataTableControls.svelte +525 -0
- package/dist/components/flowbite/DataTableControls.svelte.d.ts +39 -0
- package/{src/components → dist/components/flowbite}/FiltersModal.svelte +5 -15
- package/dist/components/flowbite/FiltersModal.svelte.d.ts +25 -0
- package/dist/filterUtils.d.ts +76 -0
- package/{src/lib → dist}/filterUtils.js +48 -46
- package/dist/index.d.ts +60 -0
- package/dist/index.flowbite.d.ts +3 -0
- package/dist/index.flowbite.js +9 -0
- package/dist/index.js +49 -0
- package/{src/lib → dist}/styles.css +26 -3
- package/package.json +38 -17
- package/src/components/DataTable.svelte +0 -252
- package/src/components/DataTableControls.svelte +0 -500
- package/src/components/DataTableFilters.svelte +0 -1225
- package/src/lib/dist/styles.css +0 -273
- package/src/lib/index.js +0 -16
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { useFilterState } from './filters/useFilterState.svelte.js';
|
|
3
|
+
import FilterColumn from './filters/FilterColumn.svelte';
|
|
4
|
+
import FilterValueList from './filters/FilterValueList.svelte';
|
|
5
|
+
import FilterDateRange from './filters/FilterDateRange.svelte';
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
columnFilters = [],
|
|
9
|
+
direction = 'horizontal',
|
|
10
|
+
activeFilters = {},
|
|
11
|
+
onfilter = undefined,
|
|
12
|
+
oncolumnsort = undefined,
|
|
13
|
+
className = '',
|
|
14
|
+
showCounts = true,
|
|
15
|
+
virtualThreshold = 500,
|
|
16
|
+
virtualItemHeight = 36,
|
|
17
|
+
virtualOverscan = 5,
|
|
18
|
+
emitDebounce = 100,
|
|
19
|
+
populateThreshold = 200,
|
|
20
|
+
dropdownInline = true,
|
|
21
|
+
relativeRangePresets = [
|
|
22
|
+
{ label: '1h', value: 1, unit: 'hour' },
|
|
23
|
+
{ label: '6h', value: 6, unit: 'hour' },
|
|
24
|
+
{ label: '12h', value: 12, unit: 'hour' },
|
|
25
|
+
{ label: '1d', value: 1, unit: 'day' },
|
|
26
|
+
{ label: '7d', value: 7, unit: 'day' },
|
|
27
|
+
{ label: '30d', value: 30, unit: 'day' },
|
|
28
|
+
{ label: '1y', value: 1, unit: 'year' },
|
|
29
|
+
],
|
|
30
|
+
} = $props();
|
|
31
|
+
|
|
32
|
+
const fs = useFilterState({
|
|
33
|
+
columnFilters: () => columnFilters,
|
|
34
|
+
activeFilters: () => activeFilters,
|
|
35
|
+
emitDebounce: () => emitDebounce,
|
|
36
|
+
onfilter: () => onfilter,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
let openDropdowns = $state({});
|
|
40
|
+
const toggle = (key) => (openDropdowns = { ...openDropdowns, [key]: !openDropdowns[key] });
|
|
41
|
+
const showAll = () => {
|
|
42
|
+
const a = {};
|
|
43
|
+
for (const c of columnFilters) a[c.key] = true;
|
|
44
|
+
openDropdowns = a;
|
|
45
|
+
};
|
|
46
|
+
const closeAll = () => (openDropdowns = {});
|
|
47
|
+
|
|
48
|
+
const allOpen = $derived(columnFilters.every((c) => openDropdowns[c.key]));
|
|
49
|
+
const allClosed = $derived(columnFilters.every((c) => !openDropdowns[c.key]));
|
|
50
|
+
const isDateRange = (col) => col.type === 'daterange' || col.type === 'datetimerange';
|
|
51
|
+
|
|
52
|
+
const hasActive = $derived(
|
|
53
|
+
Object.values(fs.selections).some((v) =>
|
|
54
|
+
Array.isArray(v) ? v.length > 0 : !!(v?.from || v?.to),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
const activeCount = $derived(
|
|
58
|
+
Object.values(fs.selections).reduce((s, v) => {
|
|
59
|
+
if (Array.isArray(v)) return s + (v?.length || 0);
|
|
60
|
+
if (v && typeof v === 'object' && (v.from || v.to)) return s + 1;
|
|
61
|
+
return s;
|
|
62
|
+
}, 0),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
function handleSortChange(columnKey, { mode, dir }) {
|
|
66
|
+
try {
|
|
67
|
+
if (oncolumnsort) /** @type {any} */ (oncolumnsort)({ key: columnKey, mode, dir });
|
|
68
|
+
} catch (err) {
|
|
69
|
+
try {
|
|
70
|
+
console.debug('oncolumnsort threw', err);
|
|
71
|
+
} catch (e) {}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<div
|
|
77
|
+
class="p-2 bg-gray-50 rounded-md border border-gray-200 dark:bg-gray-800 dark:border-gray-700 {className}"
|
|
78
|
+
class:horizontal={direction === 'horizontal'}
|
|
79
|
+
class:vertical={direction === 'vertical'}
|
|
80
|
+
>
|
|
81
|
+
<div class="flex justify-between items-center mb-2 flex-wrap gap-1">
|
|
82
|
+
<div class="flex items-center gap-1 flex-wrap">
|
|
83
|
+
<button
|
|
84
|
+
class="px-3 py-1 text-sm bg-transparent border rounded-md transition-all cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"
|
|
85
|
+
style="color: var(--vtable-color-accent); border-color: var(--vtable-color-accent);"
|
|
86
|
+
disabled={allOpen}
|
|
87
|
+
onclick={showAll}
|
|
88
|
+
onmouseenter={(e) => {
|
|
89
|
+
if (!e.currentTarget.disabled) {
|
|
90
|
+
e.currentTarget.style.backgroundColor = 'var(--vtable-color-accent)';
|
|
91
|
+
e.currentTarget.style.color = '#fff';
|
|
92
|
+
}
|
|
93
|
+
}}
|
|
94
|
+
onmouseleave={(e) => {
|
|
95
|
+
e.currentTarget.style.backgroundColor = '';
|
|
96
|
+
e.currentTarget.style.color = 'var(--vtable-color-accent)';
|
|
97
|
+
}}
|
|
98
|
+
title="Show all filter dropdowns">Show All</button
|
|
99
|
+
>
|
|
100
|
+
<button
|
|
101
|
+
class="px-3 py-1 text-sm bg-transparent border rounded-md transition-all cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed"
|
|
102
|
+
style="color: #64748b; border-color: #64748b;"
|
|
103
|
+
disabled={allClosed}
|
|
104
|
+
onclick={closeAll}
|
|
105
|
+
onmouseenter={(e) => {
|
|
106
|
+
if (!e.currentTarget.disabled) {
|
|
107
|
+
e.currentTarget.style.backgroundColor = '#64748b';
|
|
108
|
+
e.currentTarget.style.color = '#fff';
|
|
109
|
+
e.currentTarget.style.borderColor = '#64748b';
|
|
110
|
+
}
|
|
111
|
+
}}
|
|
112
|
+
onmouseleave={(e) => {
|
|
113
|
+
e.currentTarget.style.backgroundColor = '';
|
|
114
|
+
e.currentTarget.style.color = '#64748b';
|
|
115
|
+
e.currentTarget.style.borderColor = '#64748b';
|
|
116
|
+
}}
|
|
117
|
+
title="Close all filter dropdowns">Close All</button
|
|
118
|
+
>
|
|
119
|
+
</div>
|
|
120
|
+
<div class="flex items-center gap-2 flex-wrap">
|
|
121
|
+
{#if hasActive}
|
|
122
|
+
<span
|
|
123
|
+
class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/40 dark:text-blue-300"
|
|
124
|
+
>{activeCount} active</span
|
|
125
|
+
>
|
|
126
|
+
<button
|
|
127
|
+
class="px-3 py-1 text-sm text-red-600 bg-transparent border border-red-600 rounded-md hover:bg-red-600 hover:text-white transition-all cursor-pointer"
|
|
128
|
+
onclick={fs.clearAllFilters}
|
|
129
|
+
title="Clear all filters">Clear All</button
|
|
130
|
+
>
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
133
|
+
</div>
|
|
134
|
+
|
|
135
|
+
<div
|
|
136
|
+
class="grid gap-2"
|
|
137
|
+
class:grid-horizontal={direction === 'horizontal'}
|
|
138
|
+
class:grid-vertical={direction === 'vertical'}
|
|
139
|
+
>
|
|
140
|
+
{#each columnFilters as column (column.key)}
|
|
141
|
+
{@const sel = fs.selections[column.key]}
|
|
142
|
+
{@const isActive = Array.isArray(sel) ? sel.length > 0 : !!(sel?.from || sel?.to)}
|
|
143
|
+
{@const isOpen = !!openDropdowns[column.key]}
|
|
144
|
+
<div class="flex flex-col min-w-0 relative">
|
|
145
|
+
<FilterColumn
|
|
146
|
+
{column}
|
|
147
|
+
{isOpen}
|
|
148
|
+
{isActive}
|
|
149
|
+
selection={sel}
|
|
150
|
+
ontoggle={() => toggle(column.key)}
|
|
151
|
+
/>
|
|
152
|
+
{#if isOpen}
|
|
153
|
+
<div
|
|
154
|
+
class={[
|
|
155
|
+
dropdownInline ? '' : 'absolute top-full left-0 right-0',
|
|
156
|
+
'mt-1 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md shadow-lg dark:shadow-gray-900 flex flex-col dropdown-menu',
|
|
157
|
+
isDateRange(column) ? 'overflow-y-auto' : 'max-h-64',
|
|
158
|
+
]
|
|
159
|
+
.filter(Boolean)
|
|
160
|
+
.join(' ')}
|
|
161
|
+
tabindex="-1"
|
|
162
|
+
data-column={column.key}
|
|
163
|
+
>
|
|
164
|
+
{#if isDateRange(column)}
|
|
165
|
+
<FilterDateRange
|
|
166
|
+
{column}
|
|
167
|
+
selection={sel || {}}
|
|
168
|
+
{relativeRangePresets}
|
|
169
|
+
onchange={(u) => fs.updateDateRange(column.key, u)}
|
|
170
|
+
onclear={() => fs.clearColumn(column.key)}
|
|
171
|
+
/>
|
|
172
|
+
{:else}
|
|
173
|
+
<FilterValueList
|
|
174
|
+
{column}
|
|
175
|
+
selections={sel || []}
|
|
176
|
+
{showCounts}
|
|
177
|
+
{virtualThreshold}
|
|
178
|
+
{virtualItemHeight}
|
|
179
|
+
{virtualOverscan}
|
|
180
|
+
{populateThreshold}
|
|
181
|
+
ontoggle={(v) => fs.toggleSelection(column.key, v)}
|
|
182
|
+
oncheckall={(vs) => fs.checkAll(column.key, vs)}
|
|
183
|
+
oninvert={(vs) => fs.invertSelection(column.key, vs)}
|
|
184
|
+
onchecknone={() => fs.checkNone(column.key)}
|
|
185
|
+
onsortchange={(i) => handleSortChange(column.key, i)}
|
|
186
|
+
/>
|
|
187
|
+
{/if}
|
|
188
|
+
</div>
|
|
189
|
+
{/if}
|
|
190
|
+
</div>
|
|
191
|
+
{/each}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
|
|
195
|
+
<style>
|
|
196
|
+
.grid-horizontal {
|
|
197
|
+
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
|
|
198
|
+
}
|
|
199
|
+
.grid-vertical {
|
|
200
|
+
grid-template-columns: 1fr;
|
|
201
|
+
}
|
|
202
|
+
.dropdown-menu {
|
|
203
|
+
z-index: 9999;
|
|
204
|
+
}
|
|
205
|
+
@media (max-width: 768px) {
|
|
206
|
+
.grid-horizontal {
|
|
207
|
+
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
@media (max-width: 640px) {
|
|
211
|
+
.grid-horizontal {
|
|
212
|
+
grid-template-columns: 1fr;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
</style>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default DataTableFilters;
|
|
2
|
+
type DataTableFilters = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const DataTableFilters: import("svelte").Component<{
|
|
7
|
+
columnFilters?: any[];
|
|
8
|
+
direction?: string;
|
|
9
|
+
activeFilters?: Record<string, any>;
|
|
10
|
+
onfilter?: any;
|
|
11
|
+
oncolumnsort?: any;
|
|
12
|
+
className?: string;
|
|
13
|
+
showCounts?: boolean;
|
|
14
|
+
virtualThreshold?: number;
|
|
15
|
+
virtualItemHeight?: number;
|
|
16
|
+
virtualOverscan?: number;
|
|
17
|
+
emitDebounce?: number;
|
|
18
|
+
populateThreshold?: number;
|
|
19
|
+
dropdownInline?: boolean;
|
|
20
|
+
relativeRangePresets?: any[];
|
|
21
|
+
}, {}, "">;
|
|
22
|
+
type $$ComponentProps = {
|
|
23
|
+
columnFilters?: any[];
|
|
24
|
+
direction?: string;
|
|
25
|
+
activeFilters?: Record<string, any>;
|
|
26
|
+
onfilter?: any;
|
|
27
|
+
oncolumnsort?: any;
|
|
28
|
+
className?: string;
|
|
29
|
+
showCounts?: boolean;
|
|
30
|
+
virtualThreshold?: number;
|
|
31
|
+
virtualItemHeight?: number;
|
|
32
|
+
virtualOverscan?: number;
|
|
33
|
+
emitDebounce?: number;
|
|
34
|
+
populateThreshold?: number;
|
|
35
|
+
dropdownInline?: boolean;
|
|
36
|
+
relativeRangePresets?: any[];
|
|
37
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import DataTableFilters from './DataTableFilters.svelte';
|
|
3
|
+
|
|
4
|
+
// Props — make `open` bindable so parent can use `bind:open`
|
|
5
|
+
let {
|
|
6
|
+
open = $bindable(false),
|
|
7
|
+
columnFilters = [],
|
|
8
|
+
activeFilters = {},
|
|
9
|
+
/** @type {string} */
|
|
10
|
+
title = 'Filters',
|
|
11
|
+
// onfilter({ key, values, allFilters })
|
|
12
|
+
onfilter = undefined,
|
|
13
|
+
direction = 'horizontal',
|
|
14
|
+
showCounts = true,
|
|
15
|
+
className = '',
|
|
16
|
+
} = $props();
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
{#if open}
|
|
20
|
+
<!-- Backdrop -->
|
|
21
|
+
<div
|
|
22
|
+
class="vtable-modal-backdrop fixed inset-0 bg-black/50 z-40"
|
|
23
|
+
role="presentation"
|
|
24
|
+
onclick={() => (open = false)}
|
|
25
|
+
onkeydown={(e) => e.key === 'Escape' && (open = false)}
|
|
26
|
+
></div>
|
|
27
|
+
|
|
28
|
+
<!-- Modal panel -->
|
|
29
|
+
<div
|
|
30
|
+
class="vtable-modal fixed inset-0 z-50 flex items-center justify-center p-4 pointer-events-none"
|
|
31
|
+
role="dialog"
|
|
32
|
+
aria-modal="true"
|
|
33
|
+
aria-labelledby="vtable-modal-title"
|
|
34
|
+
>
|
|
35
|
+
<div
|
|
36
|
+
class="vtable-modal-panel bg-white dark:bg-gray-800 rounded-lg shadow-xl w-full max-w-2xl pointer-events-auto overflow-hidden"
|
|
37
|
+
>
|
|
38
|
+
<div class="flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700">
|
|
39
|
+
<h3 id="vtable-modal-title" class="text-lg font-semibold text-gray-900 dark:text-white">
|
|
40
|
+
{title}
|
|
41
|
+
</h3>
|
|
42
|
+
<button
|
|
43
|
+
aria-label="Close"
|
|
44
|
+
class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm p-1.5 inline-flex items-center dark:hover:bg-gray-600 dark:hover:text-white focus:outline-none"
|
|
45
|
+
onclick={() => (open = false)}
|
|
46
|
+
>
|
|
47
|
+
<svg
|
|
48
|
+
class="h-5 w-5"
|
|
49
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
50
|
+
fill="none"
|
|
51
|
+
viewBox="0 0 24 24"
|
|
52
|
+
stroke="currentColor"
|
|
53
|
+
aria-hidden="true"
|
|
54
|
+
>
|
|
55
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12" />
|
|
56
|
+
</svg>
|
|
57
|
+
</button>
|
|
58
|
+
</div>
|
|
59
|
+
|
|
60
|
+
<div class="p-4 overflow-y-auto max-h-[80vh]">
|
|
61
|
+
<DataTableFilters {columnFilters} {activeFilters} {onfilter} {direction} {showCounts} />
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
{/if}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default FiltersModal;
|
|
2
|
+
type FiltersModal = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const FiltersModal: import("svelte").Component<{
|
|
7
|
+
open?: boolean;
|
|
8
|
+
columnFilters?: any[];
|
|
9
|
+
activeFilters?: Record<string, any>;
|
|
10
|
+
title?: string;
|
|
11
|
+
onfilter?: any;
|
|
12
|
+
direction?: string;
|
|
13
|
+
showCounts?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
}, {}, "open">;
|
|
16
|
+
type $$ComponentProps = {
|
|
17
|
+
open?: boolean;
|
|
18
|
+
columnFilters?: any[];
|
|
19
|
+
activeFilters?: Record<string, any>;
|
|
20
|
+
title?: string;
|
|
21
|
+
onfilter?: any;
|
|
22
|
+
direction?: string;
|
|
23
|
+
showCounts?: boolean;
|
|
24
|
+
className?: string;
|
|
25
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* PaginationBar — a self-contained native pagination sub-component.
|
|
4
|
+
*
|
|
5
|
+
* Props:
|
|
6
|
+
* - pages: { name: string; active: boolean; jump?: number }[]
|
|
7
|
+
* - currentPage: number
|
|
8
|
+
* - onpage: (page: number) => void
|
|
9
|
+
*/
|
|
10
|
+
let { pages = [], currentPage = 1, onpage = undefined } = $props();
|
|
11
|
+
|
|
12
|
+
// Derive total pages from the last entry in the pages array (always the last page number).
|
|
13
|
+
const lastPage = $derived(pages.length > 0 ? +pages[pages.length - 1].name || 1 : 1);
|
|
14
|
+
|
|
15
|
+
function goTo(p) {
|
|
16
|
+
if (onpage) onpage(p);
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<nav aria-label="Pagination">
|
|
21
|
+
<ul role="list" class="flex gap-0.5 items-center list-none p-0 m-0">
|
|
22
|
+
<li>
|
|
23
|
+
<button
|
|
24
|
+
type="button"
|
|
25
|
+
aria-label="Previous"
|
|
26
|
+
disabled={currentPage <= 1}
|
|
27
|
+
class="text-sm rounded-l-lg border border-gray-300 bg-transparent w-8 h-8 inline-flex items-center justify-center transition-colors hover:bg-gray-100 disabled:opacity-60 disabled:cursor-default disabled:pointer-events-none"
|
|
28
|
+
onclick={() => goTo(currentPage - 1)}
|
|
29
|
+
>
|
|
30
|
+
<span class="sr-only">Previous</span>
|
|
31
|
+
<svg
|
|
32
|
+
class="shrink-0 h-4 w-4"
|
|
33
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
34
|
+
fill="none"
|
|
35
|
+
viewBox="0 0 24 24"
|
|
36
|
+
stroke="currentColor"
|
|
37
|
+
aria-hidden="true"
|
|
38
|
+
>
|
|
39
|
+
<path
|
|
40
|
+
stroke-linecap="round"
|
|
41
|
+
stroke-linejoin="round"
|
|
42
|
+
stroke-width="1"
|
|
43
|
+
d="M15 19l-7-7 7-7"
|
|
44
|
+
/>
|
|
45
|
+
</svg>
|
|
46
|
+
</button>
|
|
47
|
+
</li>
|
|
48
|
+
|
|
49
|
+
{#each pages as p}
|
|
50
|
+
<li>
|
|
51
|
+
<button
|
|
52
|
+
type="button"
|
|
53
|
+
aria-current={p.active ? 'page' : undefined}
|
|
54
|
+
title={p.name === '…' ? `Jump to page ${p.jump}` : undefined}
|
|
55
|
+
onclick={() => goTo(p.jump ?? +p.name)}
|
|
56
|
+
class={`w-8 h-8 text-sm border inline-flex items-center justify-center transition-colors${p.active ? ' border-transparent' : ' border-gray-300 bg-transparent hover:bg-gray-100'}`}
|
|
57
|
+
style={p.active
|
|
58
|
+
? 'background-color: var(--vtable-color-accent-light); color: var(--vtable-color-accent);'
|
|
59
|
+
: ''}>{p.name}</button
|
|
60
|
+
>
|
|
61
|
+
</li>
|
|
62
|
+
{/each}
|
|
63
|
+
|
|
64
|
+
<li>
|
|
65
|
+
<button
|
|
66
|
+
type="button"
|
|
67
|
+
aria-label="Next"
|
|
68
|
+
disabled={currentPage >= lastPage}
|
|
69
|
+
class="text-sm rounded-r-lg border border-gray-300 bg-transparent w-8 h-8 inline-flex items-center justify-center transition-colors hover:bg-gray-100 disabled:opacity-60 disabled:cursor-default disabled:pointer-events-none"
|
|
70
|
+
onclick={() => goTo(currentPage + 1)}
|
|
71
|
+
>
|
|
72
|
+
<span class="sr-only">Next</span>
|
|
73
|
+
<svg
|
|
74
|
+
class="shrink-0 h-4 w-4"
|
|
75
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
76
|
+
fill="none"
|
|
77
|
+
viewBox="0 0 24 24"
|
|
78
|
+
stroke="currentColor"
|
|
79
|
+
aria-hidden="true"
|
|
80
|
+
>
|
|
81
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M9 5l7 7-7 7" />
|
|
82
|
+
</svg>
|
|
83
|
+
</button>
|
|
84
|
+
</li>
|
|
85
|
+
</ul>
|
|
86
|
+
</nav>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default PaginationBar;
|
|
2
|
+
type PaginationBar = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const PaginationBar: import("svelte").Component<{
|
|
7
|
+
pages?: any[];
|
|
8
|
+
currentPage?: number;
|
|
9
|
+
onpage?: any;
|
|
10
|
+
}, {}, "">;
|
|
11
|
+
type $$ComponentProps = {
|
|
12
|
+
pages?: any[];
|
|
13
|
+
currentPage?: number;
|
|
14
|
+
onpage?: any;
|
|
15
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
/**
|
|
3
|
+
* Renders a single column's toggle button header with label, badge, and chevron.
|
|
4
|
+
*
|
|
5
|
+
* Props:
|
|
6
|
+
* column — column config object { key, label, type, ... }
|
|
7
|
+
* isOpen — whether the dropdown is currently open
|
|
8
|
+
* isActive — whether the column has any active filters
|
|
9
|
+
* selection — current selection (array for value filters, object for date range)
|
|
10
|
+
* ontoggle — callback invoked when the button is clicked
|
|
11
|
+
*/
|
|
12
|
+
let { column, isOpen = false, isActive = false, selection = [], ontoggle } = $props();
|
|
13
|
+
|
|
14
|
+
const selectionIsRange = $derived(!Array.isArray(selection));
|
|
15
|
+
const selectionCount = $derived(Array.isArray(selection) ? selection.length : 0);
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<button
|
|
19
|
+
id="filter-{column.key}"
|
|
20
|
+
class="w-full flex justify-between items-center px-3 py-2 text-sm text-gray-700 dark:text-gray-300 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-md hover:border-gray-400 dark:hover:border-gray-500 focus:outline-none focus:border-blue-500 dark:focus:border-blue-400 focus:ring-2 focus:ring-blue-100 dark:focus:ring-blue-900 transition-all cursor-pointer gap-2"
|
|
21
|
+
style={isActive
|
|
22
|
+
? 'border-color: var(--vtable-color-accent-border); background-color: color-mix(in srgb, var(--vtable-color-accent-light) 40%, transparent);'
|
|
23
|
+
: ''}
|
|
24
|
+
onclick={ontoggle}
|
|
25
|
+
type="button"
|
|
26
|
+
>
|
|
27
|
+
<span class="flex-1 text-left whitespace-nowrap overflow-hidden text-ellipsis min-w-0">
|
|
28
|
+
{column.label || column.key}
|
|
29
|
+
</span>
|
|
30
|
+
{#if isActive}
|
|
31
|
+
{#if !selectionIsRange}
|
|
32
|
+
<span
|
|
33
|
+
class="ml-1 inline-flex items-center justify-center px-2 py-0.5 rounded-full text-xs font-medium text-white"
|
|
34
|
+
style="background-color: var(--vtable-color-accent);">{selectionCount}</span
|
|
35
|
+
>
|
|
36
|
+
{:else}
|
|
37
|
+
<span
|
|
38
|
+
class="ml-1 inline-flex items-center justify-center px-2 py-0.5 rounded-full text-xs font-medium text-white"
|
|
39
|
+
style="background-color: var(--vtable-color-accent);">range</span
|
|
40
|
+
>
|
|
41
|
+
{/if}
|
|
42
|
+
{/if}
|
|
43
|
+
<svg
|
|
44
|
+
class="w-5 h-5 shrink-0 transition-transform {isOpen ? 'rotate-180' : ''}"
|
|
45
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
46
|
+
fill="none"
|
|
47
|
+
viewBox="0 0 24 24"
|
|
48
|
+
stroke="currentColor"
|
|
49
|
+
aria-hidden="true"
|
|
50
|
+
>
|
|
51
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
|
|
52
|
+
</svg>
|
|
53
|
+
</button>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default FilterColumn;
|
|
2
|
+
type FilterColumn = {
|
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
|
4
|
+
$set?(props: Partial<$$ComponentProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const FilterColumn: import("svelte").Component<{
|
|
7
|
+
column: any;
|
|
8
|
+
isOpen?: boolean;
|
|
9
|
+
isActive?: boolean;
|
|
10
|
+
selection?: any[];
|
|
11
|
+
ontoggle: any;
|
|
12
|
+
}, {}, "">;
|
|
13
|
+
type $$ComponentProps = {
|
|
14
|
+
column: any;
|
|
15
|
+
isOpen?: boolean;
|
|
16
|
+
isActive?: boolean;
|
|
17
|
+
selection?: any[];
|
|
18
|
+
ontoggle: any;
|
|
19
|
+
};
|