@passui/tanstack 0.2.6 → 0.3.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/dist/{types/src/auth-shell → auth-shell}/auth-shell.d.ts +3 -3
- package/dist/auth-shell/auth-shell.js +17 -0
- package/dist/auth-shell.d.ts +2 -0
- package/dist/auth-shell.js +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.js +3 -0
- package/dist/{types/src/document → document}/compose-viewport.d.ts +11 -11
- package/dist/document/compose-viewport.js +43 -0
- package/dist/document.d.ts +2 -0
- package/dist/document.js +1 -0
- package/dist/form-fields/fields.d.ts +30 -0
- package/dist/form-fields/fields.js +160 -0
- package/dist/form-fields/selection.d.ts +21 -0
- package/dist/form-fields/selection.js +73 -0
- package/dist/form-fields/submit.d.ts +3 -0
- package/dist/form-fields/submit.js +26 -0
- package/dist/form-fields.d.ts +7 -0
- package/dist/form-fields.js +7 -0
- package/dist/forms/contexts.js +4 -0
- package/dist/{types/src/forms → forms}/elements/form-alert.d.ts +4 -4
- package/dist/forms/elements/form-alert.js +19 -0
- package/dist/forms/fields/avatar-picker.d.ts +10 -0
- package/dist/forms/fields/avatar-picker.js +228 -0
- package/dist/forms/fields/avatar.d.ts +30 -0
- package/dist/forms/fields/avatar.js +188 -0
- package/dist/forms/fields/checkbox.d.ts +2 -0
- package/dist/forms/fields/index.d.ts +21 -0
- package/dist/forms/fields/index.js +15 -0
- package/dist/forms/fields/input.d.ts +2 -0
- package/dist/forms/fields/multiselect.d.ts +2 -0
- package/dist/forms/fields/otp.d.ts +2 -0
- package/dist/forms/fields/radio-card.d.ts +2 -0
- package/dist/forms/fields/switch.d.ts +2 -0
- package/dist/forms/fields/textarea.d.ts +2 -0
- package/dist/forms.d.ts +45 -0
- package/dist/forms.js +16 -0
- package/dist/mutation/use-app-mutation.d.ts +23 -0
- package/dist/mutation/use-app-mutation.js +41 -0
- package/dist/mutation.d.ts +3 -0
- package/dist/mutation.js +3 -0
- package/dist/route-boundary/default-boundary.d.ts +2 -0
- package/dist/route-boundary/default-boundary.js +40 -0
- package/dist/route-boundary/default-loader.d.ts +6 -0
- package/dist/route-boundary/default-loader.js +17 -0
- package/dist/{types/src/route-boundary → route-boundary}/not-founder.d.ts +2 -2
- package/dist/route-boundary/not-founder.js +44 -0
- package/dist/route-boundary.d.ts +4 -0
- package/dist/route-boundary.js +4 -0
- package/dist/settings/setting-list.d.ts +51 -0
- package/dist/settings/setting-list.js +122 -0
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +1 -0
- package/dist/{types/src/shared → shared}/optimistic.d.ts +2 -2
- package/dist/shared/optimistic.js +16 -0
- package/dist/{types/src/shared → shared}/table.d.ts +7 -7
- package/dist/shared/table.js +12 -0
- package/dist/tables/columns.d.ts +3 -0
- package/dist/tables/columns.js +21 -0
- package/dist/tables/data-table.d.ts +76 -0
- package/dist/tables/data-table.js +307 -0
- package/dist/tables/filter-row.js +137 -0
- package/dist/tables/pagination.d.ts +8 -0
- package/dist/tables/pagination.js +86 -0
- package/dist/tables.d.ts +4 -0
- package/dist/tables.js +4 -0
- package/package.json +129 -128
- package/src/styles.css +1 -0
- package/dist/types/src/auth-shell/index.d.ts +0 -1
- package/dist/types/src/document/index.d.ts +0 -1
- package/dist/types/src/form-fields/fields.d.ts +0 -24
- package/dist/types/src/form-fields/index.d.ts +0 -2
- package/dist/types/src/form-fields/selection.d.ts +0 -21
- package/dist/types/src/form-fields/submit.d.ts +0 -3
- package/dist/types/src/forms/contexts.d.ts +0 -1
- package/dist/types/src/forms/elements/submit.d.ts +0 -1
- package/dist/types/src/forms/fields/avatar-picker.d.ts +0 -30
- package/dist/types/src/forms/fields/avatar.d.ts +0 -30
- package/dist/types/src/forms/fields/checkbox.d.ts +0 -1
- package/dist/types/src/forms/fields/index.d.ts +0 -21
- package/dist/types/src/forms/fields/input.d.ts +0 -1
- package/dist/types/src/forms/fields/multiselect.d.ts +0 -1
- package/dist/types/src/forms/fields/otp.d.ts +0 -1
- package/dist/types/src/forms/fields/radio-card.d.ts +0 -1
- package/dist/types/src/forms/fields/switch.d.ts +0 -1
- package/dist/types/src/forms/fields/textarea.d.ts +0 -1
- package/dist/types/src/forms/index.d.ts +0 -41
- package/dist/types/src/mutation/index.d.ts +0 -1
- package/dist/types/src/mutation/use-app-mutation.d.ts +0 -22
- package/dist/types/src/route-boundary/default-boundary.d.ts +0 -2
- package/dist/types/src/route-boundary/default-loader.d.ts +0 -6
- package/dist/types/src/route-boundary/index.d.ts +0 -3
- package/dist/types/src/settings/index.d.ts +0 -1
- package/dist/types/src/settings/setting-list.d.ts +0 -51
- package/dist/types/src/shared/index.d.ts +0 -2
- package/dist/types/src/tables/columns.d.ts +0 -3
- package/dist/types/src/tables/data-table.d.ts +0 -76
- package/dist/types/src/tables/filter-row.d.ts +0 -9
- package/dist/types/src/tables/index.d.ts +0 -3
- package/dist/types/src/tables/pagination.d.ts +0 -8
- package/dist/types/src/tables/utils.d.ts +0 -1
- package/src/auth-shell/auth-shell.tsx +0 -16
- package/src/auth-shell/index.ts +0 -1
- package/src/document/compose-viewport.tsx +0 -80
- package/src/document/index.ts +0 -1
- package/src/form-fields/fields.tsx +0 -147
- package/src/form-fields/index.ts +0 -2
- package/src/form-fields/selection.tsx +0 -109
- package/src/form-fields/submit.tsx +0 -35
- package/src/forms/contexts.ts +0 -4
- package/src/forms/elements/form-alert.tsx +0 -21
- package/src/forms/elements/submit.tsx +0 -1
- package/src/forms/fields/avatar-picker.tsx +0 -319
- package/src/forms/fields/avatar.tsx +0 -269
- package/src/forms/fields/checkbox.tsx +0 -1
- package/src/forms/fields/index.ts +0 -29
- package/src/forms/fields/input.tsx +0 -1
- package/src/forms/fields/multiselect.tsx +0 -1
- package/src/forms/fields/otp.tsx +0 -1
- package/src/forms/fields/radio-card.tsx +0 -1
- package/src/forms/fields/switch.tsx +0 -1
- package/src/forms/fields/textarea.tsx +0 -1
- package/src/forms/index.ts +0 -26
- package/src/mutation/index.ts +0 -1
- package/src/mutation/use-app-mutation.ts +0 -100
- package/src/route-boundary/default-boundary.tsx +0 -46
- package/src/route-boundary/default-loader.tsx +0 -23
- package/src/route-boundary/index.ts +0 -3
- package/src/route-boundary/not-founder.tsx +0 -39
- package/src/settings/index.ts +0 -1
- package/src/settings/setting-list.tsx +0 -221
- package/src/shared/index.ts +0 -2
- package/src/shared/optimistic.ts +0 -19
- package/src/shared/table.ts +0 -12
- package/src/tables/columns.tsx +0 -30
- package/src/tables/data-table.tsx +0 -522
- package/src/tables/filter-row.tsx +0 -196
- package/src/tables/index.ts +0 -3
- package/src/tables/pagination.tsx +0 -85
- package/src/tables/utils.ts +0 -5
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { FilterRow } from "./filter-row.js";
|
|
2
|
+
import { DataTablePagination } from "./pagination.js";
|
|
3
|
+
import { columnIdOf, getColumnLabel, isArrayValuedColumn } from "../shared/table.js";
|
|
4
|
+
import { Button } from "@passui/react/button";
|
|
5
|
+
import { Spinner } from "@passui/react/spinner";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { Checkbox } from "@passui/react/checkbox";
|
|
8
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
9
|
+
import { cn } from "@passui/react/cn";
|
|
10
|
+
import { ChevronDownIcon } from "@passui/icons/chevron-down";
|
|
11
|
+
import { ChevronUpIcon } from "@passui/icons/chevron-up";
|
|
12
|
+
import { CloseIcon } from "@passui/icons/close";
|
|
13
|
+
import { SearchField } from "@passui/react/search-field";
|
|
14
|
+
import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow } from "@passui/react/table";
|
|
15
|
+
import { columnFilteringFeature, columnVisibilityFeature, createFilteredRowModel, createPaginatedRowModel, createSortedRowModel, filterFn_arrIncludes, filterFn_arrIncludesSome, filterFn_equals, filterFn_inDateRange, filterFn_inNumberRange, filterFn_includesString, flexRender, globalFilteringFeature, rowPaginationFeature, rowSelectionFeature, rowSortingFeature, sortFn_alphanumeric, sortFn_datetime, sortFn_text, tableFeatures, useTable } from "@tanstack/react-table";
|
|
16
|
+
// src/tables/data-table.tsx
|
|
17
|
+
const baseTableFeatures = tableFeatures({
|
|
18
|
+
globalFilteringFeature,
|
|
19
|
+
columnFilteringFeature,
|
|
20
|
+
rowSortingFeature,
|
|
21
|
+
rowPaginationFeature,
|
|
22
|
+
columnVisibilityFeature,
|
|
23
|
+
rowSelectionFeature,
|
|
24
|
+
filteredRowModel: createFilteredRowModel(),
|
|
25
|
+
sortedRowModel: createSortedRowModel(),
|
|
26
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
27
|
+
filterFns: {
|
|
28
|
+
includesString: filterFn_includesString,
|
|
29
|
+
inNumberRange: filterFn_inNumberRange,
|
|
30
|
+
equals: filterFn_equals,
|
|
31
|
+
arrIncludes: filterFn_arrIncludes,
|
|
32
|
+
arrIncludesSome: filterFn_arrIncludesSome,
|
|
33
|
+
inDateRange: filterFn_inDateRange
|
|
34
|
+
},
|
|
35
|
+
sortFns: {
|
|
36
|
+
text: sortFn_text,
|
|
37
|
+
alphanumeric: sortFn_alphanumeric,
|
|
38
|
+
datetime: sortFn_datetime
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
/** A pill that opens the Columns or Filters panel, with a quiet count when something is hidden or applied. */
|
|
42
|
+
function ToolbarToggle({ label, count, open, onClick }) {
|
|
43
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
44
|
+
type: "button",
|
|
45
|
+
"aria-expanded": open,
|
|
46
|
+
onClick,
|
|
47
|
+
className: cn("border-border/40 text-caption flex h-8 cursor-pointer items-center gap-1.5 rounded-full border px-3 transition-colors", open || count > 0 ? "bg-foreground/[0.07] text-foreground" : "text-muted-foreground hover:bg-foreground/[0.04] hover:text-foreground"),
|
|
48
|
+
children: [
|
|
49
|
+
label,
|
|
50
|
+
count > 0 && /* @__PURE__ */ jsx("span", {
|
|
51
|
+
className: "bg-foreground/10 rounded-full px-1.5 tabular-nums",
|
|
52
|
+
children: count
|
|
53
|
+
}),
|
|
54
|
+
/* @__PURE__ */ jsx(ChevronDownIcon, {
|
|
55
|
+
size: 12,
|
|
56
|
+
className: cn("transition-transform duration-150", open && "rotate-180")
|
|
57
|
+
})
|
|
58
|
+
]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Self-contained table: pass `data` + `columns`, get sorting, pagination,
|
|
63
|
+
* search, column visibility, per-column filters, and row selection for
|
|
64
|
+
* free. There's no `useTable` state to wire up on the caller's side.
|
|
65
|
+
*/
|
|
66
|
+
function DataTable({ data, columns, getRowId, emptyMessage = "No results.", searchPlaceholder = "Search…", bulkActions, pagination = true, pageSizeOptions, onSelectedRowsChange, onRowClick, footer, isLoading = false, initialColumnVisibility = {}, "aria-label": ariaLabel }) {
|
|
67
|
+
const [searchInput, setSearchInput] = useState("");
|
|
68
|
+
const [globalFilter, setGlobalFilter] = useState("");
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
const timeout = setTimeout(() => setGlobalFilter(searchInput), 200);
|
|
71
|
+
return () => clearTimeout(timeout);
|
|
72
|
+
}, [searchInput]);
|
|
73
|
+
const [sorting, setSorting] = useState([]);
|
|
74
|
+
const [columnFilters, setColumnFilters] = useState([]);
|
|
75
|
+
const [columnVisibility, setColumnVisibility] = useState(initialColumnVisibility);
|
|
76
|
+
const [rowSelection, setRowSelection] = useState({});
|
|
77
|
+
const lastReportedSelection = useRef(rowSelection);
|
|
78
|
+
const [columnsOpen, setColumnsOpen] = useState(false);
|
|
79
|
+
const [filtersOpen, setFiltersOpen] = useState(false);
|
|
80
|
+
const augmentedColumns = useMemo(() => columns.map((col) => {
|
|
81
|
+
if (col.filterFn) return col;
|
|
82
|
+
const colId = columnIdOf(col);
|
|
83
|
+
if (!colId) return col;
|
|
84
|
+
if (col.meta?.filterVariant === "date") return {
|
|
85
|
+
...col,
|
|
86
|
+
filterFn: filterFn_inDateRange
|
|
87
|
+
};
|
|
88
|
+
if (isArrayValuedColumn(data, colId)) return {
|
|
89
|
+
...col,
|
|
90
|
+
filterFn: filterFn_arrIncludesSome
|
|
91
|
+
};
|
|
92
|
+
return col;
|
|
93
|
+
}), [columns, data]);
|
|
94
|
+
const table = useTable({
|
|
95
|
+
features: baseTableFeatures,
|
|
96
|
+
data,
|
|
97
|
+
columns: augmentedColumns,
|
|
98
|
+
getRowId,
|
|
99
|
+
enableRowSelection: true,
|
|
100
|
+
state: {
|
|
101
|
+
globalFilter,
|
|
102
|
+
sorting,
|
|
103
|
+
columnFilters,
|
|
104
|
+
columnVisibility,
|
|
105
|
+
rowSelection
|
|
106
|
+
},
|
|
107
|
+
onGlobalFilterChange: setGlobalFilter,
|
|
108
|
+
onSortingChange: setSorting,
|
|
109
|
+
onColumnFiltersChange: setColumnFilters,
|
|
110
|
+
onColumnVisibilityChange: setColumnVisibility,
|
|
111
|
+
onRowSelectionChange: setRowSelection,
|
|
112
|
+
globalFilterFn: "auto"
|
|
113
|
+
});
|
|
114
|
+
const toggleableColumns = table.getAllColumns().filter((c) => c.getCanHide());
|
|
115
|
+
const hiddenCount = toggleableColumns.filter((c) => !c.getIsVisible()).length;
|
|
116
|
+
const skip = ["select", "actions"];
|
|
117
|
+
const filterableColumns = table.getAllColumns().filter((c) => c.getCanFilter() && !skip.includes(c.id) && c.accessorFn !== void 0);
|
|
118
|
+
const activeFilterCount = columnFilters.length;
|
|
119
|
+
const selectedCount = Object.values(rowSelection).filter(Boolean).length;
|
|
120
|
+
const selectedRows = useMemo(() => data.filter((row) => rowSelection[getRowId(row)]), [
|
|
121
|
+
data,
|
|
122
|
+
getRowId,
|
|
123
|
+
rowSelection
|
|
124
|
+
]);
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (lastReportedSelection.current === rowSelection) return;
|
|
127
|
+
lastReportedSelection.current = rowSelection;
|
|
128
|
+
onSelectedRowsChange?.(selectedRows);
|
|
129
|
+
}, [
|
|
130
|
+
rowSelection,
|
|
131
|
+
selectedRows,
|
|
132
|
+
onSelectedRowsChange
|
|
133
|
+
]);
|
|
134
|
+
const clearSelection = () => setRowSelection({});
|
|
135
|
+
const rows = table.getRowModel().rows;
|
|
136
|
+
const columnCount = table.getVisibleLeafColumns().length;
|
|
137
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
138
|
+
className: "[&_div]:no-scrollbar flex flex-col gap-3 [&_tr]:border-none!",
|
|
139
|
+
children: [
|
|
140
|
+
/* @__PURE__ */ jsxs("div", {
|
|
141
|
+
className: "flex flex-wrap items-center gap-3",
|
|
142
|
+
children: [
|
|
143
|
+
/* @__PURE__ */ jsx(SearchField, {
|
|
144
|
+
className: "w-full min-w-0 sm:max-w-sm",
|
|
145
|
+
"aria-label": searchPlaceholder,
|
|
146
|
+
placeholder: searchPlaceholder,
|
|
147
|
+
autoComplete: "off",
|
|
148
|
+
value: searchInput,
|
|
149
|
+
onChange: (event) => setSearchInput(event.target.value)
|
|
150
|
+
}),
|
|
151
|
+
isLoading && /* @__PURE__ */ jsx(Spinner, { className: "shrink-0" }),
|
|
152
|
+
/* @__PURE__ */ jsxs("div", {
|
|
153
|
+
className: "flex shrink-0 items-center gap-1.5 sm:ml-auto",
|
|
154
|
+
children: [/* @__PURE__ */ jsx(ToolbarToggle, {
|
|
155
|
+
label: "Columns",
|
|
156
|
+
count: hiddenCount,
|
|
157
|
+
open: columnsOpen,
|
|
158
|
+
onClick: () => {
|
|
159
|
+
setColumnsOpen((o) => !o);
|
|
160
|
+
setFiltersOpen(false);
|
|
161
|
+
}
|
|
162
|
+
}), /* @__PURE__ */ jsx(ToolbarToggle, {
|
|
163
|
+
label: "Filters",
|
|
164
|
+
count: activeFilterCount,
|
|
165
|
+
open: filtersOpen,
|
|
166
|
+
onClick: () => {
|
|
167
|
+
setFiltersOpen((o) => !o);
|
|
168
|
+
setColumnsOpen(false);
|
|
169
|
+
}
|
|
170
|
+
})]
|
|
171
|
+
})
|
|
172
|
+
]
|
|
173
|
+
}),
|
|
174
|
+
columnsOpen && /* @__PURE__ */ jsxs("div", {
|
|
175
|
+
className: "border-border/40 bg-foreground/[0.025] flex flex-col gap-2 rounded-2xl border p-4",
|
|
176
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
177
|
+
className: "flex items-center justify-between",
|
|
178
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
179
|
+
className: "text-caption",
|
|
180
|
+
children: "Columns"
|
|
181
|
+
}), hiddenCount > 0 && /* @__PURE__ */ jsx(Button, {
|
|
182
|
+
type: "button",
|
|
183
|
+
variant: "ghost",
|
|
184
|
+
size: "sm",
|
|
185
|
+
onClick: () => table.resetColumnVisibility(),
|
|
186
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
187
|
+
children: "Show all"
|
|
188
|
+
})]
|
|
189
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
190
|
+
className: "flex flex-wrap items-center gap-4",
|
|
191
|
+
children: toggleableColumns.map((column) => {
|
|
192
|
+
const visible = column.getIsVisible();
|
|
193
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
194
|
+
className: "flex items-center gap-2",
|
|
195
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
196
|
+
"aria-label": getColumnLabel(column),
|
|
197
|
+
checked: visible,
|
|
198
|
+
onCheckedChange: () => column.toggleVisibility()
|
|
199
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
200
|
+
className: "text-caption",
|
|
201
|
+
children: getColumnLabel(column)
|
|
202
|
+
})]
|
|
203
|
+
}, column.id);
|
|
204
|
+
})
|
|
205
|
+
})]
|
|
206
|
+
}),
|
|
207
|
+
filtersOpen && /* @__PURE__ */ jsxs("div", {
|
|
208
|
+
className: "border-border/40 bg-foreground/[0.025] flex flex-col gap-2 rounded-2xl border p-4",
|
|
209
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
210
|
+
className: "flex items-center justify-between",
|
|
211
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
212
|
+
className: "text-caption",
|
|
213
|
+
children: "Filters"
|
|
214
|
+
}), activeFilterCount > 0 && /* @__PURE__ */ jsxs(Button, {
|
|
215
|
+
type: "button",
|
|
216
|
+
variant: "ghost",
|
|
217
|
+
size: "sm",
|
|
218
|
+
onClick: () => setColumnFilters([]),
|
|
219
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
220
|
+
children: [/* @__PURE__ */ jsx(CloseIcon, { size: 12 }), "Clear all"]
|
|
221
|
+
})]
|
|
222
|
+
}), filterableColumns.length === 0 ? /* @__PURE__ */ jsx("p", {
|
|
223
|
+
className: "text-caption text-muted-foreground/60",
|
|
224
|
+
children: "No filterable columns."
|
|
225
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
226
|
+
className: "flex flex-col gap-3",
|
|
227
|
+
children: filterableColumns.map((column) => /* @__PURE__ */ jsx(FilterRow, {
|
|
228
|
+
column,
|
|
229
|
+
data,
|
|
230
|
+
skip,
|
|
231
|
+
isArrayColumn: isArrayValuedColumn(data, column.id),
|
|
232
|
+
isDateColumn: column.columnDef.meta?.filterVariant === "date"
|
|
233
|
+
}, column.id))
|
|
234
|
+
})]
|
|
235
|
+
}),
|
|
236
|
+
bulkActions && selectedCount > 0 && /* @__PURE__ */ jsxs("div", {
|
|
237
|
+
className: "border-border/40 bg-foreground/[0.035] flex items-center gap-3 rounded-full border py-1.5 pr-1.5 pl-4",
|
|
238
|
+
children: [
|
|
239
|
+
/* @__PURE__ */ jsxs("span", {
|
|
240
|
+
className: "text-caption font-medium",
|
|
241
|
+
children: [selectedCount, " selected"]
|
|
242
|
+
}),
|
|
243
|
+
/* @__PURE__ */ jsx("div", { className: "bg-input/40 h-4 w-px" }),
|
|
244
|
+
bulkActions(selectedRows, clearSelection),
|
|
245
|
+
/* @__PURE__ */ jsx(Button, {
|
|
246
|
+
type: "button",
|
|
247
|
+
variant: "ghost",
|
|
248
|
+
size: "sm",
|
|
249
|
+
onClick: clearSelection,
|
|
250
|
+
className: "text-muted-foreground hover:text-foreground ml-auto",
|
|
251
|
+
children: "Clear"
|
|
252
|
+
})
|
|
253
|
+
]
|
|
254
|
+
}),
|
|
255
|
+
/* @__PURE__ */ jsxs(Table, {
|
|
256
|
+
"aria-label": ariaLabel,
|
|
257
|
+
className: cn("divide-none!", isLoading && "opacity-60 transition-opacity"),
|
|
258
|
+
children: [
|
|
259
|
+
/* @__PURE__ */ jsx(TableHeader, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx(TableRow, {
|
|
260
|
+
className: "border-border/40 border-b hover:bg-transparent",
|
|
261
|
+
children: headerGroup.headers.map((header) => /* @__PURE__ */ jsx(TableHead, {
|
|
262
|
+
"aria-sort": header.column.getCanSort() ? header.column.getIsSorted() === "asc" ? "ascending" : header.column.getIsSorted() === "desc" ? "descending" : "none" : void 0,
|
|
263
|
+
children: header.isPlaceholder ? null : header.column.getCanSort() ? /* @__PURE__ */ jsxs("button", {
|
|
264
|
+
type: "button",
|
|
265
|
+
className: "text-muted-foreground hover:text-foreground flex w-fit items-center gap-1 focus-visible:outline-2 focus-visible:outline-offset-2",
|
|
266
|
+
onClick: header.column.getToggleSortingHandler(),
|
|
267
|
+
children: [flexRender(header.column.columnDef.header, header.getContext()), /* @__PURE__ */ jsxs("div", {
|
|
268
|
+
className: "flex flex-col",
|
|
269
|
+
children: [/* @__PURE__ */ jsx(ChevronUpIcon, {
|
|
270
|
+
size: 12,
|
|
271
|
+
className: cn("opacity-20", header.column.getIsSorted() === "asc" && "opacity-100")
|
|
272
|
+
}), /* @__PURE__ */ jsx(ChevronDownIcon, {
|
|
273
|
+
size: 12,
|
|
274
|
+
className: cn("-mt-1.5 opacity-20", header.column.getIsSorted() === "desc" && "opacity-100")
|
|
275
|
+
})]
|
|
276
|
+
})]
|
|
277
|
+
}) : flexRender(header.column.columnDef.header, header.getContext())
|
|
278
|
+
}, header.id))
|
|
279
|
+
}, headerGroup.id)) }),
|
|
280
|
+
/* @__PURE__ */ jsx(TableBody, { children: rows.length ? rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
|
|
281
|
+
className: cn("border-border/25 hover:bg-foreground/[0.025] border-b transition-colors last:border-b-0", onRowClick && "cursor-pointer"),
|
|
282
|
+
"data-state": row.getIsSelected() ? "selected" : void 0,
|
|
283
|
+
onClick: (event) => {
|
|
284
|
+
if (event.target instanceof Element && event.target.closest("a,button,input,select,textarea,[role='button'],[data-stop-row-click]")) return;
|
|
285
|
+
if (!onSelectedRowsChange) {
|
|
286
|
+
onRowClick?.(row.original);
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
row.toggleSelected();
|
|
290
|
+
},
|
|
291
|
+
children: row.getVisibleCells().map((cell) => /* @__PURE__ */ jsx(TableCell, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id))
|
|
292
|
+
}, row.id)) : /* @__PURE__ */ jsx(TableRow, { children: /* @__PURE__ */ jsx(TableCell, {
|
|
293
|
+
colSpan: columnCount,
|
|
294
|
+
className: "h-24 text-center",
|
|
295
|
+
children: emptyMessage
|
|
296
|
+
}) }) }),
|
|
297
|
+
footer && /* @__PURE__ */ jsx(TableFooter, { children: footer(columnCount) })
|
|
298
|
+
]
|
|
299
|
+
}),
|
|
300
|
+
pagination && /* @__PURE__ */ jsx(DataTablePagination, {
|
|
301
|
+
table,
|
|
302
|
+
pageSizeOptions
|
|
303
|
+
})
|
|
304
|
+
]
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
export { DataTable, baseTableFeatures };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { getColumnLabel } from "../shared/table.js";
|
|
2
|
+
import { Button } from "@passui/react/button";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
import { Checkbox } from "@passui/react/checkbox";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { CloseIcon } from "@passui/icons/close";
|
|
7
|
+
// src/tables/filter-row.tsx
|
|
8
|
+
/**
|
|
9
|
+
* The quick-filter checkbox list's own candidate values. For a plain scalar
|
|
10
|
+
* column, one value per distinct cell. For an array-valued column, the
|
|
11
|
+
* individual items across every row's array are what should show up as
|
|
12
|
+
* checkboxes.
|
|
13
|
+
*/
|
|
14
|
+
function useQuickFilterValues(data, colId, exclude, isArrayColumn) {
|
|
15
|
+
return useMemo(() => {
|
|
16
|
+
if (exclude.includes(colId)) return [];
|
|
17
|
+
if (isArrayColumn) {
|
|
18
|
+
const flattened = data.flatMap((row) => {
|
|
19
|
+
const value = row[colId];
|
|
20
|
+
return Array.isArray(value) ? value : [];
|
|
21
|
+
});
|
|
22
|
+
const unique = [...new Set(flattened.filter((v) => v !== null && v !== void 0 && v !== ""))];
|
|
23
|
+
if (unique.length < 2 || unique.length > 20) return [];
|
|
24
|
+
return unique.map((v) => String(v));
|
|
25
|
+
}
|
|
26
|
+
const raw = data.map((row) => row[colId]);
|
|
27
|
+
const unique = [...new Set(raw.filter((v) => v !== null && v !== void 0 && v !== "" && typeof v !== "object"))];
|
|
28
|
+
if (unique.length < 2 || unique.length > 12) return [];
|
|
29
|
+
return unique.map((v) => String(v));
|
|
30
|
+
}, [
|
|
31
|
+
data,
|
|
32
|
+
colId,
|
|
33
|
+
exclude,
|
|
34
|
+
isArrayColumn
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
function FilterRow({ column, data, skip, isArrayColumn, isDateColumn }) {
|
|
38
|
+
const uniqueValues = useQuickFilterValues(data, column.id, skip, isArrayColumn);
|
|
39
|
+
const label = getColumnLabel(column);
|
|
40
|
+
if (isDateColumn) {
|
|
41
|
+
const [from, to] = column.getFilterValue() ?? [];
|
|
42
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
43
|
+
className: "flex items-center gap-3",
|
|
44
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
45
|
+
className: "text-caption2 text-muted-foreground w-20 shrink-0 font-medium",
|
|
46
|
+
children: label
|
|
47
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
48
|
+
className: "flex items-center gap-2",
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ jsx("input", {
|
|
51
|
+
type: "date",
|
|
52
|
+
value: from ?? "",
|
|
53
|
+
onChange: (e) => column.setFilterValue([e.target.value || void 0, to]),
|
|
54
|
+
className: "border-input/40 bg-background text-caption h-7 rounded-none border border-dashed px-2 outline-none"
|
|
55
|
+
}),
|
|
56
|
+
/* @__PURE__ */ jsx("span", {
|
|
57
|
+
className: "text-caption2 text-muted-foreground",
|
|
58
|
+
children: "to"
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx("input", {
|
|
61
|
+
type: "date",
|
|
62
|
+
value: to ?? "",
|
|
63
|
+
onChange: (e) => column.setFilterValue([from, e.target.value || void 0]),
|
|
64
|
+
className: "border-input/40 bg-background text-caption h-7 rounded-none border border-dashed px-2 outline-none"
|
|
65
|
+
}),
|
|
66
|
+
(from || to) && /* @__PURE__ */ jsx(Button, {
|
|
67
|
+
"aria-label": "Clear filter",
|
|
68
|
+
type: "button",
|
|
69
|
+
size: "icon-sm",
|
|
70
|
+
onClick: () => column.setFilterValue(void 0),
|
|
71
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
72
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { size: 12 })
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
})]
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const activeFilter = column.getFilterValue();
|
|
79
|
+
const activeValue = isArrayColumn ? Array.isArray(activeFilter) ? activeFilter[0] : void 0 : activeFilter;
|
|
80
|
+
if (uniqueValues.length > 0) return /* @__PURE__ */ jsxs("div", {
|
|
81
|
+
className: "flex flex-col gap-1",
|
|
82
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
83
|
+
className: "text-caption",
|
|
84
|
+
children: label
|
|
85
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
86
|
+
className: "flex flex-wrap items-center gap-3",
|
|
87
|
+
children: [uniqueValues.map((value) => {
|
|
88
|
+
const active = activeValue === value;
|
|
89
|
+
const setActive = () => column.setFilterValue(active ? void 0 : isArrayColumn ? [value] : value);
|
|
90
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
91
|
+
type: "button",
|
|
92
|
+
className: "flex cursor-pointer items-center gap-2",
|
|
93
|
+
onClick: setActive,
|
|
94
|
+
children: [/* @__PURE__ */ jsx(Checkbox, {
|
|
95
|
+
"aria-label": value,
|
|
96
|
+
checked: active,
|
|
97
|
+
onCheckedChange: () => setActive()
|
|
98
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
99
|
+
className: "text-caption",
|
|
100
|
+
children: value
|
|
101
|
+
})]
|
|
102
|
+
}, value);
|
|
103
|
+
}), activeValue && /* @__PURE__ */ jsxs(Button, {
|
|
104
|
+
type: "button",
|
|
105
|
+
variant: "ghost",
|
|
106
|
+
size: "sm",
|
|
107
|
+
onClick: () => column.setFilterValue(void 0),
|
|
108
|
+
className: "text-muted-foreground hover:text-foreground",
|
|
109
|
+
children: [/* @__PURE__ */ jsx(CloseIcon, { size: 12 }), "Clear"]
|
|
110
|
+
})]
|
|
111
|
+
})]
|
|
112
|
+
});
|
|
113
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
114
|
+
className: "flex items-center gap-3",
|
|
115
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
116
|
+
className: "text-caption2 text-muted-foreground w-20 shrink-0 font-medium capitalize",
|
|
117
|
+
children: label
|
|
118
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
119
|
+
className: "relative max-w-xs flex-1",
|
|
120
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
121
|
+
type: "text",
|
|
122
|
+
placeholder: `Filter ${label.toLowerCase()}…`,
|
|
123
|
+
value: activeValue ?? "",
|
|
124
|
+
onChange: (e) => column.setFilterValue(e.target.value ? isArrayColumn ? [e.target.value] : e.target.value : void 0),
|
|
125
|
+
className: "border-input/40 bg-background text-caption placeholder:text-muted-foreground/40 h-7 w-full rounded-none border border-dashed px-2.5 outline-none"
|
|
126
|
+
}), activeValue && /* @__PURE__ */ jsx(Button, {
|
|
127
|
+
"aria-label": "Clear filter",
|
|
128
|
+
type: "button",
|
|
129
|
+
size: "icon-sm",
|
|
130
|
+
onClick: () => column.setFilterValue(void 0),
|
|
131
|
+
className: "text-muted-foreground hover:text-foreground absolute top-1/2 right-1 -translate-y-1/2",
|
|
132
|
+
children: /* @__PURE__ */ jsx(CloseIcon, { size: 12 })
|
|
133
|
+
})]
|
|
134
|
+
})]
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
export { FilterRow };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DataTableFeatures } from "./data-table.js";
|
|
2
|
+
import { ReactTable, RowData } from "@tanstack/react-table";
|
|
3
|
+
type DataTablePaginationProps<TData extends RowData> = {
|
|
4
|
+
table: ReactTable<DataTableFeatures, TData>;
|
|
5
|
+
pageSizeOptions?: number[];
|
|
6
|
+
};
|
|
7
|
+
export declare function DataTablePagination<TData extends RowData>({ table, pageSizeOptions }: DataTablePaginationProps<TData>): import("react").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Button } from "@passui/react/button";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChevronFirstIcon } from "@passui/icons/chevron-first";
|
|
4
|
+
import { ChevronLastIcon } from "@passui/icons/chevron-last";
|
|
5
|
+
import { ChevronLeftIcon } from "@passui/icons/chevron-left";
|
|
6
|
+
import { ChevronRightIcon } from "@passui/icons/chevron-right";
|
|
7
|
+
import { Select } from "@passui/react/select";
|
|
8
|
+
// src/tables/pagination.tsx
|
|
9
|
+
function DataTablePagination({ table, pageSizeOptions = [
|
|
10
|
+
10,
|
|
11
|
+
20,
|
|
12
|
+
30,
|
|
13
|
+
50
|
|
14
|
+
] }) {
|
|
15
|
+
const { pageIndex, pageSize } = table.state.pagination;
|
|
16
|
+
const pageCount = table.getPageCount();
|
|
17
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
18
|
+
className: "flex flex-wrap items-center gap-x-4 gap-y-2",
|
|
19
|
+
children: [
|
|
20
|
+
/* @__PURE__ */ jsxs("p", {
|
|
21
|
+
className: "text-footnote text-label-secondary shrink-0 whitespace-nowrap",
|
|
22
|
+
children: [
|
|
23
|
+
"Page ",
|
|
24
|
+
pageCount ? pageIndex + 1 : 0,
|
|
25
|
+
" of ",
|
|
26
|
+
pageCount
|
|
27
|
+
]
|
|
28
|
+
}),
|
|
29
|
+
/* @__PURE__ */ jsxs("div", {
|
|
30
|
+
className: "flex items-center gap-1",
|
|
31
|
+
children: [
|
|
32
|
+
/* @__PURE__ */ jsx(Button, {
|
|
33
|
+
variant: "ghost",
|
|
34
|
+
"aria-label": "First page",
|
|
35
|
+
type: "button",
|
|
36
|
+
size: "icon-sm",
|
|
37
|
+
disabled: !table.getCanPreviousPage(),
|
|
38
|
+
onClick: () => table.setPageIndex(0),
|
|
39
|
+
children: /* @__PURE__ */ jsx(ChevronFirstIcon, { size: 16 })
|
|
40
|
+
}),
|
|
41
|
+
/* @__PURE__ */ jsx(Button, {
|
|
42
|
+
variant: "ghost",
|
|
43
|
+
"aria-label": "Previous page",
|
|
44
|
+
type: "button",
|
|
45
|
+
size: "icon-sm",
|
|
46
|
+
disabled: !table.getCanPreviousPage(),
|
|
47
|
+
onClick: () => table.previousPage(),
|
|
48
|
+
children: /* @__PURE__ */ jsx(ChevronLeftIcon, { size: 16 })
|
|
49
|
+
}),
|
|
50
|
+
/* @__PURE__ */ jsx(Button, {
|
|
51
|
+
variant: "ghost",
|
|
52
|
+
"aria-label": "Next page",
|
|
53
|
+
type: "button",
|
|
54
|
+
size: "icon-sm",
|
|
55
|
+
disabled: !table.getCanNextPage(),
|
|
56
|
+
onClick: () => table.nextPage(),
|
|
57
|
+
children: /* @__PURE__ */ jsx(ChevronRightIcon, { size: 16 })
|
|
58
|
+
}),
|
|
59
|
+
/* @__PURE__ */ jsx(Button, {
|
|
60
|
+
variant: "ghost",
|
|
61
|
+
"aria-label": "Last page",
|
|
62
|
+
type: "button",
|
|
63
|
+
size: "icon-sm",
|
|
64
|
+
disabled: !table.getCanNextPage(),
|
|
65
|
+
onClick: () => table.setPageIndex(pageCount - 1),
|
|
66
|
+
children: /* @__PURE__ */ jsx(ChevronLastIcon, { size: 16 })
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
}),
|
|
70
|
+
/* @__PURE__ */ jsx("div", {
|
|
71
|
+
className: "w-20 shrink-0",
|
|
72
|
+
children: /* @__PURE__ */ jsx(Select, {
|
|
73
|
+
className: "w-full",
|
|
74
|
+
"aria-label": "Rows per page",
|
|
75
|
+
value: String(pageSize),
|
|
76
|
+
onValueChange: (value) => value && table.setPageSize(Number(value)),
|
|
77
|
+
items: pageSizeOptions.map((size) => ({
|
|
78
|
+
value: String(size),
|
|
79
|
+
label: String(size)
|
|
80
|
+
}))
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
]
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export { DataTablePagination };
|
package/dist/tables.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { selectColumn } from "./tables/columns.js";
|
|
2
|
+
import { DataTable, DataTableColumnDef, DataTableColumnMeta, DataTableFeatures, baseTableFeatures } from "./tables/data-table.js";
|
|
3
|
+
import { DataTablePagination } from "./tables/pagination.js";
|
|
4
|
+
export { DataTable, DataTableColumnDef, DataTableColumnMeta, DataTableFeatures, DataTablePagination, baseTableFeatures, selectColumn };
|
package/dist/tables.js
ADDED