@passui/tanstack 0.2.4 → 0.2.6
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 +3 -42
- package/dist/types/src/auth-shell/auth-shell.d.ts +5 -0
- package/dist/types/src/document/compose-viewport.d.ts +20 -0
- package/dist/types/src/form-fields/fields.d.ts +24 -0
- package/dist/types/src/form-fields/index.d.ts +2 -0
- package/dist/types/src/form-fields/selection.d.ts +21 -0
- package/dist/types/src/form-fields/submit.d.ts +3 -0
- package/dist/types/src/forms/contexts.d.ts +1 -0
- package/dist/types/src/forms/elements/form-alert.d.ts +6 -0
- package/dist/types/src/forms/elements/submit.d.ts +1 -0
- package/dist/types/src/forms/fields/avatar-picker.d.ts +30 -0
- package/dist/types/src/forms/fields/avatar.d.ts +30 -0
- package/dist/types/src/forms/fields/checkbox.d.ts +1 -0
- package/dist/types/src/forms/fields/index.d.ts +21 -0
- package/dist/types/src/forms/fields/input.d.ts +1 -0
- package/dist/types/src/forms/fields/multiselect.d.ts +1 -0
- package/dist/types/src/forms/fields/otp.d.ts +1 -0
- package/dist/types/src/forms/fields/radio-card.d.ts +1 -0
- package/dist/types/src/forms/fields/switch.d.ts +1 -0
- package/dist/types/src/forms/fields/textarea.d.ts +1 -0
- package/dist/types/src/forms/index.d.ts +41 -0
- package/dist/types/src/mutation/index.d.ts +1 -0
- package/dist/types/src/mutation/use-app-mutation.d.ts +22 -0
- package/dist/types/src/route-boundary/default-boundary.d.ts +2 -0
- package/dist/types/src/route-boundary/default-loader.d.ts +6 -0
- package/dist/types/src/route-boundary/index.d.ts +3 -0
- package/dist/types/src/route-boundary/not-founder.d.ts +4 -0
- package/dist/types/src/settings/setting-list.d.ts +51 -0
- package/dist/types/src/shared/index.d.ts +2 -0
- package/dist/types/src/shared/optimistic.d.ts +3 -0
- package/dist/types/src/shared/table.d.ts +11 -0
- package/dist/types/src/{solid/tables → tables}/columns.d.ts +1 -2
- package/dist/types/src/tables/data-table.d.ts +76 -0
- package/dist/types/src/tables/filter-row.d.ts +9 -0
- package/dist/types/src/{solid/tables → tables}/index.d.ts +0 -1
- package/dist/types/src/tables/pagination.d.ts +8 -0
- package/dist/types/src/tables/utils.d.ts +1 -0
- package/package.json +8 -93
- package/src/document/compose-viewport.tsx +4 -20
- package/src/form-fields/fields.tsx +17 -62
- package/src/form-fields/selection.tsx +12 -52
- package/src/form-fields/submit.tsx +1 -6
- package/src/forms/contexts.ts +2 -6
- package/src/forms/elements/form-alert.tsx +2 -11
- package/src/forms/fields/avatar-picker.tsx +39 -119
- package/src/forms/fields/avatar.tsx +13 -43
- package/src/forms/fields/index.ts +1 -4
- package/src/forms/index.ts +1 -5
- package/src/mutation/use-app-mutation.ts +32 -88
- package/src/route-boundary/default-boundary.tsx +4 -19
- package/src/route-boundary/default-loader.tsx +14 -10
- package/src/route-boundary/not-founder.tsx +3 -14
- package/src/settings/setting-list.tsx +10 -41
- package/src/shared/optimistic.ts +15 -3
- package/src/shared/table.ts +6 -24
- package/src/tables/columns.tsx +4 -13
- package/src/tables/data-table.tsx +130 -225
- package/src/tables/filter-row.tsx +19 -83
- package/src/tables/pagination.tsx +4 -12
- package/dist/client/chunks/form-fields-DlWu70u5.js +0 -630
- package/dist/client/src/solid/auth-shell/index.js +0 -15
- package/dist/client/src/solid/document/index.js +0 -51
- package/dist/client/src/solid/form-fields/index.js +0 -1
- package/dist/client/src/solid/forms/index.js +0 -33
- package/dist/client/src/solid/mutation/index.js +0 -46
- package/dist/client/src/solid/route-boundary/index.js +0 -73
- package/dist/client/src/solid/settings/index.js +0 -173
- package/dist/client/src/solid/tables/index.js +0 -500
- package/dist/server/src/solid/auth-shell/index.js +0 -15
- package/dist/server/src/solid/document/index.js +0 -55
- package/dist/server/src/solid/form-fields/index.js +0 -598
- package/dist/server/src/solid/forms/index.js +0 -33
- package/dist/server/src/solid/mutation/index.js +0 -46
- package/dist/server/src/solid/route-boundary/index.js +0 -73
- package/dist/server/src/solid/settings/index.js +0 -169
- package/dist/server/src/solid/tables/index.js +0 -480
- package/dist/types/src/solid/auth-shell/auth-shell.d.ts +0 -4
- package/dist/types/src/solid/document/compose-viewport.d.ts +0 -14
- package/dist/types/src/solid/form-fields/avatar.d.ts +0 -26
- package/dist/types/src/solid/form-fields/fields.d.ts +0 -45
- package/dist/types/src/solid/form-fields/index.d.ts +0 -3
- package/dist/types/src/solid/form-fields/submit.d.ts +0 -3
- package/dist/types/src/solid/forms/contexts.d.ts +0 -1
- package/dist/types/src/solid/forms/form-alert.d.ts +0 -6
- package/dist/types/src/solid/forms/index.d.ts +0 -43
- package/dist/types/src/solid/mutation/index.d.ts +0 -1
- package/dist/types/src/solid/mutation/use-app-mutation.d.ts +0 -22
- package/dist/types/src/solid/route-boundary/boundaries.d.ts +0 -8
- package/dist/types/src/solid/route-boundary/index.d.ts +0 -1
- package/dist/types/src/solid/settings/setting-list.d.ts +0 -37
- package/dist/types/src/solid/tables/data-table.d.ts +0 -58
- package/dist/types/src/solid/tables/filter-row.d.ts +0 -9
- package/dist/types/src/solid/tables/pagination.d.ts +0 -7
- package/src/solid/auth-shell/auth-shell.tsx +0 -16
- package/src/solid/auth-shell/index.ts +0 -1
- package/src/solid/document/compose-viewport.tsx +0 -69
- package/src/solid/document/index.ts +0 -1
- package/src/solid/form-fields/avatar.tsx +0 -370
- package/src/solid/form-fields/fields.tsx +0 -336
- package/src/solid/form-fields/index.ts +0 -3
- package/src/solid/form-fields/submit.tsx +0 -31
- package/src/solid/forms/contexts.ts +0 -7
- package/src/solid/forms/form-alert.tsx +0 -19
- package/src/solid/forms/index.ts +0 -32
- package/src/solid/mutation/index.ts +0 -5
- package/src/solid/mutation/use-app-mutation.ts +0 -171
- package/src/solid/route-boundary/boundaries.tsx +0 -104
- package/src/solid/route-boundary/index.ts +0 -1
- package/src/solid/settings/index.ts +0 -1
- package/src/solid/settings/setting-list.tsx +0 -185
- package/src/solid/styles.css +0 -2
- package/src/solid/tables/columns.tsx +0 -40
- package/src/solid/tables/data-table.tsx +0 -448
- package/src/solid/tables/filter-row.tsx +0 -161
- package/src/solid/tables/index.ts +0 -4
- package/src/solid/tables/pagination.tsx +0 -78
- /package/dist/types/src/{solid/auth-shell → auth-shell}/index.d.ts +0 -0
- /package/dist/types/src/{solid/document → document}/index.d.ts +0 -0
- /package/dist/types/src/{solid/settings → settings}/index.d.ts +0 -0
|
@@ -1,448 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import {
|
|
3
|
-
createTable,
|
|
4
|
-
FlexRender,
|
|
5
|
-
columnFilteringFeature,
|
|
6
|
-
columnVisibilityFeature,
|
|
7
|
-
createFilteredRowModel,
|
|
8
|
-
createPaginatedRowModel,
|
|
9
|
-
createSortedRowModel,
|
|
10
|
-
filterFn_arrIncludes,
|
|
11
|
-
filterFn_arrIncludesSome,
|
|
12
|
-
filterFn_equals,
|
|
13
|
-
filterFn_inDateRange,
|
|
14
|
-
filterFn_inNumberRange,
|
|
15
|
-
filterFn_includesString,
|
|
16
|
-
globalFilteringFeature,
|
|
17
|
-
rowPaginationFeature,
|
|
18
|
-
rowSelectionFeature,
|
|
19
|
-
rowSortingFeature,
|
|
20
|
-
sortFn_alphanumeric,
|
|
21
|
-
sortFn_datetime,
|
|
22
|
-
sortFn_text,
|
|
23
|
-
tableFeatures,
|
|
24
|
-
type ColumnDef,
|
|
25
|
-
type RowData,
|
|
26
|
-
type ColumnVisibilityState,
|
|
27
|
-
} from "@tanstack/solid-table"
|
|
28
|
-
import {
|
|
29
|
-
createEffect,
|
|
30
|
-
createMemo,
|
|
31
|
-
createSignal,
|
|
32
|
-
For,
|
|
33
|
-
onCleanup,
|
|
34
|
-
Show,
|
|
35
|
-
type JSX,
|
|
36
|
-
} from "solid-js"
|
|
37
|
-
import { Button, SearchField, Toggle } from "@passui/solid"
|
|
38
|
-
import {
|
|
39
|
-
Table,
|
|
40
|
-
TableHeader,
|
|
41
|
-
TableBody,
|
|
42
|
-
TableRow,
|
|
43
|
-
TableHead,
|
|
44
|
-
TableCell,
|
|
45
|
-
TableFooter,
|
|
46
|
-
} from "@passui/solid/table"
|
|
47
|
-
import { DataTablePagination } from "./pagination"
|
|
48
|
-
import { FilterRow } from "./filter-row"
|
|
49
|
-
export const baseTableFeatures = tableFeatures({
|
|
50
|
-
globalFilteringFeature,
|
|
51
|
-
columnFilteringFeature,
|
|
52
|
-
rowSortingFeature,
|
|
53
|
-
rowPaginationFeature,
|
|
54
|
-
columnVisibilityFeature,
|
|
55
|
-
rowSelectionFeature,
|
|
56
|
-
filteredRowModel: createFilteredRowModel(),
|
|
57
|
-
sortedRowModel: createSortedRowModel(),
|
|
58
|
-
paginatedRowModel: createPaginatedRowModel(),
|
|
59
|
-
filterFns: {
|
|
60
|
-
includesString: filterFn_includesString,
|
|
61
|
-
inNumberRange: filterFn_inNumberRange,
|
|
62
|
-
equals: filterFn_equals,
|
|
63
|
-
arrIncludes: filterFn_arrIncludes,
|
|
64
|
-
arrIncludesSome: filterFn_arrIncludesSome,
|
|
65
|
-
inDateRange: filterFn_inDateRange,
|
|
66
|
-
},
|
|
67
|
-
sortFns: {
|
|
68
|
-
text: sortFn_text,
|
|
69
|
-
alphanumeric: sortFn_alphanumeric,
|
|
70
|
-
datetime: sortFn_datetime,
|
|
71
|
-
},
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
export type DataTableFeatures = typeof baseTableFeatures
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* `filterVariant: 'date'` is the one thing a caller has to opt into
|
|
78
|
-
* explicitly (`updatedAt`/`createdAt`, or a custom `type: 'date'` column):
|
|
79
|
-
* unlike an array-valued column (detected automatically below, from the
|
|
80
|
-
* actual data), a date is just a string or number at runtime, nothing to
|
|
81
|
-
* sniff it from safely.
|
|
82
|
-
*/
|
|
83
|
-
export type DataTableColumnMeta = {
|
|
84
|
-
filterVariant?: "date"
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export type DataTableColumnDef<
|
|
88
|
-
TData extends RowData,
|
|
89
|
-
TValue = unknown,
|
|
90
|
-
> = ColumnDef<DataTableFeatures, TData, TValue> & {
|
|
91
|
-
meta?: DataTableColumnMeta
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export type DataTableProps<TData extends RowData> = {
|
|
95
|
-
data: TData[]
|
|
96
|
-
// biome-ignore lint/suspicious/noExplicitAny: columns can carry different cell value types.
|
|
97
|
-
columns: DataTableColumnDef<TData, any>[]
|
|
98
|
-
getRowId?: (row: TData, index: number) => string
|
|
99
|
-
emptyMessage?: string
|
|
100
|
-
searchPlaceholder?: string
|
|
101
|
-
bulkActions?: (
|
|
102
|
-
selected: TData[],
|
|
103
|
-
clear: () => void
|
|
104
|
-
) => JSX.Element
|
|
105
|
-
pagination?: boolean
|
|
106
|
-
pageSizeOptions?: number[]
|
|
107
|
-
onSelectedRowsChange?: (rows: TData[]) => void
|
|
108
|
-
onRowClick?: (row: TData) => void
|
|
109
|
-
footer?: (columns: number) => JSX.Element
|
|
110
|
-
isLoading?: boolean
|
|
111
|
-
initialColumnVisibility?: ColumnVisibilityState
|
|
112
|
-
"aria-label"?: string
|
|
113
|
-
}
|
|
114
|
-
export function DataTable<TData extends RowData>(
|
|
115
|
-
props: DataTableProps<TData>
|
|
116
|
-
) {
|
|
117
|
-
const [search, setSearch] = createSignal(""),
|
|
118
|
-
[columnsOpen, setColumnsOpen] = createSignal(false),
|
|
119
|
-
[filtersOpen, setFiltersOpen] = createSignal(false)
|
|
120
|
-
const columns = createMemo(() =>
|
|
121
|
-
props.columns.map((column) =>
|
|
122
|
-
column.filterFn || !("accessorKey" in column)
|
|
123
|
-
? column
|
|
124
|
-
: {
|
|
125
|
-
...column,
|
|
126
|
-
filterFn: props.data.some((row) =>
|
|
127
|
-
Array.isArray(
|
|
128
|
-
(
|
|
129
|
-
row as Record<
|
|
130
|
-
string,
|
|
131
|
-
unknown
|
|
132
|
-
>
|
|
133
|
-
)[String(column.accessorKey)]
|
|
134
|
-
)
|
|
135
|
-
)
|
|
136
|
-
? ("arrIncludesSome" as const)
|
|
137
|
-
: column.meta?.filterVariant ===
|
|
138
|
-
"date"
|
|
139
|
-
? ("inDateRange" as const)
|
|
140
|
-
: ("includesString" as const),
|
|
141
|
-
}
|
|
142
|
-
)
|
|
143
|
-
)
|
|
144
|
-
const table = createTable({
|
|
145
|
-
features: baseTableFeatures,
|
|
146
|
-
get data() {
|
|
147
|
-
return props.data
|
|
148
|
-
},
|
|
149
|
-
get columns() {
|
|
150
|
-
return columns()
|
|
151
|
-
},
|
|
152
|
-
getRowId: props.getRowId,
|
|
153
|
-
initialState: {
|
|
154
|
-
columnVisibility:
|
|
155
|
-
props.initialColumnVisibility ?? {},
|
|
156
|
-
pagination: {
|
|
157
|
-
pageIndex: 0,
|
|
158
|
-
pageSize: props.pageSizeOptions?.[0] ?? 10,
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
})
|
|
162
|
-
createEffect(() => {
|
|
163
|
-
const value = search()
|
|
164
|
-
const timer = setTimeout(
|
|
165
|
-
() => table.setGlobalFilter(value),
|
|
166
|
-
200
|
|
167
|
-
)
|
|
168
|
-
onCleanup(() => clearTimeout(timer))
|
|
169
|
-
})
|
|
170
|
-
const selected = () =>
|
|
171
|
-
table
|
|
172
|
-
.getSelectedRowModel()
|
|
173
|
-
.rows.map((row) => row.original)
|
|
174
|
-
createEffect(() => {
|
|
175
|
-
const rows = selected()
|
|
176
|
-
props.onSelectedRowsChange?.(rows)
|
|
177
|
-
})
|
|
178
|
-
const clear = () => table.resetRowSelection()
|
|
179
|
-
const rows = () =>
|
|
180
|
-
props.pagination === false
|
|
181
|
-
? table.getPrePaginatedRowModel().rows
|
|
182
|
-
: table.getRowModel().rows
|
|
183
|
-
return (
|
|
184
|
-
<div
|
|
185
|
-
class="flex w-full flex-col gap-4"
|
|
186
|
-
aria-busy={props.isLoading}
|
|
187
|
-
>
|
|
188
|
-
<div class="flex flex-wrap items-center gap-2">
|
|
189
|
-
<SearchField
|
|
190
|
-
aria-label={
|
|
191
|
-
props.searchPlaceholder ?? "Search"
|
|
192
|
-
}
|
|
193
|
-
placeholder={
|
|
194
|
-
props.searchPlaceholder ?? "Search…"
|
|
195
|
-
}
|
|
196
|
-
value={search()}
|
|
197
|
-
onInput={(event) =>
|
|
198
|
-
setSearch(event.currentTarget.value)
|
|
199
|
-
}
|
|
200
|
-
/>
|
|
201
|
-
<Button
|
|
202
|
-
size="sm"
|
|
203
|
-
variant="secondary"
|
|
204
|
-
aria-expanded={columnsOpen()}
|
|
205
|
-
onClick={() =>
|
|
206
|
-
setColumnsOpen((value) => !value)
|
|
207
|
-
}
|
|
208
|
-
>
|
|
209
|
-
Columns
|
|
210
|
-
</Button>
|
|
211
|
-
<Button
|
|
212
|
-
size="sm"
|
|
213
|
-
variant="secondary"
|
|
214
|
-
aria-expanded={filtersOpen()}
|
|
215
|
-
onClick={() =>
|
|
216
|
-
setFiltersOpen((value) => !value)
|
|
217
|
-
}
|
|
218
|
-
>
|
|
219
|
-
Filters
|
|
220
|
-
</Button>
|
|
221
|
-
</div>
|
|
222
|
-
<Show when={columnsOpen()}>
|
|
223
|
-
<div class="flex flex-wrap gap-3">
|
|
224
|
-
<For
|
|
225
|
-
each={table
|
|
226
|
-
.getAllLeafColumns()
|
|
227
|
-
.filter((column) =>
|
|
228
|
-
column.getCanHide()
|
|
229
|
-
)}
|
|
230
|
-
>
|
|
231
|
-
{(column) => (
|
|
232
|
-
<Toggle
|
|
233
|
-
style="checkbox"
|
|
234
|
-
label={
|
|
235
|
-
typeof column.columnDef
|
|
236
|
-
.header === "string"
|
|
237
|
-
? column.columnDef
|
|
238
|
-
.header
|
|
239
|
-
: column.id
|
|
240
|
-
}
|
|
241
|
-
checked={column.getIsVisible()}
|
|
242
|
-
onChange={(visible) =>
|
|
243
|
-
column.toggleVisibility(
|
|
244
|
-
visible
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
/>
|
|
248
|
-
)}
|
|
249
|
-
</For>
|
|
250
|
-
</div>
|
|
251
|
-
</Show>
|
|
252
|
-
<Show when={filtersOpen()}>
|
|
253
|
-
<div class="flex flex-col gap-3">
|
|
254
|
-
<For
|
|
255
|
-
each={table
|
|
256
|
-
.getAllLeafColumns()
|
|
257
|
-
.filter((column) =>
|
|
258
|
-
column.getCanFilter()
|
|
259
|
-
)}
|
|
260
|
-
>
|
|
261
|
-
{(column) => (
|
|
262
|
-
<FilterRow
|
|
263
|
-
column={column}
|
|
264
|
-
data={props.data}
|
|
265
|
-
skip={[]}
|
|
266
|
-
isArrayColumn={props.data.some(
|
|
267
|
-
(row) =>
|
|
268
|
-
Array.isArray(
|
|
269
|
-
(
|
|
270
|
-
row as Record<
|
|
271
|
-
string,
|
|
272
|
-
unknown
|
|
273
|
-
>
|
|
274
|
-
)[column.id]
|
|
275
|
-
)
|
|
276
|
-
)}
|
|
277
|
-
isDateColumn={
|
|
278
|
-
(
|
|
279
|
-
column.columnDef
|
|
280
|
-
.meta as
|
|
281
|
-
| DataTableColumnMeta
|
|
282
|
-
| undefined
|
|
283
|
-
)?.filterVariant ===
|
|
284
|
-
"date"
|
|
285
|
-
}
|
|
286
|
-
/>
|
|
287
|
-
)}
|
|
288
|
-
</For>
|
|
289
|
-
</div>
|
|
290
|
-
</Show>
|
|
291
|
-
<Show
|
|
292
|
-
when={props.bulkActions && selected().length}
|
|
293
|
-
>
|
|
294
|
-
<div class="flex items-center gap-3 rounded-full bg-fill p-2">
|
|
295
|
-
<span>{selected().length} selected</span>
|
|
296
|
-
{props.bulkActions?.(selected(), clear)}
|
|
297
|
-
<Button
|
|
298
|
-
size="sm"
|
|
299
|
-
variant="ghost"
|
|
300
|
-
onClick={clear}
|
|
301
|
-
>
|
|
302
|
-
Clear
|
|
303
|
-
</Button>
|
|
304
|
-
</div>
|
|
305
|
-
</Show>
|
|
306
|
-
<Table aria-label={props["aria-label"]}>
|
|
307
|
-
<TableHeader>
|
|
308
|
-
<For each={table.getHeaderGroups()}>
|
|
309
|
-
{(group) => (
|
|
310
|
-
<TableRow>
|
|
311
|
-
<For each={group.headers}>
|
|
312
|
-
{(header) => (
|
|
313
|
-
<TableHead
|
|
314
|
-
aria-sort={
|
|
315
|
-
header.column.getIsSorted() ===
|
|
316
|
-
"asc"
|
|
317
|
-
? "ascending"
|
|
318
|
-
: header.column.getIsSorted() ===
|
|
319
|
-
"desc"
|
|
320
|
-
? "descending"
|
|
321
|
-
: undefined
|
|
322
|
-
}
|
|
323
|
-
>
|
|
324
|
-
<Show
|
|
325
|
-
when={
|
|
326
|
-
!header.isPlaceholder
|
|
327
|
-
}
|
|
328
|
-
>
|
|
329
|
-
<Show
|
|
330
|
-
when={header.column.getCanSort()}
|
|
331
|
-
fallback={
|
|
332
|
-
<FlexRender
|
|
333
|
-
header={
|
|
334
|
-
header
|
|
335
|
-
}
|
|
336
|
-
/>
|
|
337
|
-
}
|
|
338
|
-
>
|
|
339
|
-
<button
|
|
340
|
-
type="button"
|
|
341
|
-
onClick={header.column.getToggleSortingHandler()}
|
|
342
|
-
class="flex items-center gap-1"
|
|
343
|
-
>
|
|
344
|
-
<FlexRender
|
|
345
|
-
header={
|
|
346
|
-
header
|
|
347
|
-
}
|
|
348
|
-
/>
|
|
349
|
-
<span aria-hidden="true">
|
|
350
|
-
{header.column.getIsSorted() ===
|
|
351
|
-
"asc"
|
|
352
|
-
? "↑"
|
|
353
|
-
: header.column.getIsSorted() ===
|
|
354
|
-
"desc"
|
|
355
|
-
? "↓"
|
|
356
|
-
: "↕"}
|
|
357
|
-
</span>
|
|
358
|
-
</button>
|
|
359
|
-
</Show>
|
|
360
|
-
</Show>
|
|
361
|
-
</TableHead>
|
|
362
|
-
)}
|
|
363
|
-
</For>
|
|
364
|
-
</TableRow>
|
|
365
|
-
)}
|
|
366
|
-
</For>
|
|
367
|
-
</TableHeader>
|
|
368
|
-
<TableBody>
|
|
369
|
-
<Show
|
|
370
|
-
when={rows().length}
|
|
371
|
-
fallback={
|
|
372
|
-
<TableRow>
|
|
373
|
-
<TableCell
|
|
374
|
-
colSpan={
|
|
375
|
-
table.getVisibleLeafColumns()
|
|
376
|
-
.length
|
|
377
|
-
}
|
|
378
|
-
class="h-24 text-center"
|
|
379
|
-
>
|
|
380
|
-
{props.emptyMessage ??
|
|
381
|
-
"No results."}
|
|
382
|
-
</TableCell>
|
|
383
|
-
</TableRow>
|
|
384
|
-
}
|
|
385
|
-
>
|
|
386
|
-
<For each={rows()}>
|
|
387
|
-
{(row) => (
|
|
388
|
-
<TableRow
|
|
389
|
-
data-state={
|
|
390
|
-
row.getIsSelected()
|
|
391
|
-
? "selected"
|
|
392
|
-
: undefined
|
|
393
|
-
}
|
|
394
|
-
onClick={(event) => {
|
|
395
|
-
if (
|
|
396
|
-
(
|
|
397
|
-
event.target as Element
|
|
398
|
-
).closest(
|
|
399
|
-
"button, input, a"
|
|
400
|
-
)
|
|
401
|
-
)
|
|
402
|
-
return
|
|
403
|
-
if (
|
|
404
|
-
props.onSelectedRowsChange
|
|
405
|
-
)
|
|
406
|
-
row.toggleSelected()
|
|
407
|
-
else
|
|
408
|
-
props.onRowClick?.(
|
|
409
|
-
row.original
|
|
410
|
-
)
|
|
411
|
-
}}
|
|
412
|
-
>
|
|
413
|
-
<For
|
|
414
|
-
each={row.getVisibleCells()}
|
|
415
|
-
>
|
|
416
|
-
{(cell) => (
|
|
417
|
-
<TableCell>
|
|
418
|
-
<FlexRender
|
|
419
|
-
cell={
|
|
420
|
-
cell
|
|
421
|
-
}
|
|
422
|
-
/>
|
|
423
|
-
</TableCell>
|
|
424
|
-
)}
|
|
425
|
-
</For>
|
|
426
|
-
</TableRow>
|
|
427
|
-
)}
|
|
428
|
-
</For>
|
|
429
|
-
</Show>
|
|
430
|
-
</TableBody>
|
|
431
|
-
<Show when={props.footer}>
|
|
432
|
-
<TableFooter>
|
|
433
|
-
{props.footer?.(
|
|
434
|
-
table.getVisibleLeafColumns()
|
|
435
|
-
.length
|
|
436
|
-
)}
|
|
437
|
-
</TableFooter>
|
|
438
|
-
</Show>
|
|
439
|
-
</Table>
|
|
440
|
-
<Show when={props.pagination !== false}>
|
|
441
|
-
<DataTablePagination
|
|
442
|
-
table={table}
|
|
443
|
-
pageSizeOptions={props.pageSizeOptions}
|
|
444
|
-
/>
|
|
445
|
-
</Show>
|
|
446
|
-
</div>
|
|
447
|
-
)
|
|
448
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import { createMemo, For, Show } from "solid-js"
|
|
3
|
-
import type { Column, RowData } from "@tanstack/solid-table"
|
|
4
|
-
import { Button, Toggle } from "@passui/solid"
|
|
5
|
-
import type { DataTableFeatures } from "./data-table"
|
|
6
|
-
export function FilterRow<TData extends RowData>(props: {
|
|
7
|
-
column: Column<DataTableFeatures, TData, unknown>
|
|
8
|
-
data: TData[]
|
|
9
|
-
skip: string[]
|
|
10
|
-
isArrayColumn: boolean
|
|
11
|
-
isDateColumn?: boolean
|
|
12
|
-
}) {
|
|
13
|
-
const values = createMemo(() => {
|
|
14
|
-
if (props.skip.includes(props.column.id)) return []
|
|
15
|
-
const values = props.data
|
|
16
|
-
.flatMap((row) => {
|
|
17
|
-
const value = (
|
|
18
|
-
row as Record<string, unknown>
|
|
19
|
-
)[props.column.id]
|
|
20
|
-
return props.isArrayColumn &&
|
|
21
|
-
Array.isArray(value)
|
|
22
|
-
? value
|
|
23
|
-
: [value]
|
|
24
|
-
})
|
|
25
|
-
.filter(
|
|
26
|
-
(value) =>
|
|
27
|
-
value !== null &&
|
|
28
|
-
value !== undefined &&
|
|
29
|
-
value !== "" &&
|
|
30
|
-
typeof value !== "object"
|
|
31
|
-
)
|
|
32
|
-
const unique = [...new Set(values.map(String))]
|
|
33
|
-
return unique.length >= 2 &&
|
|
34
|
-
unique.length <= (props.isArrayColumn ? 20 : 12)
|
|
35
|
-
? unique
|
|
36
|
-
: []
|
|
37
|
-
})
|
|
38
|
-
const label = () =>
|
|
39
|
-
typeof props.column.columnDef.header === "string"
|
|
40
|
-
? props.column.columnDef.header
|
|
41
|
-
: props.column.id
|
|
42
|
-
const range = () =>
|
|
43
|
-
(props.column.getFilterValue() as
|
|
44
|
-
| [string?, string?]
|
|
45
|
-
| undefined) ?? []
|
|
46
|
-
return (
|
|
47
|
-
<div class="flex flex-wrap items-center gap-3">
|
|
48
|
-
<span class="text-footnote">{label()}</span>
|
|
49
|
-
<Show
|
|
50
|
-
when={props.isDateColumn}
|
|
51
|
-
fallback={
|
|
52
|
-
<Show
|
|
53
|
-
when={values().length}
|
|
54
|
-
fallback={
|
|
55
|
-
<input
|
|
56
|
-
aria-label={label()}
|
|
57
|
-
value={String(
|
|
58
|
-
props.column.getFilterValue() ??
|
|
59
|
-
""
|
|
60
|
-
)}
|
|
61
|
-
onInput={(event) =>
|
|
62
|
-
props.column.setFilterValue(
|
|
63
|
-
event.currentTarget
|
|
64
|
-
.value ||
|
|
65
|
-
undefined
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
class="rounded-lg border border-separator px-3 py-2"
|
|
69
|
-
/>
|
|
70
|
-
}
|
|
71
|
-
>
|
|
72
|
-
<For each={values()}>
|
|
73
|
-
{(value) => (
|
|
74
|
-
<Toggle
|
|
75
|
-
style="checkbox"
|
|
76
|
-
label={value}
|
|
77
|
-
checked={(
|
|
78
|
-
(props.column.getFilterValue() as
|
|
79
|
-
| string[]
|
|
80
|
-
| undefined) ?? []
|
|
81
|
-
).includes(value)}
|
|
82
|
-
onChange={(checked) =>
|
|
83
|
-
props.column.setFilterValue(
|
|
84
|
-
(
|
|
85
|
-
previous:
|
|
86
|
-
| string[]
|
|
87
|
-
| undefined
|
|
88
|
-
) => {
|
|
89
|
-
const next =
|
|
90
|
-
checked
|
|
91
|
-
? [
|
|
92
|
-
...(previous ??
|
|
93
|
-
[]),
|
|
94
|
-
value,
|
|
95
|
-
]
|
|
96
|
-
: (
|
|
97
|
-
previous ??
|
|
98
|
-
[]
|
|
99
|
-
).filter(
|
|
100
|
-
(
|
|
101
|
-
item
|
|
102
|
-
) =>
|
|
103
|
-
item !==
|
|
104
|
-
value
|
|
105
|
-
)
|
|
106
|
-
return next.length
|
|
107
|
-
? next
|
|
108
|
-
: undefined
|
|
109
|
-
}
|
|
110
|
-
)
|
|
111
|
-
}
|
|
112
|
-
/>
|
|
113
|
-
)}
|
|
114
|
-
</For>
|
|
115
|
-
</Show>
|
|
116
|
-
}
|
|
117
|
-
>
|
|
118
|
-
<input
|
|
119
|
-
type="date"
|
|
120
|
-
aria-label={`${label()} from`}
|
|
121
|
-
value={range()[0] ?? ""}
|
|
122
|
-
onInput={(event) =>
|
|
123
|
-
props.column.setFilterValue([
|
|
124
|
-
event.currentTarget.value ||
|
|
125
|
-
undefined,
|
|
126
|
-
range()[1],
|
|
127
|
-
])
|
|
128
|
-
}
|
|
129
|
-
/>
|
|
130
|
-
<input
|
|
131
|
-
type="date"
|
|
132
|
-
aria-label={`${label()} to`}
|
|
133
|
-
value={range()[1] ?? ""}
|
|
134
|
-
onInput={(event) =>
|
|
135
|
-
props.column.setFilterValue([
|
|
136
|
-
range()[0],
|
|
137
|
-
event.currentTarget.value ||
|
|
138
|
-
undefined,
|
|
139
|
-
])
|
|
140
|
-
}
|
|
141
|
-
/>
|
|
142
|
-
</Show>
|
|
143
|
-
<Show
|
|
144
|
-
when={
|
|
145
|
-
props.column.getFilterValue() !==
|
|
146
|
-
undefined
|
|
147
|
-
}
|
|
148
|
-
>
|
|
149
|
-
<Button
|
|
150
|
-
size="sm"
|
|
151
|
-
variant="ghost"
|
|
152
|
-
onClick={() =>
|
|
153
|
-
props.column.setFilterValue(undefined)
|
|
154
|
-
}
|
|
155
|
-
>
|
|
156
|
-
Clear
|
|
157
|
-
</Button>
|
|
158
|
-
</Show>
|
|
159
|
-
</div>
|
|
160
|
-
)
|
|
161
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/** @jsxImportSource solid-js */
|
|
2
|
-
import type {
|
|
3
|
-
RowData,
|
|
4
|
-
SolidTable,
|
|
5
|
-
} from "@tanstack/solid-table"
|
|
6
|
-
import { Button, Picker } from "@passui/solid"
|
|
7
|
-
import type { DataTableFeatures } from "./data-table"
|
|
8
|
-
export function DataTablePagination<
|
|
9
|
-
TData extends RowData,
|
|
10
|
-
>(props: {
|
|
11
|
-
table: SolidTable<DataTableFeatures, TData>
|
|
12
|
-
pageSizeOptions?: number[]
|
|
13
|
-
}) {
|
|
14
|
-
return (
|
|
15
|
-
<div class="flex flex-wrap items-center gap-2">
|
|
16
|
-
<p class="text-footnote text-label-secondary">
|
|
17
|
-
Page{" "}
|
|
18
|
-
{props.table.getPageCount()
|
|
19
|
-
? (props.table.atoms.pagination.get()
|
|
20
|
-
?.pageIndex ?? 0) + 1
|
|
21
|
-
: 0}{" "}
|
|
22
|
-
of {props.table.getPageCount()}
|
|
23
|
-
</p>
|
|
24
|
-
<Button
|
|
25
|
-
size="sm"
|
|
26
|
-
variant="ghost"
|
|
27
|
-
disabled={!props.table.getCanPreviousPage()}
|
|
28
|
-
onClick={() => props.table.setPageIndex(0)}
|
|
29
|
-
>
|
|
30
|
-
First
|
|
31
|
-
</Button>
|
|
32
|
-
<Button
|
|
33
|
-
size="sm"
|
|
34
|
-
variant="ghost"
|
|
35
|
-
disabled={!props.table.getCanPreviousPage()}
|
|
36
|
-
onClick={() => props.table.previousPage()}
|
|
37
|
-
>
|
|
38
|
-
Previous
|
|
39
|
-
</Button>
|
|
40
|
-
<Button
|
|
41
|
-
size="sm"
|
|
42
|
-
variant="ghost"
|
|
43
|
-
disabled={!props.table.getCanNextPage()}
|
|
44
|
-
onClick={() => props.table.nextPage()}
|
|
45
|
-
>
|
|
46
|
-
Next
|
|
47
|
-
</Button>
|
|
48
|
-
<Button
|
|
49
|
-
size="sm"
|
|
50
|
-
variant="ghost"
|
|
51
|
-
disabled={!props.table.getCanNextPage()}
|
|
52
|
-
onClick={() =>
|
|
53
|
-
props.table.setPageIndex(
|
|
54
|
-
props.table.getPageCount() - 1
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
>
|
|
58
|
-
Last
|
|
59
|
-
</Button>
|
|
60
|
-
<Picker
|
|
61
|
-
label="Rows per page"
|
|
62
|
-
value={String(
|
|
63
|
-
props.table.atoms.pagination.get()
|
|
64
|
-
?.pageSize ?? 10
|
|
65
|
-
)}
|
|
66
|
-
onChange={(value) =>
|
|
67
|
-
props.table.setPageSize(Number(value))
|
|
68
|
-
}
|
|
69
|
-
options={(
|
|
70
|
-
props.pageSizeOptions ?? [10, 20, 30, 50]
|
|
71
|
-
).map((size) => ({
|
|
72
|
-
value: String(size),
|
|
73
|
-
label: String(size),
|
|
74
|
-
}))}
|
|
75
|
-
/>
|
|
76
|
-
</div>
|
|
77
|
-
)
|
|
78
|
-
}
|
|
File without changes
|
|
File without changes
|