@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
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
useTable,
|
|
38
38
|
} from "@tanstack/react-table"
|
|
39
39
|
import type { ReactNode } from "react"
|
|
40
|
-
import { useEffect, useMemo, useState } from "react"
|
|
40
|
+
import { useEffect, useMemo, useRef, useState } from "react"
|
|
41
41
|
import { Button } from "@passui/react/button"
|
|
42
42
|
import { Toggle } from "@passui/react/toggle"
|
|
43
43
|
import { SearchField } from "@passui/react"
|
|
@@ -53,11 +53,7 @@ import {
|
|
|
53
53
|
import { cn } from "@passui/react/cn"
|
|
54
54
|
import { FilterRow } from "./filter-row"
|
|
55
55
|
import { DataTablePagination } from "./pagination"
|
|
56
|
-
import {
|
|
57
|
-
columnIdOf,
|
|
58
|
-
getColumnLabel,
|
|
59
|
-
isArrayValuedColumn,
|
|
60
|
-
} from "./utils"
|
|
56
|
+
import { columnIdOf, getColumnLabel, isArrayValuedColumn } from "./utils"
|
|
61
57
|
|
|
62
58
|
export const baseTableFeatures = tableFeatures({
|
|
63
59
|
globalFilteringFeature,
|
|
@@ -97,10 +93,11 @@ export type DataTableColumnMeta = {
|
|
|
97
93
|
filterVariant?: "date"
|
|
98
94
|
}
|
|
99
95
|
|
|
100
|
-
export type DataTableColumnDef<
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
export type DataTableColumnDef<TData extends RowData, TValue = unknown> = ColumnDef<
|
|
97
|
+
DataTableFeatures,
|
|
98
|
+
TData,
|
|
99
|
+
TValue
|
|
100
|
+
> & {
|
|
104
101
|
meta?: DataTableColumnMeta
|
|
105
102
|
}
|
|
106
103
|
|
|
@@ -120,10 +117,7 @@ type DataTableProps<TData extends RowData> = {
|
|
|
120
117
|
"aria-label": string
|
|
121
118
|
emptyMessage?: ReactNode
|
|
122
119
|
searchPlaceholder?: string
|
|
123
|
-
bulkActions?: (
|
|
124
|
-
selectedRows: TData[],
|
|
125
|
-
clearSelection: () => void
|
|
126
|
-
) => ReactNode
|
|
120
|
+
bulkActions?: (selectedRows: TData[], clearSelection: () => void) => ReactNode
|
|
127
121
|
/** Set false to render just the table. Default true. */
|
|
128
122
|
pagination?: boolean
|
|
129
123
|
pageSizeOptions?: number[]
|
|
@@ -165,16 +159,11 @@ function ToolbarToggle({
|
|
|
165
159
|
>
|
|
166
160
|
{label}
|
|
167
161
|
{count > 0 && (
|
|
168
|
-
<span className="rounded-full bg-foreground/10 px-1.5 tabular-nums">
|
|
169
|
-
{count}
|
|
170
|
-
</span>
|
|
162
|
+
<span className="rounded-full bg-foreground/10 px-1.5 tabular-nums">{count}</span>
|
|
171
163
|
)}
|
|
172
164
|
<HugeiconsIcon
|
|
173
165
|
icon={ChevronDownIcon}
|
|
174
|
-
className={cn(
|
|
175
|
-
"size-3 transition-transform duration-150",
|
|
176
|
-
open && "rotate-180"
|
|
177
|
-
)}
|
|
166
|
+
className={cn("size-3 transition-transform duration-150", open && "rotate-180")}
|
|
178
167
|
/>
|
|
179
168
|
</button>
|
|
180
169
|
)
|
|
@@ -207,21 +196,15 @@ export function DataTable<TData extends RowData>({
|
|
|
207
196
|
// globalFilter (the actual re-filter trigger, synchronous across the
|
|
208
197
|
// whole dataset) only updates 200ms after the last keystroke.
|
|
209
198
|
useEffect(() => {
|
|
210
|
-
const timeout = setTimeout(
|
|
211
|
-
() => setGlobalFilter(searchInput),
|
|
212
|
-
200
|
|
213
|
-
)
|
|
199
|
+
const timeout = setTimeout(() => setGlobalFilter(searchInput), 200)
|
|
214
200
|
return () => clearTimeout(timeout)
|
|
215
201
|
}, [searchInput])
|
|
216
202
|
const [sorting, setSorting] = useState<SortingState>([])
|
|
217
|
-
const [columnFilters, setColumnFilters] =
|
|
218
|
-
useState<ColumnFiltersState>([])
|
|
203
|
+
const [columnFilters, setColumnFilters] = useState<ColumnFiltersState>([])
|
|
219
204
|
const [columnVisibility, setColumnVisibility] =
|
|
220
|
-
useState<ColumnVisibilityState>(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const [rowSelection, setRowSelection] =
|
|
224
|
-
useState<RowSelectionState>({})
|
|
205
|
+
useState<ColumnVisibilityState>(initialColumnVisibility)
|
|
206
|
+
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
|
207
|
+
const lastReportedSelection = useRef(rowSelection)
|
|
225
208
|
const [columnsOpen, setColumnsOpen] = useState(false)
|
|
226
209
|
const [filtersOpen, setFiltersOpen] = useState(false)
|
|
227
210
|
const augmentedColumns = useMemo(
|
|
@@ -268,29 +251,25 @@ export function DataTable<TData extends RowData>({
|
|
|
268
251
|
globalFilterFn: "auto",
|
|
269
252
|
})
|
|
270
253
|
|
|
271
|
-
const toggleableColumns = table
|
|
272
|
-
|
|
273
|
-
.filter((c) => c.getCanHide())
|
|
274
|
-
const hiddenCount = toggleableColumns.filter(
|
|
275
|
-
(c) => !c.getIsVisible()
|
|
276
|
-
).length
|
|
254
|
+
const toggleableColumns = table.getAllColumns().filter((c) => c.getCanHide())
|
|
255
|
+
const hiddenCount = toggleableColumns.filter((c) => !c.getIsVisible()).length
|
|
277
256
|
|
|
278
257
|
const skip = ["select", "actions"]
|
|
279
258
|
const filterableColumns = table
|
|
280
259
|
.getAllColumns()
|
|
281
|
-
.filter(
|
|
282
|
-
(c) =>
|
|
283
|
-
c.getCanFilter() &&
|
|
284
|
-
!skip.includes(c.id) &&
|
|
285
|
-
c.accessorFn !== undefined
|
|
286
|
-
)
|
|
260
|
+
.filter((c) => c.getCanFilter() && !skip.includes(c.id) && c.accessorFn !== undefined)
|
|
287
261
|
|
|
288
262
|
const activeFilterCount = columnFilters.length
|
|
289
|
-
const selectedCount =
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
263
|
+
const selectedCount = Object.values(rowSelection).filter(Boolean).length
|
|
264
|
+
const selectedRows = useMemo(
|
|
265
|
+
() => data.filter((row) => rowSelection[getRowId(row)]),
|
|
266
|
+
[data, getRowId, rowSelection]
|
|
267
|
+
)
|
|
268
|
+
useEffect(() => {
|
|
269
|
+
if (lastReportedSelection.current === rowSelection) return
|
|
270
|
+
lastReportedSelection.current = rowSelection
|
|
271
|
+
onSelectedRowsChange?.(selectedRows)
|
|
272
|
+
}, [rowSelection, selectedRows, onSelectedRowsChange])
|
|
294
273
|
const clearSelection = () => setRowSelection({})
|
|
295
274
|
|
|
296
275
|
const rows = table.getRowModel().rows
|
|
@@ -305,9 +284,7 @@ export function DataTable<TData extends RowData>({
|
|
|
305
284
|
placeholder={searchPlaceholder}
|
|
306
285
|
autoComplete="off"
|
|
307
286
|
value={searchInput}
|
|
308
|
-
onChange={(event) =>
|
|
309
|
-
setSearchInput(event.target.value)
|
|
310
|
-
}
|
|
287
|
+
onChange={(event) => setSearchInput(event.target.value)}
|
|
311
288
|
/>
|
|
312
289
|
{isLoading && (
|
|
313
290
|
<HugeiconsIcon
|
|
@@ -347,9 +324,7 @@ export function DataTable<TData extends RowData>({
|
|
|
347
324
|
type="button"
|
|
348
325
|
variant="ghost"
|
|
349
326
|
size="sm"
|
|
350
|
-
onClick={() =>
|
|
351
|
-
table.resetColumnVisibility()
|
|
352
|
-
}
|
|
327
|
+
onClick={() => table.resetColumnVisibility()}
|
|
353
328
|
className="text-muted-foreground hover:text-foreground"
|
|
354
329
|
>
|
|
355
330
|
Show all
|
|
@@ -358,32 +333,17 @@ export function DataTable<TData extends RowData>({
|
|
|
358
333
|
</div>
|
|
359
334
|
<div className="flex flex-wrap items-center gap-4">
|
|
360
335
|
{toggleableColumns.map((column) => {
|
|
361
|
-
const visible =
|
|
362
|
-
column.getIsVisible()
|
|
336
|
+
const visible = column.getIsVisible()
|
|
363
337
|
return (
|
|
364
|
-
<div
|
|
365
|
-
key={column.id}
|
|
366
|
-
className="flex cursor-pointer items-center gap-2"
|
|
367
|
-
onClick={() =>
|
|
368
|
-
column.toggleVisibility()
|
|
369
|
-
}
|
|
370
|
-
>
|
|
338
|
+
<div key={column.id} className="flex items-center gap-2">
|
|
371
339
|
<Toggle
|
|
372
340
|
style="checkbox"
|
|
373
341
|
labelHidden
|
|
374
|
-
label={getColumnLabel(
|
|
375
|
-
column
|
|
376
|
-
)}
|
|
342
|
+
label={getColumnLabel(column)}
|
|
377
343
|
checked={visible}
|
|
378
|
-
onChange={() =>
|
|
379
|
-
column.toggleVisibility()
|
|
380
|
-
}
|
|
344
|
+
onChange={() => column.toggleVisibility()}
|
|
381
345
|
/>
|
|
382
|
-
<span className="text-xs">
|
|
383
|
-
{getColumnLabel(
|
|
384
|
-
column
|
|
385
|
-
)}
|
|
386
|
-
</span>
|
|
346
|
+
<span className="text-xs">{getColumnLabel(column)}</span>
|
|
387
347
|
</div>
|
|
388
348
|
)
|
|
389
349
|
})}
|
|
@@ -400,48 +360,34 @@ export function DataTable<TData extends RowData>({
|
|
|
400
360
|
type="button"
|
|
401
361
|
variant="ghost"
|
|
402
362
|
size="sm"
|
|
403
|
-
onClick={() =>
|
|
404
|
-
setColumnFilters([])
|
|
405
|
-
}
|
|
363
|
+
onClick={() => setColumnFilters([])}
|
|
406
364
|
className="text-muted-foreground hover:text-foreground"
|
|
407
365
|
>
|
|
408
|
-
<HugeiconsIcon
|
|
409
|
-
icon={Cancel01Icon}
|
|
410
|
-
className="size-3"
|
|
411
|
-
/>
|
|
366
|
+
<HugeiconsIcon icon={Cancel01Icon} className="size-3" />
|
|
412
367
|
Clear all
|
|
413
368
|
</Button>
|
|
414
369
|
)}
|
|
415
370
|
</div>
|
|
416
371
|
{filterableColumns.length === 0 ? (
|
|
417
|
-
<p className="text-xs text-muted-foreground/60">
|
|
418
|
-
No filterable columns.
|
|
419
|
-
</p>
|
|
372
|
+
<p className="text-xs text-muted-foreground/60">No filterable columns.</p>
|
|
420
373
|
) : (
|
|
421
374
|
<div className="flex flex-col gap-3">
|
|
422
|
-
{filterableColumns.map(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
column.
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
).meta
|
|
439
|
-
?.filterVariant ===
|
|
440
|
-
"date"
|
|
441
|
-
}
|
|
442
|
-
/>
|
|
443
|
-
)
|
|
444
|
-
)}
|
|
375
|
+
{filterableColumns.map((column) => (
|
|
376
|
+
<FilterRow
|
|
377
|
+
key={column.id}
|
|
378
|
+
column={column}
|
|
379
|
+
data={data}
|
|
380
|
+
skip={skip}
|
|
381
|
+
isArrayColumn={isArrayValuedColumn(data, column.id)}
|
|
382
|
+
isDateColumn={
|
|
383
|
+
(
|
|
384
|
+
column.columnDef as {
|
|
385
|
+
meta?: DataTableColumnMeta
|
|
386
|
+
}
|
|
387
|
+
).meta?.filterVariant === "date"
|
|
388
|
+
}
|
|
389
|
+
/>
|
|
390
|
+
))}
|
|
445
391
|
</div>
|
|
446
392
|
)}
|
|
447
393
|
</div>
|
|
@@ -449,14 +395,9 @@ export function DataTable<TData extends RowData>({
|
|
|
449
395
|
|
|
450
396
|
{bulkActions && selectedCount > 0 && (
|
|
451
397
|
<div className="flex items-center gap-3 rounded-full border border-border/40 bg-foreground/[0.035] py-1.5 pr-1.5 pl-4">
|
|
452
|
-
<span className="text-xs font-medium">
|
|
453
|
-
{selectedCount} selected
|
|
454
|
-
</span>
|
|
398
|
+
<span className="text-xs font-medium">{selectedCount} selected</span>
|
|
455
399
|
<div className="h-4 w-px bg-input/40" />
|
|
456
|
-
{bulkActions(
|
|
457
|
-
selectedRows,
|
|
458
|
-
clearSelection
|
|
459
|
-
)}
|
|
400
|
+
{bulkActions(selectedRows, clearSelection)}
|
|
460
401
|
<Button
|
|
461
402
|
type="button"
|
|
462
403
|
variant="ghost"
|
|
@@ -471,76 +412,66 @@ export function DataTable<TData extends RowData>({
|
|
|
471
412
|
|
|
472
413
|
<Table
|
|
473
414
|
aria-label={ariaLabel}
|
|
474
|
-
className={cn(
|
|
475
|
-
"divide-none!",
|
|
476
|
-
isLoading &&
|
|
477
|
-
"opacity-60 transition-opacity"
|
|
478
|
-
)}
|
|
415
|
+
className={cn("divide-none!", isLoading && "opacity-60 transition-opacity")}
|
|
479
416
|
>
|
|
480
417
|
<TableHeader>
|
|
481
|
-
{table
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
418
|
+
{table.getHeaderGroups().map((headerGroup) => (
|
|
419
|
+
<TableRow
|
|
420
|
+
key={headerGroup.id}
|
|
421
|
+
className="border-b border-border/40 hover:bg-transparent"
|
|
422
|
+
>
|
|
423
|
+
{headerGroup.headers.map((header) => (
|
|
424
|
+
<TableHead
|
|
425
|
+
key={header.id}
|
|
426
|
+
aria-sort={
|
|
427
|
+
header.column.getCanSort()
|
|
428
|
+
? header.column.getIsSorted() === "asc"
|
|
429
|
+
? "ascending"
|
|
430
|
+
: header.column.getIsSorted() === "desc"
|
|
431
|
+
? "descending"
|
|
432
|
+
: "none"
|
|
433
|
+
: undefined
|
|
434
|
+
}
|
|
435
|
+
>
|
|
436
|
+
{header.isPlaceholder ? null : header.column.getCanSort() ? (
|
|
437
|
+
<button
|
|
438
|
+
type="button"
|
|
439
|
+
className="flex w-fit items-center gap-1 text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-offset-2"
|
|
440
|
+
onClick={header.column.getToggleSortingHandler()}
|
|
492
441
|
>
|
|
493
|
-
{
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
onClick={header.column.getToggleSortingHandler()}
|
|
497
|
-
>
|
|
498
|
-
{flexRender(
|
|
499
|
-
header
|
|
500
|
-
.column
|
|
501
|
-
.columnDef
|
|
502
|
-
.header,
|
|
503
|
-
header.getContext()
|
|
504
|
-
)}
|
|
505
|
-
<div className="flex flex-col">
|
|
506
|
-
<HugeiconsIcon
|
|
507
|
-
icon={
|
|
508
|
-
ChevronUpIcon
|
|
509
|
-
}
|
|
510
|
-
className={cn(
|
|
511
|
-
"size-3 opacity-20",
|
|
512
|
-
header.column.getIsSorted() ===
|
|
513
|
-
"asc" &&
|
|
514
|
-
"opacity-100"
|
|
515
|
-
)}
|
|
516
|
-
/>
|
|
517
|
-
<HugeiconsIcon
|
|
518
|
-
icon={
|
|
519
|
-
ChevronDownIcon
|
|
520
|
-
}
|
|
521
|
-
className={cn(
|
|
522
|
-
"-mt-1.5 size-3 opacity-20",
|
|
523
|
-
header.column.getIsSorted() ===
|
|
524
|
-
"desc" &&
|
|
525
|
-
"opacity-100"
|
|
526
|
-
)}
|
|
527
|
-
/>
|
|
528
|
-
</div>
|
|
529
|
-
</div>
|
|
530
|
-
) : (
|
|
531
|
-
flexRender(
|
|
532
|
-
header
|
|
533
|
-
.column
|
|
534
|
-
.columnDef
|
|
535
|
-
.header,
|
|
536
|
-
header.getContext()
|
|
537
|
-
)
|
|
442
|
+
{flexRender(
|
|
443
|
+
header.column.columnDef.header,
|
|
444
|
+
header.getContext()
|
|
538
445
|
)}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
446
|
+
<div className="flex flex-col">
|
|
447
|
+
<HugeiconsIcon
|
|
448
|
+
icon={ChevronUpIcon}
|
|
449
|
+
className={cn(
|
|
450
|
+
"size-3 opacity-20",
|
|
451
|
+
header.column.getIsSorted() === "asc" &&
|
|
452
|
+
"opacity-100"
|
|
453
|
+
)}
|
|
454
|
+
/>
|
|
455
|
+
<HugeiconsIcon
|
|
456
|
+
icon={ChevronDownIcon}
|
|
457
|
+
className={cn(
|
|
458
|
+
"-mt-1.5 size-3 opacity-20",
|
|
459
|
+
header.column.getIsSorted() === "desc" &&
|
|
460
|
+
"opacity-100"
|
|
461
|
+
)}
|
|
462
|
+
/>
|
|
463
|
+
</div>
|
|
464
|
+
</button>
|
|
465
|
+
) : (
|
|
466
|
+
flexRender(
|
|
467
|
+
header.column.columnDef.header,
|
|
468
|
+
header.getContext()
|
|
469
|
+
)
|
|
470
|
+
)}
|
|
471
|
+
</TableHead>
|
|
472
|
+
))}
|
|
473
|
+
</TableRow>
|
|
474
|
+
))}
|
|
544
475
|
</TableHeader>
|
|
545
476
|
<TableBody>
|
|
546
477
|
{rows.length ? (
|
|
@@ -549,69 +480,43 @@ export function DataTable<TData extends RowData>({
|
|
|
549
480
|
key={row.id}
|
|
550
481
|
className={cn(
|
|
551
482
|
"border-b border-border/25 transition-colors last:border-b-0 hover:bg-foreground/[0.025]",
|
|
552
|
-
onRowClick &&
|
|
553
|
-
"cursor-pointer"
|
|
483
|
+
onRowClick && "cursor-pointer"
|
|
554
484
|
)}
|
|
555
|
-
data-state={
|
|
556
|
-
|
|
557
|
-
? "selected"
|
|
558
|
-
: undefined
|
|
559
|
-
}
|
|
560
|
-
onClick={() => {
|
|
485
|
+
data-state={row.getIsSelected() ? "selected" : undefined}
|
|
486
|
+
onClick={(event) => {
|
|
561
487
|
if (
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
row.original
|
|
488
|
+
event.target instanceof Element &&
|
|
489
|
+
event.target.closest(
|
|
490
|
+
"a,button,input,select,textarea,[role='button'],[data-stop-row-click]"
|
|
566
491
|
)
|
|
492
|
+
)
|
|
493
|
+
return
|
|
494
|
+
if (!onSelectedRowsChange) {
|
|
495
|
+
onRowClick?.(row.original)
|
|
567
496
|
return
|
|
568
497
|
}
|
|
569
498
|
row.toggleSelected()
|
|
570
|
-
onSelectedRowsChange(
|
|
571
|
-
selectedRows
|
|
572
|
-
)
|
|
573
499
|
}}
|
|
574
500
|
>
|
|
575
|
-
{row
|
|
576
|
-
.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
>
|
|
581
|
-
{flexRender(
|
|
582
|
-
cell.column
|
|
583
|
-
.columnDef
|
|
584
|
-
.cell,
|
|
585
|
-
cell.getContext()
|
|
586
|
-
)}
|
|
587
|
-
</TableCell>
|
|
588
|
-
))}
|
|
501
|
+
{row.getVisibleCells().map((cell) => (
|
|
502
|
+
<TableCell key={cell.id}>
|
|
503
|
+
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
504
|
+
</TableCell>
|
|
505
|
+
))}
|
|
589
506
|
</TableRow>
|
|
590
507
|
))
|
|
591
508
|
) : (
|
|
592
509
|
<TableRow>
|
|
593
|
-
<TableCell
|
|
594
|
-
colSpan={columnCount}
|
|
595
|
-
className="h-24 text-center"
|
|
596
|
-
>
|
|
510
|
+
<TableCell colSpan={columnCount} className="h-24 text-center">
|
|
597
511
|
{emptyMessage}
|
|
598
512
|
</TableCell>
|
|
599
513
|
</TableRow>
|
|
600
514
|
)}
|
|
601
515
|
</TableBody>
|
|
602
|
-
{footer && (
|
|
603
|
-
<TableFooter>
|
|
604
|
-
{footer(columnCount)}
|
|
605
|
-
</TableFooter>
|
|
606
|
-
)}
|
|
516
|
+
{footer && <TableFooter>{footer(columnCount)}</TableFooter>}
|
|
607
517
|
</Table>
|
|
608
518
|
|
|
609
|
-
{pagination &&
|
|
610
|
-
<DataTablePagination
|
|
611
|
-
table={table}
|
|
612
|
-
pageSizeOptions={pageSizeOptions}
|
|
613
|
-
/>
|
|
614
|
-
)}
|
|
519
|
+
{pagination && <DataTablePagination table={table} pageSizeOptions={pageSizeOptions} />}
|
|
615
520
|
</div>
|
|
616
521
|
)
|
|
617
522
|
}
|