@dmsi/wedgekit-react 0.0.82 → 0.0.84

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.
Files changed (46) hide show
  1. package/dist/{chunk-6R2HCLEL.js → chunk-37TJJQL3.js} +2 -2
  2. package/dist/{chunk-B6PDZCU7.js → chunk-5GUW4DUY.js} +1 -1
  3. package/dist/{chunk-ATOEGP3V.js → chunk-CKSDMI2Q.js} +14 -7
  4. package/dist/{chunk-2DCVAATK.js → chunk-MQWWNAO3.js} +4 -4
  5. package/dist/{chunk-FOC6LTSX.js → chunk-UPBBOZM3.js} +1 -1
  6. package/dist/{chunk-SWA5WVQO.js → chunk-WNQ53SVY.js} +30 -0
  7. package/dist/components/DataGridCell.cjs +53 -43
  8. package/dist/components/DataGridCell.js +5 -5
  9. package/dist/components/Menu.cjs +17 -14
  10. package/dist/components/Menu.js +3 -3
  11. package/dist/components/MenuOption.cjs +10 -7
  12. package/dist/components/MenuOption.js +2 -2
  13. package/dist/components/Modal.cjs +18 -15
  14. package/dist/components/Modal.js +3 -3
  15. package/dist/components/NestedMenu.cjs +12 -9
  16. package/dist/components/NestedMenu.js +2 -2
  17. package/dist/components/PDFViewer.cjs +21 -18
  18. package/dist/components/PDFViewer.js +3 -3
  19. package/dist/components/ProjectBar.cjs +6 -3
  20. package/dist/components/ProjectBar.js +1 -1
  21. package/dist/components/TopBar.cjs +1 -1
  22. package/dist/components/TopBar.js +1 -1
  23. package/dist/components/{DataGrid.cjs → index.cjs} +1424 -1335
  24. package/dist/components/{DataGrid.js → index.js} +948 -883
  25. package/dist/components/useMenuSystem.cjs +20 -17
  26. package/dist/components/useMenuSystem.js +2 -2
  27. package/dist/hooks/index.cjs +34 -3
  28. package/dist/hooks/index.js +3 -1
  29. package/package.json +6 -1
  30. package/src/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.tsx +32 -0
  31. package/src/components/DataGrid/ColumnSelectorHeaderCell/index.tsx +66 -0
  32. package/src/components/DataGrid/PinnedColumns.tsx +145 -0
  33. package/src/components/DataGrid/TableBody/LoadingCell.tsx +40 -0
  34. package/src/components/DataGrid/TableBody/TableBodyRow.tsx +129 -0
  35. package/src/components/DataGrid/TableBody/index.tsx +159 -0
  36. package/src/components/{DataGrid.tsx → DataGrid/index.tsx} +42 -678
  37. package/src/components/DataGrid/types.ts +86 -0
  38. package/src/components/DataGrid/utils.tsx +15 -0
  39. package/src/components/DataGridCell.tsx +37 -21
  40. package/src/components/TopBar.tsx +1 -1
  41. package/src/components/index.ts +20 -0
  42. package/src/hooks/index.ts +1 -0
  43. package/dist/chunk-AWQSSKCK.js +0 -32
  44. package/dist/components/useInfiniteScroll.cjs +0 -57
  45. package/dist/components/useInfiniteScroll.js +0 -8
  46. /package/src/{components → hooks}/useInfiniteScroll.tsx +0 -0
@@ -1,7 +1,3 @@
1
- "use client";
2
- import {
3
- useInfiniteScroll
4
- } from "../chunk-AWQSSKCK.js";
5
1
  import {
6
2
  Tooltip
7
3
  } from "../chunk-QZGUMB7T.js";
@@ -16,15 +12,17 @@ import {
16
12
  DataGridCell,
17
13
  DragAlongCell,
18
14
  DraggableCellHeader
19
- } from "../chunk-ATOEGP3V.js";
15
+ } from "../chunk-CKSDMI2Q.js";
20
16
  import {
21
17
  Menu
22
- } from "../chunk-6R2HCLEL.js";
23
- import "../chunk-B6PDZCU7.js";
18
+ } from "../chunk-37TJJQL3.js";
19
+ import "../chunk-5GUW4DUY.js";
24
20
  import {
25
21
  MenuOption
26
- } from "../chunk-FOC6LTSX.js";
27
- import "../chunk-SWA5WVQO.js";
22
+ } from "../chunk-UPBBOZM3.js";
23
+ import {
24
+ useInfiniteScroll
25
+ } from "../chunk-WNQ53SVY.js";
28
26
  import {
29
27
  Search
30
28
  } from "../chunk-LP6AZST2.js";
@@ -58,18 +56,15 @@ import {
58
56
  __spreadValues
59
57
  } from "../chunk-ORMEWXMH.js";
60
58
 
61
- // src/components/DataGrid.tsx
62
- import React, { useCallback, useId, useRef, useState } from "react";
59
+ // src/components/DataGrid/index.tsx
60
+ import React3, { useCallback, useId, useState as useState3 } from "react";
63
61
  import {
64
- flexRender,
62
+ flexRender as flexRender3,
65
63
  getCoreRowModel,
66
64
  getFilteredRowModel,
67
65
  getSortedRowModel,
68
66
  useReactTable
69
67
  } from "@tanstack/react-table";
70
- import {
71
- useVirtualizer
72
- } from "@tanstack/react-virtual";
73
68
  import {
74
69
  closestCenter,
75
70
  DndContext,
@@ -85,914 +80,984 @@ import {
85
80
  SortableContext
86
81
  } from "@dnd-kit/sortable";
87
82
  import { restrictToHorizontalAxis } from "@dnd-kit/modifiers";
83
+ import { useVirtualizer as useVirtualizer2 } from "@tanstack/react-virtual";
84
+ import clsx5 from "clsx";
85
+
86
+ // src/components/DataGrid/PinnedColumns.tsx
87
+ import { flexRender as flexRender2 } from "@tanstack/react-table";
88
+ import clsx4 from "clsx";
89
+
90
+ // src/components/DataGrid/utils.tsx
88
91
  import clsx from "clsx";
89
- import { jsx, jsxs } from "react/jsx-runtime";
90
- var PAGE_SIZE_OPTIONS = [5, 10, 15, 20, 25, 30, 35];
91
- var NO_RESULTS_HEIGHT = "h-[120px]";
92
- function adaptTableStateSetter(setter) {
93
- return (valueOrFn) => {
94
- setter(
95
- (prev) => typeof valueOrFn === "function" ? valueOrFn(prev) : valueOrFn
96
- );
97
- };
92
+ import { jsx } from "react/jsx-runtime";
93
+ function getSortIcon(sort, nextSort = false) {
94
+ const iconClassName = clsx(
95
+ "text-icon-on-action-primary-normal",
96
+ nextSort && "hidden group-hover:block"
97
+ );
98
+ if (sort === "asc")
99
+ return /* @__PURE__ */ jsx(Icon, { size: 16, className: iconClassName, name: "arrow_upward" });
100
+ if (sort === "desc")
101
+ return /* @__PURE__ */ jsx(Icon, { size: 16, className: iconClassName, name: "arrow_downward" });
102
+ return null;
98
103
  }
99
- function DataGrid({
104
+
105
+ // src/components/DataGrid/PinnedColumns.tsx
106
+ import React2 from "react";
107
+
108
+ // src/components/DataGrid/TableBody/index.tsx
109
+ import { useVirtualizer } from "@tanstack/react-virtual";
110
+ import clsx3 from "clsx";
111
+
112
+ // src/components/DataGrid/TableBody/TableBodyRow.tsx
113
+ import clsx2 from "clsx";
114
+ import { flexRender } from "@tanstack/react-table";
115
+ import React from "react";
116
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
117
+ function TableBodyRow({
100
118
  id,
101
- data,
102
- columns,
103
- status,
104
- isLoadingMore = false,
105
- onLoadMore,
106
- pagination,
107
- showFilterRow = false,
108
- hasMore = false,
109
- sorting: externalSorting,
110
- onSortingChange,
111
- columnFilters: externalColumnFilters,
112
- onColumnFiltersChange,
113
- rowSelection: externalRowSelection,
114
- onRowSelectionChange,
115
- filteredSortedData,
116
- totalRowCount,
117
- hideStatusBar,
118
- centerHeader,
119
- enableColumnSelector,
120
- predeterminedLeftPins = [],
121
- predeterminedRightPins = []
119
+ columnVirtualizer,
120
+ row,
121
+ // rowVirtualizer,
122
+ virtualPaddingLeft,
123
+ virtualPaddingRight,
124
+ virtualRow,
125
+ showFilterRow,
126
+ enableColumnSelector = false,
127
+ locked,
128
+ pinDirection
122
129
  }) {
123
- var _a, _b, _c, _d, _e;
124
- const [columnOrder, setColumnOrder] = useState(
125
- () => columns.map((c) => c.id)
126
- );
127
- const [localSorting, setLocalSorting] = useState([]);
128
- const [localColumnFilters, setLocalColumnFilters] = useState([]);
129
- const [localRowSelection, setLocalRowSelection] = useState({});
130
- const sortingState = pagination ? externalSorting != null ? externalSorting : localSorting : localSorting;
131
- const setSortingState = pagination ? (updaterOrValue) => {
132
- const value = typeof updaterOrValue === "function" ? updaterOrValue(
133
- externalSorting != null ? externalSorting : []
134
- ) : updaterOrValue;
135
- (onSortingChange != null ? onSortingChange : setLocalSorting)(value);
136
- } : setLocalSorting;
137
- const columnFilterState = pagination ? externalColumnFilters != null ? externalColumnFilters : localColumnFilters : localColumnFilters;
138
- const setColumnFilterState = pagination ? (updaterOrValue) => {
139
- const value = typeof updaterOrValue === "function" ? updaterOrValue(externalColumnFilters != null ? externalColumnFilters : []) : updaterOrValue;
140
- (onColumnFiltersChange != null ? onColumnFiltersChange : setLocalColumnFilters)(value);
141
- } : setLocalColumnFilters;
142
- const rowSelection = pagination ? externalRowSelection != null ? externalRowSelection : localRowSelection : localRowSelection;
143
- const setRowSelection = pagination ? (updaterOrValue) => {
144
- const value = typeof updaterOrValue === "function" ? updaterOrValue(externalRowSelection != null ? externalRowSelection : {}) : updaterOrValue;
145
- (onRowSelectionChange != null ? onRowSelectionChange : setLocalRowSelection)(value);
146
- } : setLocalRowSelection;
147
- const dndId = useId();
148
- const containerRef = React.useRef(null);
149
- const [columnVisibility, setColumnVisibility] = useState(() => {
150
- const initialVisibility = {};
151
- columns.forEach((column) => {
152
- var _a2, _b2;
153
- if (column.id) {
154
- initialVisibility[column.id] = (_b2 = (_a2 = column.meta) == null ? void 0 : _a2.visible) != null ? _b2 : true;
155
- }
156
- });
157
- return initialVisibility;
158
- });
159
- const toggleColumnVisibility = useCallback(
160
- (columnId, isVisible) => {
161
- setColumnVisibility((prev) => __spreadProps(__spreadValues({}, prev), { [columnId]: isVisible }));
130
+ var _a;
131
+ let visibleCells;
132
+ if (locked) {
133
+ visibleCells = pinDirection === "left" ? row.getLeftVisibleCells() : row.getRightVisibleCells();
134
+ } else {
135
+ visibleCells = row.getCenterVisibleCells();
136
+ }
137
+ const virtualColumns = (_a = columnVirtualizer == null ? void 0 : columnVirtualizer.getVirtualItems()) != null ? _a : [];
138
+ const columns = locked ? visibleCells : virtualColumns;
139
+ const isError = typeof row.original === "object" && row.original !== null && "rowState" in row.original && row.original.rowState === "error";
140
+ const CellElement = locked ? DataGridCell : DragAlongCell;
141
+ return /* @__PURE__ */ jsxs(
142
+ "tr",
143
+ {
144
+ className: clsx2(
145
+ "transition-colors hover:bg-background-action-secondary-hover",
146
+ row.getIsSelected() && "!bg-background-action-secondary-hover",
147
+ isError && "!bg-background-action-critical-secondary-hover",
148
+ showFilterRow ? "even:bg-background-grouped-primary-normal odd:bg-background-grouped-secondary-normal" : "odd:bg-background-grouped-primary-normal even:bg-background-grouped-secondary-normal"
149
+ ),
150
+ style: {
151
+ display: "flex",
152
+ position: "absolute",
153
+ transform: `translateY(${showFilterRow ? virtualRow.start + 40 : virtualRow.start}px)`,
154
+ width: "100%"
155
+ },
156
+ children: [
157
+ !locked && virtualPaddingLeft ? (
158
+ // fake empty column to the left for virtualization scroll padding
159
+ /* @__PURE__ */ jsx2("td", { style: { display: "flex", width: virtualPaddingLeft } })
160
+ ) : null,
161
+ columns.map((column) => {
162
+ var _a2, _b;
163
+ const cell = locked ? column : visibleCells[column.index];
164
+ if (!cell) {
165
+ return;
166
+ }
167
+ const cellValue = cell.getValue();
168
+ return ((_a2 = cell.column.columnDef.meta) == null ? void 0 : _a2.useCustomRenderer) ? /* @__PURE__ */ jsx2(React.Fragment, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id) : /* @__PURE__ */ jsx2(
169
+ CellElement,
170
+ {
171
+ id: id ? `${id}-cell-${cell.id}` : void 0,
172
+ cell,
173
+ className: clsx2({
174
+ "justify-end": typeof cellValue === "number"
175
+ }),
176
+ width: (_b = cell.column.columnDef.meta) == null ? void 0 : _b.headerWidth,
177
+ children: /* @__PURE__ */ jsx2(
178
+ Tooltip,
179
+ {
180
+ id: id ? `${id}-tooltip-${cell.id}` : void 0,
181
+ showOnTruncation: true,
182
+ message: cellValue,
183
+ position: "bottom",
184
+ children: /* @__PURE__ */ jsx2(Paragraph, { addOverflow: true, tall: true, children: cellValue })
185
+ }
186
+ )
187
+ },
188
+ cell.id
189
+ );
190
+ }),
191
+ !locked && virtualPaddingRight ? (
192
+ // fake empty column to the right for virtualization scroll padding
193
+ /* @__PURE__ */ jsx2("td", { style: { display: "flex", width: virtualPaddingRight } })
194
+ ) : null,
195
+ enableColumnSelector && !locked && /* @__PURE__ */ jsx2("td", { className: "p-2", style: { width: "48.8px" } })
196
+ ]
162
197
  },
163
- [setColumnVisibility]
198
+ row.id
164
199
  );
165
- const resetColumnVisibility = useCallback(() => {
166
- setColumnVisibility(() => {
167
- const initialVisibility = {};
168
- columns.forEach((column) => {
169
- var _a2, _b2;
170
- if (column.id) {
171
- initialVisibility[column.id] = (_b2 = (_a2 = column.meta) == null ? void 0 : _a2.visible) != null ? _b2 : true;
172
- }
173
- });
174
- return initialVisibility;
175
- });
176
- }, [columns]);
177
- const table = useReactTable({
178
- columns,
179
- data,
180
- getCoreRowModel: getCoreRowModel(),
181
- getSortedRowModel: getSortedRowModel(),
182
- getFilteredRowModel: getFilteredRowModel(),
183
- columnResizeMode: "onChange",
184
- getRowId: (row, index) => {
185
- var _a2;
186
- return String((_a2 = row.id) != null ? _a2 : index + 1);
187
- },
188
- state: {
189
- columnOrder,
190
- sorting: sortingState,
191
- columnFilters: columnFilterState,
192
- rowSelection,
193
- columnVisibility
194
- },
195
- initialState: {
196
- columnPinning: {
197
- left: predeterminedLeftPins,
198
- right: predeterminedRightPins
199
- }
200
- },
201
- enableColumnPinning: (predeterminedLeftPins == null ? void 0 : predeterminedLeftPins.length) > 0 || predeterminedRightPins.length > 0,
202
- onColumnOrderChange: setColumnOrder,
203
- onSortingChange: adaptTableStateSetter(setSortingState),
204
- onColumnFiltersChange: adaptTableStateSetter(setColumnFilterState),
205
- onRowSelectionChange: adaptTableStateSetter(setRowSelection),
206
- filterFns: {
207
- startsWith: (row, columnId, filterValue) => {
208
- const cellValue = row == null ? void 0 : row.getValue(columnId);
209
- if (!cellValue || !filterValue) {
210
- return true;
211
- }
212
- return String(cellValue).toLowerCase().startsWith(String(filterValue).toLowerCase());
200
+ }
201
+
202
+ // src/components/DataGrid/TableBody/LoadingCell.tsx
203
+ import { jsx as jsx3 } from "react/jsx-runtime";
204
+ function LoadingCell({
205
+ id,
206
+ column
207
+ }) {
208
+ const key = `loading-${column.id}`;
209
+ if (column.cell === "checkbox") {
210
+ return /* @__PURE__ */ jsx3(DataGridCell, { id: id ? `${id}-${key}` : void 0, children: /* @__PURE__ */ jsx3(Checkbox, { id: id ? `${id}-${key}-checkbox` : void 0, disabled: true }) }, key);
211
+ }
212
+ if (column.cell === "input") {
213
+ return /* @__PURE__ */ jsx3(
214
+ DataGridCell,
215
+ {
216
+ id: id ? `${id}-${key}` : void 0,
217
+ component: "input",
218
+ children: /* @__PURE__ */ jsx3(
219
+ Input,
220
+ {
221
+ id: id ? `${id}-${key}-input` : void 0,
222
+ align: "left",
223
+ disabled: true,
224
+ wrapperClassName: "!rounded-none !border-0"
225
+ }
226
+ )
213
227
  },
214
- endsWith: (row, columnId, filterValue) => {
215
- const cellValue = row == null ? void 0 : row.getValue(columnId);
216
- if (!cellValue || !filterValue) {
217
- return true;
218
- }
219
- return String(cellValue).toLowerCase().endsWith(String(filterValue).toLowerCase());
220
- }
221
- }
228
+ key
229
+ );
230
+ }
231
+ return /* @__PURE__ */ jsx3(DataGridCell, { id: id ? `${id}-${key}` : void 0, children: /* @__PURE__ */ jsx3("div", { className: "bg-linear-270 to-neutral-300/[24%] from-neutral-300/[12%] rounded-xs w-full max-w-25 h-6" }) }, key);
232
+ }
233
+
234
+ // src/components/DataGrid/TableBody/index.tsx
235
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
236
+ function TableBody({
237
+ id,
238
+ columnVirtualizer,
239
+ table,
240
+ tableContainerRef,
241
+ virtualPaddingLeft,
242
+ virtualPaddingRight,
243
+ pagination,
244
+ isLoadingMore,
245
+ hasMore,
246
+ showFilterRow,
247
+ enableColumnSelector = false,
248
+ locked,
249
+ pinDirection
250
+ }) {
251
+ const { rows } = table.getRowModel();
252
+ const rowVirtualizer = useVirtualizer({
253
+ count: rows.length,
254
+ estimateSize: () => 40,
255
+ getScrollElement: () => tableContainerRef.current,
256
+ overscan: 8
222
257
  });
223
- const allRowIds = pagination ? (_a = filteredSortedData == null ? void 0 : filteredSortedData.map((row) => String(row.id))) != null ? _a : [] : Array.from(
224
- { length: totalRowCount != null ? totalRowCount : data.length },
225
- (_, i) => String(i + 1)
226
- );
227
- const allSelectedAcrossPages = allRowIds.every(
228
- (rowId) => rowSelection[rowId]
229
- );
230
- const someSelectedAcrossPages = !allSelectedAcrossPages && allRowIds.some((rowId) => rowSelection[rowId]);
231
- const toggleSelectAllAcrossPages = () => {
232
- setRowSelection((prev) => {
233
- const isSelecting = !allSelectedAcrossPages;
234
- if (isSelecting) {
235
- const newSelection = {};
236
- for (const rowId of allRowIds) {
237
- newSelection[rowId] = true;
238
- }
239
- return __spreadValues(__spreadValues({}, prev), newSelection);
240
- } else {
241
- const updatedSelection = __spreadValues({}, prev);
242
- for (const rowId of allRowIds) {
243
- delete updatedSelection[rowId];
244
- }
245
- return updatedSelection;
246
- }
247
- });
248
- };
249
- useInfiniteScroll({
250
- containerRef,
251
- onLoadMore: onLoadMore != null ? onLoadMore : () => {
252
- },
253
- isLoading: isLoadingMore,
254
- enabled: !pagination
255
- });
256
- const handleDragEnd = (event) => {
257
- const { active, over } = event;
258
- if (active && over && active.id !== over.id) {
259
- setColumnOrder((prev) => {
260
- const oldIndex = prev.indexOf(active.id);
261
- const newIndex = prev.indexOf(over.id);
262
- return arrayMove(prev, oldIndex, newIndex);
263
- });
264
- }
265
- };
266
- const sensors = useSensors(
267
- useSensor(MouseSensor),
268
- useSensor(TouchSensor),
269
- useSensor(KeyboardSensor)
270
- );
271
- const visibleColumns = table.getVisibleLeafColumns();
272
- const columnVirtualizer = useVirtualizer({
273
- count: visibleColumns.length,
274
- estimateSize: (index) => visibleColumns[index].getSize(),
275
- //estimate width of each column for accurate scrollbar dragging
276
- getScrollElement: () => containerRef.current,
277
- horizontal: true,
278
- overscan: 3
279
- //how many columns to render on each side off screen each way
280
- });
281
- const virtualColumns = columnVirtualizer.getVirtualItems();
282
- let virtualPaddingLeft;
283
- let virtualPaddingRight;
284
- if (columnVirtualizer && (virtualColumns == null ? void 0 : virtualColumns.length)) {
285
- virtualPaddingLeft = (_c = (_b = virtualColumns[0]) == null ? void 0 : _b.start) != null ? _c : 0;
286
- virtualPaddingRight = columnVirtualizer.getTotalSize() - ((_e = (_d = virtualColumns[virtualColumns.length - 1]) == null ? void 0 : _d.end) != null ? _e : 0);
258
+ const virtualRows = rowVirtualizer.getVirtualItems();
259
+ const CellElement = locked ? DataGridCell : DragAlongCell;
260
+ let headerGroups;
261
+ if (pinDirection === "left") {
262
+ headerGroups = table.getLeftHeaderGroups();
263
+ } else if (pinDirection === "right") {
264
+ headerGroups = table.getRightHeaderGroups();
265
+ } else {
266
+ headerGroups = table.getCenterHeaderGroups();
287
267
  }
288
- const empty = table.getRowModel().rows.length === 0;
289
- return /* @__PURE__ */ jsx(
290
- DndContext,
268
+ return /* @__PURE__ */ jsxs2(
269
+ "tbody",
291
270
  {
292
- id: dndId,
293
- collisionDetection: closestCenter,
294
- modifiers: [restrictToHorizontalAxis],
295
- onDragEnd: handleDragEnd,
296
- sensors,
297
- children: /* @__PURE__ */ jsx(
298
- SortableContext,
299
- {
300
- items: columnOrder,
301
- strategy: horizontalListSortingStrategy,
302
- children: /* @__PURE__ */ jsxs(
303
- "div",
271
+ className: clsx3(locked ? "shadow-16" : ""),
272
+ style: {
273
+ display: "grid",
274
+ height: `${showFilterRow ? rowVirtualizer.getTotalSize() + 40 : rowVirtualizer.getTotalSize()}px`,
275
+ // tells scrollbar how big the table is
276
+ position: "relative"
277
+ // needed for absolute positioning of rows
278
+ },
279
+ children: [
280
+ showFilterRow && /* @__PURE__ */ jsx4(
281
+ "tr",
282
+ {
283
+ style: {
284
+ display: "flex",
285
+ position: "sticky",
286
+ top: "40px",
287
+ width: "100%",
288
+ height: "40px",
289
+ zIndex: 10
290
+ },
291
+ className: "even:bg-background-grouped-primary-normal odd:bg-background-grouped-secondary-normal",
292
+ children: headerGroups.flatMap(
293
+ (x) => x.headers.map((header) => {
294
+ var _a, _b, _c, _d, _e;
295
+ return /* @__PURE__ */ jsx4(
296
+ CellElement,
297
+ {
298
+ id: id ? `${id}-filter-cell-${header.id}` : void 0,
299
+ noPadding: true,
300
+ cell: header,
301
+ width: ((_a = header.column.columnDef.meta) == null ? void 0 : _a.headerWidth) || (locked ? `${header.column.getSize()}px` : ""),
302
+ children: header.column.getCanFilter() && ((_e = (_c = (_b = header.column.columnDef.meta) == null ? void 0 : _b.filterRowCell) == null ? void 0 : _c.call(_b, {
303
+ header,
304
+ table
305
+ })) != null ? _e : /* @__PURE__ */ jsx4(
306
+ Search,
307
+ {
308
+ id: id ? `${id}-filter-search-${header.id}` : void 0,
309
+ removeRoundness: true,
310
+ onChange: (e) => header.column.setFilterValue(e.target.value),
311
+ value: (_d = header.column.getFilterValue()) != null ? _d : "",
312
+ placeholder: "",
313
+ removeSearchIcon: true
314
+ }
315
+ ))
316
+ },
317
+ header.id
318
+ );
319
+ })
320
+ )
321
+ }
322
+ ),
323
+ virtualRows.map((virtualRow) => {
324
+ const row = rows[virtualRow.index];
325
+ return /* @__PURE__ */ jsx4(
326
+ TableBodyRow,
304
327
  {
305
328
  id,
306
- className: "flex flex-col flex-1 h-full w-full rounded border border-border-primary-normal overflow-hidden text-text-primary-normal",
307
- children: [
308
- /* @__PURE__ */ jsxs(
309
- "div",
310
- {
311
- className: clsx(
312
- "flex overflow-auto scrollbar-thin relative contain-paint will-change-transform",
313
- empty ? "overflow-y-hidden" : "h-full"
329
+ columnVirtualizer,
330
+ row,
331
+ rowVirtualizer,
332
+ virtualPaddingLeft,
333
+ virtualPaddingRight,
334
+ virtualRow,
335
+ showFilterRow,
336
+ enableColumnSelector,
337
+ locked,
338
+ pinDirection
339
+ },
340
+ row.id
341
+ );
342
+ }),
343
+ !pagination && isLoadingMore && hasMore && /* @__PURE__ */ jsx4(
344
+ "tr",
345
+ {
346
+ style: {
347
+ display: "flex",
348
+ position: "absolute",
349
+ width: "100%",
350
+ transform: `translateY(${virtualRows[virtualRows.length - 1].start + 40}px)`
351
+ },
352
+ className: "odd:bg-background-grouped-primary-normal even:bg-background-grouped-secondary-normal",
353
+ children: table.getAllLeafColumns().map((column) => /* @__PURE__ */ jsx4(LoadingCell, { id, column: column.columnDef }, column.id))
354
+ }
355
+ )
356
+ ]
357
+ }
358
+ );
359
+ }
360
+
361
+ // src/components/DataGrid/PinnedColumns.tsx
362
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
363
+ function PinnedColumns(_a) {
364
+ var _b = _a, {
365
+ pinDirection = "left",
366
+ table,
367
+ centerHeader,
368
+ allSelectedAcrossPages,
369
+ someSelectedAcrossPages,
370
+ toggleSelectAllAcrossPages
371
+ } = _b, props = __objRest(_b, [
372
+ "pinDirection",
373
+ "table",
374
+ "centerHeader",
375
+ "allSelectedAcrossPages",
376
+ "someSelectedAcrossPages",
377
+ "toggleSelectAllAcrossPages"
378
+ ]);
379
+ var _a2;
380
+ const headerGroups = pinDirection === "left" ? table.getLeftHeaderGroups() : table.getRightHeaderGroups();
381
+ return ((_a2 = headerGroups[0]) == null ? void 0 : _a2.headers.length) > 0 && /* @__PURE__ */ jsxs3(
382
+ "table",
383
+ {
384
+ className: clsx4(
385
+ "flex flex-col min-h-min sticky z-20 bg-background-grouped-primary-normal",
386
+ pinDirection === "left" ? "left-0" : "right-0"
387
+ ),
388
+ children: [
389
+ /* @__PURE__ */ jsx5("thead", { className: "sticky top-0 z-20 grid", children: headerGroups.map((headerGroup) => {
390
+ return /* @__PURE__ */ jsx5("tr", { className: "flex w-full", children: headerGroup.headers.map((header) => {
391
+ var _a3, _b2, _c;
392
+ if (!header) {
393
+ return;
394
+ }
395
+ if (typeof header.column.columnDef.header === "string") {
396
+ const customHeaderWidth = (_a3 = header.column.columnDef.meta) == null ? void 0 : _a3.headerWidth;
397
+ return /* @__PURE__ */ jsxs3(
398
+ DataCellHeader,
399
+ {
400
+ locked: true,
401
+ header,
402
+ center: centerHeader,
403
+ width: customHeaderWidth,
404
+ className: clsx4(
405
+ header.column.getCanSort() ? "cursor-pointer" : "cursor-grab",
406
+ "group"
407
+ ),
408
+ children: [
409
+ /* @__PURE__ */ jsx5(Subheader, { tall: true, children: header.column.columnDef.header }),
410
+ getSortIcon(header.column.getIsSorted()),
411
+ !header.column.getIsSorted() && header.column.getCanSort() && getSortIcon(
412
+ header.column.getNextSortingOrder(),
413
+ true
314
414
  ),
315
- ref: containerRef,
316
- children: [
317
- /* @__PURE__ */ jsx(
318
- PinnedColumns,
319
- {
320
- pinDirection: "left",
321
- table,
322
- tableContainerRef: containerRef,
323
- pagination,
324
- isLoadingMore,
325
- hasMore,
326
- showFilterRow,
327
- enableColumnSelector
328
- }
329
- ),
330
- /* @__PURE__ */ jsxs("table", { className: "flex-1 flex flex-col min-h-min", children: [
331
- /* @__PURE__ */ jsx("thead", { className: "sticky top-0 z-10 grid", children: table.getCenterHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs("tr", { className: "flex w-full", children: [
332
- virtualPaddingLeft ? (
333
- // fake empty column to the left for virtualization scroll padding
334
- /* @__PURE__ */ jsx(
335
- "th",
336
- {
337
- style: { display: "flex", width: virtualPaddingLeft }
338
- }
339
- )
340
- ) : null,
341
- virtualColumns.map((virtualColumn) => {
342
- var _a2, _b2, _c2, _d2;
343
- const header = headerGroup.headers[virtualColumn.index];
344
- if (!header) {
345
- return;
346
- }
347
- if (typeof header.column.columnDef.header === "string") {
348
- const customHeaderWidth = (_a2 = header.column.columnDef.meta) == null ? void 0 : _a2.headerWidth;
349
- return /* @__PURE__ */ jsxs(
350
- DraggableCellHeader,
351
- {
352
- id: id ? `${id}-header-${header.id}` : void 0,
353
- header,
354
- locked: (_b2 = header.column.columnDef.meta) == null ? void 0 : _b2.locked,
355
- center: centerHeader,
356
- width: customHeaderWidth,
357
- className: clsx(
358
- header.column.getCanSort() ? "cursor-pointer" : "cursor-grab",
359
- "group"
360
- ),
361
- children: [
362
- /* @__PURE__ */ jsx(Subheader, { tall: true, children: header.column.columnDef.header }),
363
- getSortIcon(header.column.getIsSorted()),
364
- !header.column.getIsSorted() && header.column.getCanSort() && getSortIcon(
365
- header.column.getNextSortingOrder(),
366
- true
367
- ),
368
- header.column.getSortIndex() !== -1 && table.getState().sorting.length > 1 && /* @__PURE__ */ jsx(Subheader, { tall: true, children: header.column.getSortIndex() + 1 }),
369
- /* @__PURE__ */ jsx(
370
- "div",
371
- {
372
- onDoubleClick: (e) => {
373
- e.stopPropagation();
374
- header.column.resetSize();
375
- },
376
- onMouseDown: (e) => {
377
- e.stopPropagation();
378
- header.getResizeHandler()(e);
379
- },
380
- onTouchStart: (e) => {
381
- e.stopPropagation();
382
- header.getResizeHandler()(e);
383
- },
384
- className: "absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
385
- }
386
- )
387
- ]
388
- },
389
- header.id
390
- );
391
- }
392
- return /* @__PURE__ */ jsx(React.Fragment, { children: ((_c2 = header.column.columnDef.meta) == null ? void 0 : _c2.checkbox) ? /* @__PURE__ */ jsx(
393
- DataGridCell,
394
- {
395
- id: id ? `${id}-header-${header.id}` : void 0,
396
- type: "header",
397
- component: "checkbox",
398
- locked: (_d2 = header.column.columnDef.meta) == null ? void 0 : _d2.locked,
399
- children: /* @__PURE__ */ jsx(
400
- Checkbox,
401
- {
402
- id: id ? `${id}-select-all-checkbox` : void 0,
403
- checked: allSelectedAcrossPages,
404
- indeterminate: someSelectedAcrossPages,
405
- onChange: toggleSelectAllAcrossPages
406
- }
407
- )
408
- }
409
- ) : flexRender(
410
- header.column.columnDef.header,
411
- header.getContext()
412
- ) }, header.id);
413
- }),
414
- virtualPaddingRight ? (
415
- //fake empty column to the right for virtualization scroll padding
416
- /* @__PURE__ */ jsx(
417
- "th",
418
- {
419
- style: { display: "flex", width: virtualPaddingRight }
420
- }
421
- )
422
- ) : null,
423
- enableColumnSelector && /* @__PURE__ */ jsx(
424
- ColumnSelectorHeaderCell,
425
- {
426
- id: id ? `${id}-column-selector` : void 0,
427
- table,
428
- toggleColumnVisibility,
429
- resetColumnVisibility
430
- }
431
- )
432
- ] }, headerGroup.id)) }),
433
- /* @__PURE__ */ jsx(
434
- TableBody,
435
- {
436
- id,
437
- columnVirtualizer,
438
- table,
439
- tableContainerRef: containerRef,
440
- virtualPaddingLeft,
441
- virtualPaddingRight,
442
- pagination,
443
- isLoadingMore,
444
- hasMore,
445
- showFilterRow,
446
- enableColumnSelector
447
- }
448
- )
449
- ] }),
450
- /* @__PURE__ */ jsx(
451
- PinnedColumns,
452
- {
453
- pinDirection: "right",
454
- table,
455
- tableContainerRef: containerRef,
456
- pagination,
457
- isLoadingMore,
458
- hasMore,
459
- showFilterRow,
460
- enableColumnSelector
461
- }
462
- )
463
- ]
464
- }
465
- ),
466
- empty && /* @__PURE__ */ jsxs(
467
- "div",
468
- {
469
- className: clsx(
470
- NO_RESULTS_HEIGHT,
471
- "flex flex-col items-center justify-center",
472
- componentGap,
473
- componentPadding
474
- ),
475
- children: [
476
- /* @__PURE__ */ jsx(Subheader, { color: "text-secondary-normal", children: "No Results" }),
477
- /* @__PURE__ */ jsx(Paragraph, { color: "text-secondary-normal", children: "To view results, enter or update your search criteria." })
478
- ]
479
- }
480
- ),
481
- !hideStatusBar && /* @__PURE__ */ jsxs("div", { className: "p-2 pt-[7px] border-t border-border-primary-normal h-full min-h-[34px]", children: [
482
- pagination && /* @__PURE__ */ jsxs("div", { className: "flex justify-between items-center", children: [
483
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1 w-min", children: [
484
- /* @__PURE__ */ jsx(
485
- Select,
486
- {
487
- id: id ? `${id}-pagesize-select` : void 0,
488
- wrapperClassName: "!w-20",
489
- value: pagination.pageSize.toString(),
490
- onChange: (e) => {
491
- var _a2;
492
- return (_a2 = pagination.onPageSizeChange) == null ? void 0 : _a2.call(pagination, Number(e.target.value));
493
- },
494
- renderMenu: (props) => /* @__PURE__ */ jsx(
495
- Menu,
496
- __spreadProps(__spreadValues({}, props), {
497
- id: id ? `${id}-pagesize-menu` : void 0,
498
- children: PAGE_SIZE_OPTIONS.map((option) => /* @__PURE__ */ jsx(
499
- MenuOption,
500
- {
501
- id: id ? `${id}-pagesize-option-${option}` : void 0,
502
- selected: pagination.pageSize === option,
503
- onClick: () => {
504
- var _a2;
505
- return (_a2 = pagination.onPageSizeChange) == null ? void 0 : _a2.call(pagination, option);
506
- },
507
- children: option
508
- },
509
- option
510
- ))
511
- })
512
- )
513
- }
514
- ),
515
- /* @__PURE__ */ jsx(Label, { children: "Per Page" })
516
- ] }),
517
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
518
- /* @__PURE__ */ jsx(
519
- Button,
520
- {
521
- id: id ? `${id}-prev-page-button` : void 0,
522
- iconOnly: true,
523
- leftIcon: /* @__PURE__ */ jsx(Icon, { name: "chevron_left" }),
524
- onClick: () => pagination.onPageChange(pagination.pageIndex - 1),
525
- variant: "tertiary",
526
- disabled: pagination.pageIndex === 0
527
- }
528
- ),
529
- /* @__PURE__ */ jsxs(Paragraph, { children: [
530
- pagination.pageIndex * pagination.pageSize + 1,
531
- " -",
532
- " ",
533
- Math.min(
534
- (pagination.pageIndex + 1) * pagination.pageSize,
535
- pagination.total
536
- ),
537
- " ",
538
- "of ",
539
- pagination.total
540
- ] }),
541
- /* @__PURE__ */ jsx(
542
- Button,
543
- {
544
- id: id ? `${id}-next-page-button` : void 0,
545
- iconOnly: true,
546
- leftIcon: /* @__PURE__ */ jsx(Icon, { name: "chevron_right" }),
547
- onClick: () => pagination.onPageChange(pagination.pageIndex + 1),
548
- variant: "tertiary",
549
- disabled: (pagination.pageIndex + 1) * pagination.pageSize >= pagination.total
550
- }
551
- )
552
- ] })
553
- ] }),
554
- status && /* @__PURE__ */ jsx(Paragraph, { children: status })
555
- ] })
556
- ]
415
+ header.column.getSortIndex() !== -1 && table.getState().sorting.length > 1 && /* @__PURE__ */ jsx5(Subheader, { tall: true, children: header.column.getSortIndex() + 1 }),
416
+ !((_b2 = header.column.columnDef.meta) == null ? void 0 : _b2.locked) && /* @__PURE__ */ jsx5(
417
+ "div",
418
+ {
419
+ onDoubleClick: (e) => {
420
+ e.stopPropagation();
421
+ header.column.resetSize();
422
+ },
423
+ onMouseDown: (e) => {
424
+ e.stopPropagation();
425
+ header.getResizeHandler()(e);
426
+ },
427
+ onTouchStart: (e) => {
428
+ e.stopPropagation();
429
+ header.getResizeHandler()(e);
430
+ },
431
+ className: "absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
432
+ }
433
+ )
434
+ ]
435
+ },
436
+ header.id
437
+ );
557
438
  }
558
- )
559
- }
560
- )
439
+ return /* @__PURE__ */ jsx5(React2.Fragment, { children: ((_c = header.column.columnDef.meta) == null ? void 0 : _c.checkbox) ? /* @__PURE__ */ jsx5(DataGridCell, { type: "header", component: "checkbox", locked: true, children: /* @__PURE__ */ jsx5(
440
+ Checkbox,
441
+ {
442
+ checked: allSelectedAcrossPages,
443
+ indeterminate: someSelectedAcrossPages,
444
+ onChange: toggleSelectAllAcrossPages
445
+ }
446
+ ) }) : flexRender2(
447
+ header.column.columnDef.header,
448
+ header.getContext()
449
+ ) }, header.id);
450
+ }) }, headerGroup.id);
451
+ }) }),
452
+ /* @__PURE__ */ jsx5(
453
+ TableBody,
454
+ __spreadProps(__spreadValues({}, props), {
455
+ table,
456
+ locked: true,
457
+ pinDirection
458
+ })
459
+ )
460
+ ]
561
461
  }
562
462
  );
563
463
  }
564
- DataGrid.displayName = "DataGrid";
565
- function TableBody({
464
+
465
+ // src/components/DataGrid/ColumnSelectorHeaderCell/index.tsx
466
+ import { useRef, useState as useState2 } from "react";
467
+
468
+ // src/components/DataGrid/ColumnSelectorHeaderCell/ColumnSelectorMenuOption.tsx
469
+ import { useState } from "react";
470
+ import { jsx as jsx6 } from "react/jsx-runtime";
471
+ function ColumnSelectorMenuOption({
566
472
  id,
567
- columnVirtualizer,
568
- table,
569
- tableContainerRef,
570
- virtualPaddingLeft,
571
- virtualPaddingRight,
572
- pagination,
573
- isLoadingMore,
574
- hasMore,
575
- showFilterRow,
576
- enableColumnSelector = false,
577
- locked,
578
- pinDirection
473
+ column,
474
+ toggleColumnVisibility
579
475
  }) {
580
- const { rows } = table.getRowModel();
581
- const rowVirtualizer = useVirtualizer({
582
- count: rows.length,
583
- estimateSize: () => 40,
584
- getScrollElement: () => tableContainerRef.current,
585
- overscan: 8
586
- });
587
- const virtualRows = rowVirtualizer.getVirtualItems();
588
- const CellElement = locked ? DataGridCell : DragAlongCell;
589
- let headerGroups;
590
- if (pinDirection === "left") {
591
- headerGroups = table.getLeftHeaderGroups();
592
- } else if (pinDirection === "right") {
593
- headerGroups = table.getRightHeaderGroups();
594
- } else {
595
- headerGroups = table.getCenterHeaderGroups();
596
- }
597
- return /* @__PURE__ */ jsxs(
598
- "tbody",
476
+ const [isVisible, setIsVisible] = useState(column.getIsVisible());
477
+ const label = typeof column.columnDef.header === "string" ? column.columnDef.header : null;
478
+ return /* @__PURE__ */ jsx6(MenuOption, { id, selected: isVisible, defaultChecked: isVisible, children: /* @__PURE__ */ jsx6(
479
+ Checkbox,
599
480
  {
600
- className: clsx(locked ? "shadow-16" : ""),
601
- style: {
602
- display: "grid",
603
- height: `${showFilterRow ? rowVirtualizer.getTotalSize() + 40 : rowVirtualizer.getTotalSize()}px`,
604
- // tells scrollbar how big the table is
605
- position: "relative"
606
- // needed for absolute positioning of rows
607
- },
608
- children: [
609
- showFilterRow && /* @__PURE__ */ jsx(
610
- "tr",
611
- {
612
- style: {
613
- display: "flex",
614
- position: "sticky",
615
- top: "40px",
616
- width: "100%",
617
- height: "40px",
618
- zIndex: 10
619
- },
620
- className: "even:bg-background-grouped-primary-normal odd:bg-background-grouped-secondary-normal",
621
- children: headerGroups.flatMap(
622
- (x) => x.headers.map((header) => {
623
- var _a, _b, _c, _d, _e;
624
- return /* @__PURE__ */ jsx(
625
- CellElement,
626
- {
627
- id: id ? `${id}-filter-cell-${header.id}` : void 0,
628
- noPadding: true,
629
- cell: header,
630
- width: ((_a = header.column.columnDef.meta) == null ? void 0 : _a.headerWidth) || (locked ? `${header.column.getSize()}px` : ""),
631
- children: header.column.getCanFilter() && ((_e = (_c = (_b = header.column.columnDef.meta) == null ? void 0 : _b.filterRowCell) == null ? void 0 : _c.call(_b, {
632
- header,
633
- table
634
- })) != null ? _e : /* @__PURE__ */ jsx(
635
- Search,
636
- {
637
- id: id ? `${id}-filter-search-${header.id}` : void 0,
638
- removeRoundness: true,
639
- onChange: (e) => header.column.setFilterValue(e.target.value),
640
- value: (_d = header.column.getFilterValue()) != null ? _d : "",
641
- placeholder: "",
642
- removeSearchIcon: true
643
- }
644
- ))
645
- },
646
- header.id
647
- );
648
- })
649
- )
481
+ id: id ? `${id}-checkbox` : void 0,
482
+ label: label != null ? label : "Unknown",
483
+ checked: isVisible,
484
+ onChange: (e) => {
485
+ setIsVisible(e.target.checked);
486
+ toggleColumnVisibility(column.id, e.target.checked);
487
+ }
488
+ }
489
+ ) });
490
+ }
491
+
492
+ // src/components/DataGrid/ColumnSelectorHeaderCell/index.tsx
493
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
494
+ function ColumnSelectorHeaderCell({
495
+ id,
496
+ table,
497
+ toggleColumnVisibility,
498
+ resetColumnVisibility
499
+ }) {
500
+ const ref = useRef(null);
501
+ const [show, setShow] = useState2(false);
502
+ return /* @__PURE__ */ jsxs4(
503
+ DataGridCell,
504
+ {
505
+ id,
506
+ width: "48",
507
+ type: "header",
508
+ color: "text-secondary-normal",
509
+ ref,
510
+ children: [
511
+ /* @__PURE__ */ jsx7(
512
+ Button,
513
+ {
514
+ id: id ? `${id}-button` : void 0,
515
+ onClick: () => setShow((prev) => !prev),
516
+ variant: "navigation",
517
+ iconOnly: true,
518
+ leftIcon: /* @__PURE__ */ jsx7(Icon, { name: "tune" })
650
519
  }
651
520
  ),
652
- virtualRows.map((virtualRow) => {
653
- const row = rows[virtualRow.index];
654
- return /* @__PURE__ */ jsx(
655
- TableBodyRow,
656
- {
657
- id,
658
- columnVirtualizer,
659
- row,
660
- rowVirtualizer,
661
- virtualPaddingLeft,
662
- virtualPaddingRight,
663
- virtualRow,
664
- showFilterRow,
665
- enableColumnSelector,
666
- locked,
667
- pinDirection
668
- },
669
- row.id
670
- );
671
- }),
672
- !pagination && isLoadingMore && hasMore && /* @__PURE__ */ jsx(
673
- "tr",
521
+ /* @__PURE__ */ jsxs4(
522
+ Menu,
674
523
  {
675
- style: {
676
- display: "flex",
677
- position: "absolute",
678
- width: "100%",
679
- transform: `translateY(${virtualRows[virtualRows.length - 1].start + 40}px)`
680
- },
681
- className: "odd:bg-background-grouped-primary-normal even:bg-background-grouped-secondary-normal",
682
- children: table.getAllLeafColumns().map((column) => /* @__PURE__ */ jsx(LoadingCell, { id, column: column.columnDef }, column.id))
524
+ id: id ? `${id}-menu` : void 0,
525
+ positionTo: ref,
526
+ position: "bottom-right",
527
+ show,
528
+ setShow,
529
+ children: [
530
+ /* @__PURE__ */ jsx7(
531
+ Button,
532
+ {
533
+ id: id ? `${id}-reset-button` : void 0,
534
+ variant: "tertiary",
535
+ onClick: () => {
536
+ resetColumnVisibility();
537
+ setShow(false);
538
+ },
539
+ children: "Reset to default"
540
+ }
541
+ ),
542
+ table.getAllColumns().filter((x) => {
543
+ var _a;
544
+ return (_a = x.columnDef.meta) == null ? void 0 : _a.inVisibilityMenu;
545
+ }).map((column) => /* @__PURE__ */ jsx7(
546
+ ColumnSelectorMenuOption,
547
+ {
548
+ id: id ? `${id}-option-${column.id}` : void 0,
549
+ column,
550
+ toggleColumnVisibility
551
+ },
552
+ column.id
553
+ ))
554
+ ]
683
555
  }
684
556
  )
685
557
  ]
686
558
  }
687
559
  );
688
560
  }
689
- function TableBodyRow({
561
+
562
+ // src/components/DataGrid/index.tsx
563
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
564
+ var PAGE_SIZE_OPTIONS = [5, 10, 15, 20, 25, 30, 35];
565
+ var NO_RESULTS_HEIGHT = "h-[120px]";
566
+ function DataGrid({
690
567
  id,
691
- columnVirtualizer,
692
- row,
693
- // rowVirtualizer,
694
- virtualPaddingLeft,
695
- virtualPaddingRight,
696
- virtualRow,
697
- showFilterRow,
698
- enableColumnSelector = false,
699
- locked,
700
- pinDirection
568
+ data,
569
+ columns,
570
+ status,
571
+ isLoadingMore = false,
572
+ onLoadMore,
573
+ pagination,
574
+ showFilterRow = false,
575
+ hasMore = false,
576
+ sorting: externalSorting,
577
+ onSortingChange,
578
+ columnFilters: externalColumnFilters,
579
+ onColumnFiltersChange,
580
+ rowSelection: externalRowSelection,
581
+ onRowSelectionChange,
582
+ filteredSortedData,
583
+ totalRowCount,
584
+ hideStatusBar,
585
+ centerHeader,
586
+ enableColumnSelector,
587
+ predeterminedLeftPins = [],
588
+ predeterminedRightPins = [],
589
+ useMenuDefaultMinWidth
701
590
  }) {
702
- var _a;
703
- let visibleCells;
704
- if (locked) {
705
- visibleCells = pinDirection === "left" ? row.getLeftVisibleCells() : row.getRightVisibleCells();
706
- } else {
707
- visibleCells = row.getCenterVisibleCells();
708
- }
709
- const virtualColumns = (_a = columnVirtualizer == null ? void 0 : columnVirtualizer.getVirtualItems()) != null ? _a : [];
710
- const columns = locked ? visibleCells : virtualColumns;
711
- const isError = typeof row.original === "object" && row.original !== null && "rowState" in row.original && row.original.rowState === "error";
712
- const CellElement = locked ? DataGridCell : DragAlongCell;
713
- return /* @__PURE__ */ jsxs(
714
- "tr",
715
- {
716
- className: clsx(
717
- "transition-colors hover:bg-background-action-secondary-hover",
718
- row.getIsSelected() && "!bg-background-action-secondary-hover",
719
- isError && "!bg-background-action-critical-secondary-hover",
720
- showFilterRow ? "even:bg-background-grouped-primary-normal odd:bg-background-grouped-secondary-normal" : "odd:bg-background-grouped-primary-normal even:bg-background-grouped-secondary-normal"
721
- ),
722
- style: {
723
- display: "flex",
724
- position: "absolute",
725
- transform: `translateY(${showFilterRow ? virtualRow.start + 40 : virtualRow.start}px)`,
726
- width: "100%"
727
- },
728
- children: [
729
- !locked && virtualPaddingLeft ? (
730
- // fake empty column to the left for virtualization scroll padding
731
- /* @__PURE__ */ jsx("td", { style: { display: "flex", width: virtualPaddingLeft } })
732
- ) : null,
733
- columns.map((column) => {
734
- var _a2;
735
- const cell = locked ? column : visibleCells[column.index];
736
- if (!cell) {
737
- return;
738
- }
739
- return ((_a2 = cell.column.columnDef.meta) == null ? void 0 : _a2.useCustomRenderer) ? /* @__PURE__ */ jsx(React.Fragment, { children: flexRender(cell.column.columnDef.cell, cell.getContext()) }, cell.id) : /* @__PURE__ */ jsx(
740
- CellElement,
741
- {
742
- id: id ? `${id}-cell-${cell.id}` : void 0,
743
- cell,
744
- children: /* @__PURE__ */ jsx(
745
- Tooltip,
746
- {
747
- id: id ? `${id}-tooltip-${cell.id}` : void 0,
748
- showOnTruncation: true,
749
- message: cell.getValue(),
750
- position: "bottom",
751
- children: /* @__PURE__ */ jsx(Paragraph, { addOverflow: true, tall: true, children: cell.getValue() })
752
- }
753
- )
754
- },
755
- cell.id
756
- );
757
- }),
758
- !locked && virtualPaddingRight ? (
759
- // fake empty column to the right for virtualization scroll padding
760
- /* @__PURE__ */ jsx("td", { style: { display: "flex", width: virtualPaddingRight } })
761
- ) : null,
762
- enableColumnSelector && !locked && /* @__PURE__ */ jsx("td", { className: "p-2", style: { width: "48.8px" } })
763
- ]
591
+ var _a, _b, _c, _d, _e;
592
+ const [columnOrder, setColumnOrder] = useState3(
593
+ () => columns.map((c) => c.id)
594
+ );
595
+ const [localSorting, setLocalSorting] = useState3([]);
596
+ const [localColumnFilters, setLocalColumnFilters] = useState3([]);
597
+ const [localRowSelection, setLocalRowSelection] = useState3({});
598
+ const sortingState = pagination ? externalSorting != null ? externalSorting : localSorting : localSorting;
599
+ const setSortingState = pagination ? (updaterOrValue) => {
600
+ const value = typeof updaterOrValue === "function" ? updaterOrValue(
601
+ externalSorting != null ? externalSorting : []
602
+ ) : updaterOrValue;
603
+ (onSortingChange != null ? onSortingChange : setLocalSorting)(value);
604
+ } : setLocalSorting;
605
+ const columnFilterState = pagination ? externalColumnFilters != null ? externalColumnFilters : localColumnFilters : localColumnFilters;
606
+ const setColumnFilterState = pagination ? (updaterOrValue) => {
607
+ const value = typeof updaterOrValue === "function" ? updaterOrValue(externalColumnFilters != null ? externalColumnFilters : []) : updaterOrValue;
608
+ (onColumnFiltersChange != null ? onColumnFiltersChange : setLocalColumnFilters)(value);
609
+ } : setLocalColumnFilters;
610
+ const rowSelection = pagination ? externalRowSelection != null ? externalRowSelection : localRowSelection : localRowSelection;
611
+ const setRowSelection = pagination ? (updaterOrValue) => {
612
+ const value = typeof updaterOrValue === "function" ? updaterOrValue(externalRowSelection != null ? externalRowSelection : {}) : updaterOrValue;
613
+ (onRowSelectionChange != null ? onRowSelectionChange : setLocalRowSelection)(value);
614
+ } : setLocalRowSelection;
615
+ const dndId = useId();
616
+ const containerRef = React3.useRef(null);
617
+ const [columnVisibility, setColumnVisibility] = useState3(() => {
618
+ const initialVisibility = {};
619
+ columns.forEach((column) => {
620
+ var _a2, _b2;
621
+ if (column.id) {
622
+ initialVisibility[column.id] = (_b2 = (_a2 = column.meta) == null ? void 0 : _a2.visible) != null ? _b2 : true;
623
+ }
624
+ });
625
+ return initialVisibility;
626
+ });
627
+ const toggleColumnVisibility = useCallback(
628
+ (columnId, isVisible) => {
629
+ setColumnVisibility((prev) => __spreadProps(__spreadValues({}, prev), { [columnId]: isVisible }));
764
630
  },
765
- row.id
631
+ [setColumnVisibility]
766
632
  );
767
- }
768
- function PinnedColumns(_a) {
769
- var _b = _a, {
770
- pinDirection = "left",
771
- table,
772
- centerHeader,
773
- allSelectedAcrossPages,
774
- someSelectedAcrossPages,
775
- toggleSelectAllAcrossPages
776
- } = _b, props = __objRest(_b, [
777
- "pinDirection",
778
- "table",
779
- "centerHeader",
780
- "allSelectedAcrossPages",
781
- "someSelectedAcrossPages",
782
- "toggleSelectAllAcrossPages"
783
- ]);
784
- var _a2;
785
- const headerGroups = pinDirection === "left" ? table.getLeftHeaderGroups() : table.getRightHeaderGroups();
786
- return ((_a2 = headerGroups[0]) == null ? void 0 : _a2.headers.length) > 0 && /* @__PURE__ */ jsxs(
787
- "table",
633
+ const resetColumnVisibility = useCallback(() => {
634
+ setColumnVisibility(() => {
635
+ const initialVisibility = {};
636
+ columns.forEach((column) => {
637
+ var _a2, _b2;
638
+ if (column.id) {
639
+ initialVisibility[column.id] = (_b2 = (_a2 = column.meta) == null ? void 0 : _a2.visible) != null ? _b2 : true;
640
+ }
641
+ });
642
+ return initialVisibility;
643
+ });
644
+ }, [columns]);
645
+ const table = useReactTable({
646
+ columns,
647
+ data,
648
+ getCoreRowModel: getCoreRowModel(),
649
+ getSortedRowModel: getSortedRowModel(),
650
+ getFilteredRowModel: getFilteredRowModel(),
651
+ columnResizeMode: "onChange",
652
+ getRowId: (row, index) => {
653
+ var _a2;
654
+ return String((_a2 = row.id) != null ? _a2 : index + 1);
655
+ },
656
+ state: {
657
+ columnOrder,
658
+ sorting: sortingState,
659
+ columnFilters: columnFilterState,
660
+ rowSelection,
661
+ columnVisibility
662
+ },
663
+ initialState: {
664
+ columnPinning: {
665
+ left: predeterminedLeftPins,
666
+ right: predeterminedRightPins
667
+ }
668
+ },
669
+ enableColumnPinning: (predeterminedLeftPins == null ? void 0 : predeterminedLeftPins.length) > 0 || predeterminedRightPins.length > 0,
670
+ onColumnOrderChange: setColumnOrder,
671
+ onSortingChange: adaptTableStateSetter(setSortingState),
672
+ onColumnFiltersChange: adaptTableStateSetter(setColumnFilterState),
673
+ onRowSelectionChange: adaptTableStateSetter(setRowSelection),
674
+ filterFns: {
675
+ startsWith: (row, columnId, filterValue) => {
676
+ const cellValue = row == null ? void 0 : row.getValue(columnId);
677
+ if (!cellValue || !filterValue) {
678
+ return true;
679
+ }
680
+ return String(cellValue).toLowerCase().startsWith(String(filterValue).toLowerCase());
681
+ },
682
+ endsWith: (row, columnId, filterValue) => {
683
+ const cellValue = row == null ? void 0 : row.getValue(columnId);
684
+ if (!cellValue || !filterValue) {
685
+ return true;
686
+ }
687
+ return String(cellValue).toLowerCase().endsWith(String(filterValue).toLowerCase());
688
+ }
689
+ }
690
+ });
691
+ const allRowIds = pagination ? (_a = filteredSortedData == null ? void 0 : filteredSortedData.map((row) => String(row.id))) != null ? _a : [] : Array.from(
692
+ { length: totalRowCount != null ? totalRowCount : data.length },
693
+ (_, i) => String(i + 1)
694
+ );
695
+ const allSelectedAcrossPages = allRowIds.every(
696
+ (rowId) => rowSelection[rowId]
697
+ );
698
+ const someSelectedAcrossPages = !allSelectedAcrossPages && allRowIds.some((rowId) => rowSelection[rowId]);
699
+ const toggleSelectAllAcrossPages = () => {
700
+ setRowSelection((prev) => {
701
+ const isSelecting = !allSelectedAcrossPages;
702
+ if (isSelecting) {
703
+ const newSelection = {};
704
+ for (const rowId of allRowIds) {
705
+ newSelection[rowId] = true;
706
+ }
707
+ return __spreadValues(__spreadValues({}, prev), newSelection);
708
+ } else {
709
+ const updatedSelection = __spreadValues({}, prev);
710
+ for (const rowId of allRowIds) {
711
+ delete updatedSelection[rowId];
712
+ }
713
+ return updatedSelection;
714
+ }
715
+ });
716
+ };
717
+ useInfiniteScroll({
718
+ containerRef,
719
+ onLoadMore: onLoadMore != null ? onLoadMore : () => {
720
+ },
721
+ isLoading: isLoadingMore,
722
+ enabled: !pagination
723
+ });
724
+ const handleDragEnd = (event) => {
725
+ const { active, over } = event;
726
+ if (active && over && active.id !== over.id) {
727
+ setColumnOrder((prev) => {
728
+ const oldIndex = prev.indexOf(active.id);
729
+ const newIndex = prev.indexOf(over.id);
730
+ return arrayMove(prev, oldIndex, newIndex);
731
+ });
732
+ }
733
+ };
734
+ const sensors = useSensors(
735
+ useSensor(MouseSensor),
736
+ useSensor(TouchSensor),
737
+ useSensor(KeyboardSensor)
738
+ );
739
+ const visibleColumns = table.getVisibleLeafColumns();
740
+ const columnVirtualizer = useVirtualizer2({
741
+ count: visibleColumns.length,
742
+ estimateSize: (index) => visibleColumns[index].getSize(),
743
+ //estimate width of each column for accurate scrollbar dragging
744
+ getScrollElement: () => containerRef.current,
745
+ horizontal: true,
746
+ overscan: 3
747
+ //how many columns to render on each side off screen each way
748
+ });
749
+ const virtualColumns = columnVirtualizer.getVirtualItems();
750
+ let virtualPaddingLeft;
751
+ let virtualPaddingRight;
752
+ if (columnVirtualizer && (virtualColumns == null ? void 0 : virtualColumns.length)) {
753
+ virtualPaddingLeft = (_c = (_b = virtualColumns[0]) == null ? void 0 : _b.start) != null ? _c : 0;
754
+ virtualPaddingRight = columnVirtualizer.getTotalSize() - ((_e = (_d = virtualColumns[virtualColumns.length - 1]) == null ? void 0 : _d.end) != null ? _e : 0);
755
+ }
756
+ const empty = table.getRowModel().rows.length === 0;
757
+ return /* @__PURE__ */ jsx8(
758
+ DndContext,
788
759
  {
789
- className: clsx(
790
- "flex flex-col min-h-min sticky z-20 bg-background-grouped-primary-normal",
791
- pinDirection === "left" ? "left-0" : "right-0"
792
- ),
793
- children: [
794
- /* @__PURE__ */ jsx("thead", { className: "sticky top-0 z-20 grid", children: headerGroups.map((headerGroup) => {
795
- return /* @__PURE__ */ jsx("tr", { className: "flex w-full", children: headerGroup.headers.map((header) => {
796
- var _a3, _b2, _c;
797
- if (!header) {
798
- return;
799
- }
800
- if (typeof header.column.columnDef.header === "string") {
801
- const customHeaderWidth = (_a3 = header.column.columnDef.meta) == null ? void 0 : _a3.headerWidth;
802
- return /* @__PURE__ */ jsxs(
803
- DataCellHeader,
804
- {
805
- locked: true,
806
- header,
807
- center: centerHeader,
808
- width: customHeaderWidth,
809
- className: clsx(
810
- header.column.getCanSort() ? "cursor-pointer" : "cursor-grab",
811
- "group"
812
- ),
813
- children: [
814
- /* @__PURE__ */ jsx(Subheader, { tall: true, children: header.column.columnDef.header }),
815
- getSortIcon(header.column.getIsSorted()),
816
- !header.column.getIsSorted() && header.column.getCanSort() && getSortIcon(
817
- header.column.getNextSortingOrder(),
818
- true
760
+ id: dndId,
761
+ collisionDetection: closestCenter,
762
+ modifiers: [restrictToHorizontalAxis],
763
+ onDragEnd: handleDragEnd,
764
+ sensors,
765
+ children: /* @__PURE__ */ jsx8(
766
+ SortableContext,
767
+ {
768
+ items: columnOrder,
769
+ strategy: horizontalListSortingStrategy,
770
+ children: /* @__PURE__ */ jsxs5(
771
+ "div",
772
+ {
773
+ id,
774
+ className: "flex flex-col flex-1 h-full w-full rounded border border-border-primary-normal overflow-hidden text-text-primary-normal",
775
+ children: [
776
+ /* @__PURE__ */ jsxs5(
777
+ "div",
778
+ {
779
+ className: clsx5(
780
+ "flex overflow-auto scrollbar-thin relative contain-paint will-change-transform",
781
+ empty ? "overflow-y-hidden" : "h-full"
782
+ ),
783
+ ref: containerRef,
784
+ children: [
785
+ /* @__PURE__ */ jsx8(
786
+ PinnedColumns,
787
+ {
788
+ pinDirection: "left",
789
+ table,
790
+ tableContainerRef: containerRef,
791
+ pagination,
792
+ isLoadingMore,
793
+ hasMore,
794
+ showFilterRow,
795
+ enableColumnSelector
796
+ }
797
+ ),
798
+ /* @__PURE__ */ jsxs5("table", { className: "flex-1 flex flex-col min-h-min", children: [
799
+ /* @__PURE__ */ jsx8("thead", { className: "sticky top-0 z-10 grid", children: table.getCenterHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs5("tr", { className: "flex w-full", children: [
800
+ virtualPaddingLeft ? (
801
+ // fake empty column to the left for virtualization scroll padding
802
+ /* @__PURE__ */ jsx8(
803
+ "th",
804
+ {
805
+ style: { display: "flex", width: virtualPaddingLeft }
806
+ }
807
+ )
808
+ ) : null,
809
+ virtualColumns.map((virtualColumn) => {
810
+ var _a2, _b2, _c2, _d2, _e2;
811
+ const header = headerGroup.headers[virtualColumn.index];
812
+ if (!header) {
813
+ return;
814
+ }
815
+ if (typeof header.column.columnDef.header === "string") {
816
+ const customHeaderWidth = (_a2 = header.column.columnDef.meta) == null ? void 0 : _a2.headerWidth;
817
+ const cellValue = (_b2 = table.getRowModel().rows[0]) == null ? void 0 : _b2.getValue(header.column.id);
818
+ return /* @__PURE__ */ jsxs5(
819
+ DraggableCellHeader,
820
+ {
821
+ id: id ? `${id}-header-${header.id}` : void 0,
822
+ header,
823
+ locked: (_c2 = header.column.columnDef.meta) == null ? void 0 : _c2.locked,
824
+ center: centerHeader,
825
+ width: customHeaderWidth,
826
+ className: clsx5(
827
+ header.column.getCanSort() ? "cursor-pointer" : "cursor-grab",
828
+ "group",
829
+ {
830
+ "justify-end": typeof cellValue === "number"
831
+ }
832
+ ),
833
+ useMenuDefaultMinWidth,
834
+ children: [
835
+ /* @__PURE__ */ jsx8(Subheader, { tall: true, children: header.column.columnDef.header }),
836
+ getSortIcon(header.column.getIsSorted()),
837
+ !header.column.getIsSorted() && header.column.getCanSort() && getSortIcon(
838
+ header.column.getNextSortingOrder(),
839
+ true
840
+ ),
841
+ header.column.getSortIndex() !== -1 && table.getState().sorting.length > 1 && /* @__PURE__ */ jsx8(Subheader, { tall: true, children: header.column.getSortIndex() + 1 }),
842
+ /* @__PURE__ */ jsx8(
843
+ "div",
844
+ {
845
+ onDoubleClick: (e) => {
846
+ e.stopPropagation();
847
+ header.column.resetSize();
848
+ },
849
+ onMouseDown: (e) => {
850
+ e.stopPropagation();
851
+ header.getResizeHandler()(e);
852
+ },
853
+ onTouchStart: (e) => {
854
+ e.stopPropagation();
855
+ header.getResizeHandler()(e);
856
+ },
857
+ className: "absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
858
+ }
859
+ )
860
+ ]
861
+ },
862
+ header.id
863
+ );
864
+ }
865
+ return /* @__PURE__ */ jsx8(React3.Fragment, { children: ((_d2 = header.column.columnDef.meta) == null ? void 0 : _d2.checkbox) ? /* @__PURE__ */ jsx8(
866
+ DataGridCell,
867
+ {
868
+ id: id ? `${id}-header-${header.id}` : void 0,
869
+ type: "header",
870
+ component: "checkbox",
871
+ locked: (_e2 = header.column.columnDef.meta) == null ? void 0 : _e2.locked,
872
+ children: /* @__PURE__ */ jsx8(
873
+ Checkbox,
874
+ {
875
+ id: id ? `${id}-select-all-checkbox` : void 0,
876
+ checked: allSelectedAcrossPages,
877
+ indeterminate: someSelectedAcrossPages,
878
+ onChange: toggleSelectAllAcrossPages
879
+ }
880
+ )
881
+ }
882
+ ) : flexRender3(
883
+ header.column.columnDef.header,
884
+ header.getContext()
885
+ ) }, header.id);
886
+ }),
887
+ virtualPaddingRight ? (
888
+ //fake empty column to the right for virtualization scroll padding
889
+ /* @__PURE__ */ jsx8(
890
+ "th",
891
+ {
892
+ style: { display: "flex", width: virtualPaddingRight }
893
+ }
894
+ )
895
+ ) : null,
896
+ enableColumnSelector && /* @__PURE__ */ jsx8(
897
+ ColumnSelectorHeaderCell,
898
+ {
899
+ id: id ? `${id}-column-selector` : void 0,
900
+ table,
901
+ toggleColumnVisibility,
902
+ resetColumnVisibility
903
+ }
904
+ )
905
+ ] }, headerGroup.id)) }),
906
+ /* @__PURE__ */ jsx8(
907
+ TableBody,
908
+ {
909
+ id,
910
+ columnVirtualizer,
911
+ table,
912
+ tableContainerRef: containerRef,
913
+ virtualPaddingLeft,
914
+ virtualPaddingRight,
915
+ pagination,
916
+ isLoadingMore,
917
+ hasMore,
918
+ showFilterRow,
919
+ enableColumnSelector
920
+ }
921
+ )
922
+ ] }),
923
+ /* @__PURE__ */ jsx8(
924
+ PinnedColumns,
925
+ {
926
+ pinDirection: "right",
927
+ table,
928
+ tableContainerRef: containerRef,
929
+ pagination,
930
+ isLoadingMore,
931
+ hasMore,
932
+ showFilterRow,
933
+ enableColumnSelector
934
+ }
935
+ )
936
+ ]
937
+ }
938
+ ),
939
+ empty && /* @__PURE__ */ jsxs5(
940
+ "div",
941
+ {
942
+ className: clsx5(
943
+ NO_RESULTS_HEIGHT,
944
+ "flex flex-col items-center justify-center",
945
+ componentGap,
946
+ componentPadding
819
947
  ),
820
- header.column.getSortIndex() !== -1 && table.getState().sorting.length > 1 && /* @__PURE__ */ jsx(Subheader, { tall: true, children: header.column.getSortIndex() + 1 }),
821
- !((_b2 = header.column.columnDef.meta) == null ? void 0 : _b2.locked) && /* @__PURE__ */ jsx(
822
- "div",
823
- {
824
- onDoubleClick: (e) => {
825
- e.stopPropagation();
826
- header.column.resetSize();
827
- },
828
- onMouseDown: (e) => {
829
- e.stopPropagation();
830
- header.getResizeHandler()(e);
831
- },
832
- onTouchStart: (e) => {
833
- e.stopPropagation();
834
- header.getResizeHandler()(e);
835
- },
836
- className: "absolute right-0 inset-y-0 w-px bg-black cursor-col-resize"
837
- }
838
- )
839
- ]
840
- },
841
- header.id
842
- );
948
+ children: [
949
+ /* @__PURE__ */ jsx8(Subheader, { color: "text-secondary-normal", children: "No Results" }),
950
+ /* @__PURE__ */ jsx8(Paragraph, { color: "text-secondary-normal", children: "To view results, enter or update your search criteria." })
951
+ ]
952
+ }
953
+ ),
954
+ !hideStatusBar && /* @__PURE__ */ jsxs5("div", { className: "p-2 pt-[7px] border-t border-border-primary-normal h-full min-h-[34px]", children: [
955
+ pagination && /* @__PURE__ */ jsxs5("div", { className: "flex justify-between items-center", children: [
956
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-1 w-min", children: [
957
+ /* @__PURE__ */ jsx8(
958
+ Select,
959
+ {
960
+ id: id ? `${id}-pagesize-select` : void 0,
961
+ wrapperClassName: "!w-20",
962
+ value: pagination.pageSize.toString(),
963
+ onChange: (e) => {
964
+ var _a2;
965
+ return (_a2 = pagination.onPageSizeChange) == null ? void 0 : _a2.call(pagination, Number(e.target.value));
966
+ },
967
+ renderMenu: (props) => /* @__PURE__ */ jsx8(
968
+ Menu,
969
+ __spreadProps(__spreadValues({}, props), {
970
+ id: id ? `${id}-pagesize-menu` : void 0,
971
+ children: PAGE_SIZE_OPTIONS.map((option) => /* @__PURE__ */ jsx8(
972
+ MenuOption,
973
+ {
974
+ id: id ? `${id}-pagesize-option-${option}` : void 0,
975
+ selected: pagination.pageSize === option,
976
+ onClick: () => {
977
+ var _a2;
978
+ return (_a2 = pagination.onPageSizeChange) == null ? void 0 : _a2.call(pagination, option);
979
+ },
980
+ children: option
981
+ },
982
+ option
983
+ ))
984
+ })
985
+ )
986
+ }
987
+ ),
988
+ /* @__PURE__ */ jsx8(Label, { children: "Per Page" })
989
+ ] }),
990
+ /* @__PURE__ */ jsxs5("div", { className: "flex items-center gap-2", children: [
991
+ /* @__PURE__ */ jsx8(
992
+ Button,
993
+ {
994
+ id: id ? `${id}-prev-page-button` : void 0,
995
+ iconOnly: true,
996
+ leftIcon: /* @__PURE__ */ jsx8(Icon, { name: "chevron_left" }),
997
+ onClick: () => pagination.onPageChange(pagination.pageIndex - 1),
998
+ variant: "tertiary",
999
+ disabled: pagination.pageIndex === 0
1000
+ }
1001
+ ),
1002
+ /* @__PURE__ */ jsxs5(Paragraph, { children: [
1003
+ pagination.pageIndex * pagination.pageSize + 1,
1004
+ " -",
1005
+ " ",
1006
+ Math.min(
1007
+ (pagination.pageIndex + 1) * pagination.pageSize,
1008
+ pagination.total
1009
+ ),
1010
+ " ",
1011
+ "of ",
1012
+ pagination.total
1013
+ ] }),
1014
+ /* @__PURE__ */ jsx8(
1015
+ Button,
1016
+ {
1017
+ id: id ? `${id}-next-page-button` : void 0,
1018
+ iconOnly: true,
1019
+ leftIcon: /* @__PURE__ */ jsx8(Icon, { name: "chevron_right" }),
1020
+ onClick: () => pagination.onPageChange(pagination.pageIndex + 1),
1021
+ variant: "tertiary",
1022
+ disabled: (pagination.pageIndex + 1) * pagination.pageSize >= pagination.total
1023
+ }
1024
+ )
1025
+ ] })
1026
+ ] }),
1027
+ status && /* @__PURE__ */ jsx8(Paragraph, { children: status })
1028
+ ] })
1029
+ ]
843
1030
  }
844
- return /* @__PURE__ */ jsx(React.Fragment, { children: ((_c = header.column.columnDef.meta) == null ? void 0 : _c.checkbox) ? /* @__PURE__ */ jsx(DataGridCell, { type: "header", component: "checkbox", locked: true, children: /* @__PURE__ */ jsx(
845
- Checkbox,
846
- {
847
- checked: allSelectedAcrossPages,
848
- indeterminate: someSelectedAcrossPages,
849
- onChange: toggleSelectAllAcrossPages
850
- }
851
- ) }) : flexRender(
852
- header.column.columnDef.header,
853
- header.getContext()
854
- ) }, header.id);
855
- }) }, headerGroup.id);
856
- }) }),
857
- /* @__PURE__ */ jsx(
858
- TableBody,
859
- __spreadProps(__spreadValues({}, props), {
860
- table,
861
- locked: true,
862
- pinDirection
863
- })
864
- )
865
- ]
1031
+ )
1032
+ }
1033
+ )
866
1034
  }
867
1035
  );
868
1036
  }
869
- var LoadingCell = ({
870
- id,
871
- column
872
- }) => {
873
- const key = `loading-${column.id}`;
874
- if (column.cell === "checkbox") {
875
- return /* @__PURE__ */ jsx(DataGridCell, { id: id ? `${id}-${key}` : void 0, children: /* @__PURE__ */ jsx(Checkbox, { id: id ? `${id}-${key}-checkbox` : void 0, disabled: true }) }, key);
876
- }
877
- if (column.cell === "input") {
878
- return /* @__PURE__ */ jsx(
879
- DataGridCell,
880
- {
881
- id: id ? `${id}-${key}` : void 0,
882
- component: "input",
883
- children: /* @__PURE__ */ jsx(
884
- Input,
885
- {
886
- id: id ? `${id}-${key}-input` : void 0,
887
- align: "left",
888
- disabled: true,
889
- wrapperClassName: "!rounded-none !border-0"
890
- }
891
- )
892
- },
893
- key
1037
+ DataGrid.displayName = "DataGrid";
1038
+ function adaptTableStateSetter(setter) {
1039
+ return (valueOrFn) => {
1040
+ setter(
1041
+ (prev) => typeof valueOrFn === "function" ? valueOrFn(prev) : valueOrFn
894
1042
  );
895
- }
896
- return /* @__PURE__ */ jsx(DataGridCell, { id: id ? `${id}-${key}` : void 0, children: /* @__PURE__ */ jsx("div", { className: "bg-linear-270 to-neutral-300/[24%] from-neutral-300/[12%] rounded-xs w-full max-w-25 h-6" }) }, key);
897
- };
898
- function ColumnSelectorHeaderCell({
899
- id,
900
- table,
901
- toggleColumnVisibility,
902
- resetColumnVisibility
903
- }) {
904
- const ref = useRef(null);
905
- const [show, setShow] = useState(false);
906
- return /* @__PURE__ */ jsxs(
907
- DataGridCell,
908
- {
909
- id,
910
- width: "48",
911
- type: "header",
912
- color: "text-secondary-normal",
913
- ref,
914
- children: [
915
- /* @__PURE__ */ jsx(
916
- Button,
917
- {
918
- id: id ? `${id}-button` : void 0,
919
- onClick: () => setShow((prev) => !prev),
920
- variant: "navigation",
921
- iconOnly: true,
922
- leftIcon: /* @__PURE__ */ jsx(Icon, { name: "tune" })
923
- }
924
- ),
925
- /* @__PURE__ */ jsxs(
926
- Menu,
927
- {
928
- id: id ? `${id}-menu` : void 0,
929
- positionTo: ref,
930
- position: "bottom-right",
931
- show,
932
- setShow,
933
- children: [
934
- /* @__PURE__ */ jsx(
935
- Button,
936
- {
937
- id: id ? `${id}-reset-button` : void 0,
938
- variant: "tertiary",
939
- onClick: () => {
940
- resetColumnVisibility();
941
- setShow(false);
942
- },
943
- children: "Reset to default"
944
- }
945
- ),
946
- table.getAllColumns().filter((x) => {
947
- var _a;
948
- return (_a = x.columnDef.meta) == null ? void 0 : _a.inVisibilityMenu;
949
- }).map((column) => /* @__PURE__ */ jsx(
950
- ColumnSelectorMenuOption,
951
- {
952
- id: id ? `${id}-option-${column.id}` : void 0,
953
- column,
954
- toggleColumnVisibility
955
- },
956
- column.id
957
- ))
958
- ]
959
- }
960
- )
961
- ]
962
- }
963
- );
964
- }
965
- function ColumnSelectorMenuOption({
966
- id,
967
- column,
968
- toggleColumnVisibility
969
- }) {
970
- const [isVisible, setIsVisible] = useState(column.getIsVisible());
971
- const label = typeof column.columnDef.header === "string" ? column.columnDef.header : null;
972
- return /* @__PURE__ */ jsx(MenuOption, { id, selected: isVisible, defaultChecked: isVisible, children: /* @__PURE__ */ jsx(
973
- Checkbox,
974
- {
975
- id: id ? `${id}-checkbox` : void 0,
976
- label: label != null ? label : "Unknown",
977
- checked: isVisible,
978
- onChange: (e) => {
979
- setIsVisible(e.target.checked);
980
- toggleColumnVisibility(column.id, e.target.checked);
981
- }
982
- }
983
- ) });
984
- }
985
- function getSortIcon(sort, nextSort = false) {
986
- const iconClassName = clsx(
987
- "text-icon-on-action-primary-normal",
988
- nextSort && "hidden group-hover:block"
989
- );
990
- if (sort === "asc")
991
- return /* @__PURE__ */ jsx(Icon, { size: 16, className: iconClassName, name: "arrow_upward" });
992
- if (sort === "desc")
993
- return /* @__PURE__ */ jsx(Icon, { size: 16, className: iconClassName, name: "arrow_downward" });
994
- return null;
1043
+ };
995
1044
  }
996
1045
  export {
997
- DataGrid
1046
+ Button,
1047
+ Checkbox,
1048
+ DataCellHeader,
1049
+ DataGrid,
1050
+ DataGridCell,
1051
+ DragAlongCell,
1052
+ DraggableCellHeader,
1053
+ Icon,
1054
+ Input,
1055
+ Label,
1056
+ Menu,
1057
+ MenuOption,
1058
+ Paragraph,
1059
+ Search,
1060
+ Select,
1061
+ Subheader,
1062
+ Tooltip
998
1063
  };