@fuf-stack/megapixels 1.0.0-next.1 → 1.0.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.
Files changed (36) hide show
  1. package/README.md +1 -3
  2. package/dist/DataTable/index.d.mts +2 -2
  3. package/dist/DataTable/index.mjs +1 -1
  4. package/dist/{DataTable-Ml6QySfA.mjs → DataTable-CRSjenVg.mjs} +462 -608
  5. package/dist/DataTable-CRSjenVg.mjs.map +1 -0
  6. package/dist/Filter/index.d.mts +1 -1
  7. package/dist/Filter/index.mjs +1 -1
  8. package/dist/{Filter-DXRC8M5M.mjs → Filter-BTmKbroE.mjs} +91 -160
  9. package/dist/Filter-BTmKbroE.mjs.map +1 -0
  10. package/dist/Notification/index.d.mts +1 -1
  11. package/dist/Notification/index.mjs +1 -1
  12. package/dist/{Notification-Dei4OOE6.mjs → Notification-bHSDnmsA.mjs} +9 -12
  13. package/dist/Notification-bHSDnmsA.mjs.map +1 -0
  14. package/dist/VirtualList/index.d.mts +1 -1
  15. package/dist/VirtualList/index.mjs +1 -1
  16. package/dist/VirtualList-C7T47V_m.mjs +152 -0
  17. package/dist/VirtualList-C7T47V_m.mjs.map +1 -0
  18. package/dist/{index-Dv6cWC7j.d.mts → index-BxhYTX-_.d.mts} +34 -55
  19. package/dist/{index-Dv6cWC7j.d.mts.map → index-BxhYTX-_.d.mts.map} +1 -1
  20. package/dist/{index-Bs5iWkFO.d.mts → index-CNLdZuF-.d.mts} +226 -239
  21. package/dist/{index-Bs5iWkFO.d.mts.map → index-CNLdZuF-.d.mts.map} +1 -1
  22. package/dist/{index-B_ebAhwH.d.mts → index-D0uHFskO.d.mts} +61 -92
  23. package/dist/{index-B_ebAhwH.d.mts.map → index-D0uHFskO.d.mts.map} +1 -1
  24. package/dist/{index-ClWVkO3I.d.mts → index-QjwjR0tT.d.mts} +5 -9
  25. package/dist/index-QjwjR0tT.d.mts.map +1 -0
  26. package/dist/index.d.mts +5 -5
  27. package/dist/index.mjs +5 -6
  28. package/dist/{useInfiniteVirtualizer-BBgVBqJa.mjs → useInfiniteVirtualizer-CHBE4y7W.mjs} +2 -3
  29. package/dist/{useInfiniteVirtualizer-BBgVBqJa.mjs.map → useInfiniteVirtualizer-CHBE4y7W.mjs.map} +1 -1
  30. package/package.json +12 -12
  31. package/dist/DataTable-Ml6QySfA.mjs.map +0 -1
  32. package/dist/Filter-DXRC8M5M.mjs.map +0 -1
  33. package/dist/Notification-Dei4OOE6.mjs.map +0 -1
  34. package/dist/VirtualList-sPPTnS7m.mjs +0 -193
  35. package/dist/VirtualList-sPPTnS7m.mjs.map +0 -1
  36. package/dist/index-ClWVkO3I.d.mts.map +0 -1
@@ -1,138 +1,46 @@
1
- import { t as useInfiniteVirtualizer } from "./useInfiniteVirtualizer-BBgVBqJa.mjs";
2
- import { useStyling } from "@fuf-stack/pixels/StylingProvider";
3
- import { cn, tv } from "@fuf-stack/pixel-utils";
1
+ import { t as useInfiniteVirtualizer } from "./useInfiniteVirtualizer-CHBE4y7W.mjs";
4
2
  import { Fragment, useCallback, useMemo, useRef, useState } from "react";
5
- import { flexRender, getCoreRowModel, getExpandedRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
3
+ import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
4
+ import { ScrollShadow } from "@fuf-stack/pixels/ScrollShadow";
5
+ import { createExpandedRowModel, createFilteredRowModel, createPaginatedRowModel, createSortedRowModel, filterFns, flexRender, sortFns, stockFeatures, tableFeatures, useTable } from "@tanstack/react-table";
6
6
  import { Button } from "@fuf-stack/pixels/Button";
7
- import { CheckboxButton, CheckboxField } from "react-aria-components";
7
+ import { Checkbox } from "@base-ui/react/checkbox";
8
8
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
9
  import { Menu } from "@fuf-stack/pixels/Menu";
10
- import { ScrollShadow } from "@fuf-stack/pixels/ScrollShadow";
11
10
  import { LuColumns3 } from "react-icons/lu";
12
- //#region src/DataTable/dataTableVariants.ts
13
- /** Styling slots for DataTable */
14
- const dataTableVariants = tv({ slots: {
15
- /** Root wrapper around toolbar, table, and pagination */
16
- base: "w-full",
17
- /** Selection checkbox control in header/rows */
18
- checkbox: [
19
- "relative inline-flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center",
20
- "rounded border border-divider bg-background align-middle text-foreground",
21
- "data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-focus"
22
- ],
23
- /** Checkmark/minus glyph inside the selection checkbox */
24
- checkboxIndicator: "pointer-events-none absolute inset-0 flex items-center justify-center text-[10px] leading-none",
25
- /** Empty-state cell shown when no rows match */
26
- emptyCell: "h-24 text-center text-default-500",
27
- /** Button used by the injected expandable-row toggle column */
28
- expandButton: "h-8 min-w-8 px-0 disabled:cursor-not-allowed data-[disabled=true]:pointer-events-auto data-[disabled=true]:cursor-not-allowed",
29
- /** Table cell that spans all visible columns for expanded content */
30
- expandedCell: "p-4 text-sm text-default-600",
31
- /** Table row rendered directly below an expanded data row */
32
- expandedRow: "bg-content1",
33
- /** Icon wrapper inside the expandable-row toggle button */
34
- expandIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-500",
35
- /** Header/body cell reserved for the expandable-row toggle column */
36
- expansionCell: "w-10 px-0 text-center",
37
- /** Inner wrapper that visually centers expandable-row toggle buttons */
38
- expansionCellContent: "flex justify-center",
39
- /** Loading-state cell shown while data is being fetched */
40
- loadingCell: "h-24 text-center text-default-500",
41
- /** Loading/retry cell shown when fetching next page in infinite mode */
42
- loadingMoreCell: "flex h-14 items-center justify-center text-default-500",
43
- /** Plain header content used for non-sortable columns */
44
- nonSortableHeaderContent: "inline-flex items-center",
45
- /** Label wrapping the "Rows per page" selector */
46
- pageSizeLabel: "flex items-center gap-2 text-sm text-default-500",
47
- /** Menu trigger used to choose page size */
48
- pageSizeSelect: "min-w-16 justify-between gap-2",
49
- /** "Page X of Y" summary text */
50
- pageSummary: "text-sm text-default-500",
51
- /** Pagination footer container */
52
- pagination: "flex items-center gap-2 py-4",
53
- /** Shared class applied to pagination action buttons */
54
- paginationButton: "",
55
- /** Placeholder rows for unknown-yet data in total-count mode */
56
- placeholderCell: "h-10 animate-pulse bg-default-100/60 p-3 dark:bg-default-100/10",
57
- /** Scroll container in virtualized/infinite mode */
58
- scrollContainer: "overflow-y-auto overflow-x-hidden",
59
- /** Optional styling slot for ScrollShadow wrapper behavior */
60
- scrollShadow: "",
61
- /** Built-in text search input(s) rendered in the toolbar */
62
- searchInput: [
63
- "h-10 w-full max-w-sm rounded-small border-2 border-default-200 bg-transparent px-3 text-sm text-foreground",
64
- "outline-none transition-colors",
65
- "placeholder:text-default-500 hover:border-default-400 data-[focused=true]:border-focus dark:border-default-100"
66
- ],
67
- /** Header/body cell reserved for the selection checkbox column */
68
- selectionCell: "w-10 px-0 text-center",
69
- /** Inner wrapper that visually centers selection checkboxes in their cells */
70
- selectionCellContent: "flex justify-center",
71
- /** Selected rows summary text in pagination footer */
72
- selectionSummary: "mr-auto text-sm text-default-500",
73
- /** Header button used for sortable columns */
74
- sortButton: "-ml-2 min-w-0 justify-start gap-1.5 px-2 text-left font-medium text-foreground data-[sortable=true]:cursor-pointer",
75
- /** Icon wrapper for sort direction indicators */
76
- sortIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-400",
77
- /** Semantic table element */
78
- table: "w-full caption-bottom text-sm",
79
- /** Border/overflow container around the table */
80
- tableWrapper: "overflow-hidden rounded-md border border-divider",
81
- /** Semantic table body wrapper */
82
- tbody: "",
83
- /** Standard table data cell */
84
- td: "p-3 align-middle text-foreground",
85
- /** Standard table header cell */
86
- th: "h-10 px-3 text-left align-middle font-medium text-foreground",
87
- /** Table header row group background */
88
- thead: "bg-content2",
89
- /** Toolbar container for filters/actions */
90
- toolbar: "flex items-center gap-3 py-4",
91
- /** Optional custom toolbar content area */
92
- toolbarContent: "flex flex-1 items-center",
93
- /** Table row styling including selected-row state */
94
- tr: "border-b border-divider last:border-b-0 data-[state=selected]:bg-content2/60",
95
- /** Checkmark indicator area inside view options menu items */
96
- viewOptionsIndicator: "mr-2 inline-flex w-3 justify-center",
97
- /** Individual view-options menu item */
98
- viewOptionsItem: ["data-highlighted:bg-default-100 dark:data-highlighted:bg-default-100/20", "flex cursor-pointer items-center rounded px-2 py-1 text-sm text-foreground outline-none"],
99
- /** Dropdown menu panel for view options */
100
- viewOptionsMenu: "z-50 min-w-40 rounded-md border border-divider bg-background p-1 shadow-md",
101
- /** Positioner wrapper used by menu popover */
102
- viewOptionsPositioner: "outline-none",
103
- /** Trigger button for the "Columns" menu */
104
- viewOptionsTrigger: "ml-auto gap-2"
105
- } });
106
- //#endregion
107
- //#region src/DataTable/subcomponents/DataTableCheckbox.tsx
108
- /**
109
- * Row selection checkbox with a mixed state for partially selected pages
110
- *
111
- * @see https://react-aria.adobe.com/Checkbox
112
- */
11
+ // src/DataTable/features.ts
12
+ const dataTableFeatures = tableFeatures({
13
+ ...stockFeatures,
14
+ expandedRowModel: createExpandedRowModel(),
15
+ filteredRowModel: createFilteredRowModel(),
16
+ paginatedRowModel: createPaginatedRowModel(),
17
+ sortedRowModel: createSortedRowModel(),
18
+ filterFns,
19
+ sortFns
20
+ });
21
+ // src/DataTable/Subcomponents/DataTableCheckbox.tsx
22
+ /** Small checkbox wrapper used by DataTable selection UI. */
113
23
  const DataTableCheckbox = ({ ariaLabel, checked, className = void 0, checkedIcon = "✓", indeterminate = false, indeterminateIcon = "−", onCheckedChange, testId = void 0 }) => {
114
24
  const indicatorIcon = indeterminate ? indeterminateIcon : checkedIcon;
115
25
  const resolvedIndicatorIcon = indicatorIcon === false ? null : indicatorIcon;
116
- return /* @__PURE__ */ jsx(CheckboxField, {
26
+ return /* @__PURE__ */ jsx(Checkbox.Root, {
117
27
  "aria-label": ariaLabel,
118
- isIndeterminate: indeterminate,
119
- isSelected: checked,
120
- onChange: onCheckedChange,
121
- children: /* @__PURE__ */ jsx(CheckboxButton, {
122
- className: className?.checkbox,
123
- "data-slot": "checkbox",
124
- "data-testid": testId,
125
- children: checked || indeterminate ? /* @__PURE__ */ jsx("span", {
126
- "aria-hidden": "true",
127
- className: className?.checkboxIndicator,
128
- "data-slot": "checkbox-indicator",
129
- children: resolvedIndicatorIcon
130
- }) : null
28
+ checked,
29
+ className: className?.checkbox,
30
+ "data-slot": "checkbox",
31
+ "data-testid": testId,
32
+ indeterminate,
33
+ onCheckedChange: (nextChecked) => {
34
+ onCheckedChange(Boolean(nextChecked));
35
+ },
36
+ children: /* @__PURE__ */ jsx(Checkbox.Indicator, {
37
+ className: className?.checkboxIndicator,
38
+ "data-slot": "checkbox-indicator",
39
+ children: resolvedIndicatorIcon
131
40
  })
132
41
  });
133
42
  };
134
- //#endregion
135
- //#region src/DataTable/hooks/useDataTableController.tsx
43
+ // src/DataTable/hooks/useDataTableController.tsx
136
44
  /** Stable id used for the injected row-selection column. */
137
45
  const SELECTION_COLUMN_ID = "__select";
138
46
  /** Stable id used for the injected row-expansion column. */
@@ -359,20 +267,18 @@ const useDataTableController = ({ checkboxClassNames, columns, data, enableExpan
359
267
  });
360
268
  };
361
269
  return {
362
- table: useReactTable({
270
+ table: useTable({
271
+ features: dataTableFeatures,
363
272
  columns: tableColumns,
364
273
  data,
365
274
  defaultColumn: { enableSorting: false },
366
275
  enableExpanding: enableExpandableRows,
367
276
  enableRowSelection,
368
- getCoreRowModel: getCoreRowModel(),
369
- getExpandedRowModel: enableExpandableRows ? getExpandedRowModel() : void 0,
370
- getFilteredRowModel: enableServerMode ? void 0 : getFilteredRowModel(),
371
- getPaginationRowModel: enablePagination ? getPaginationRowModel() : void 0,
277
+ manualExpanding: !enableExpandableRows,
278
+ manualPagination: !enablePagination,
372
279
  getRowCanExpand: (row) => {
373
280
  return hasExpandableRowContent || row.subRows.length > 0;
374
281
  },
375
- getSortedRowModel: enableServerMode ? void 0 : getSortedRowModel(),
376
282
  getSubRows,
377
283
  manualFiltering: enableServerMode,
378
284
  manualSorting: enableServerMode,
@@ -394,8 +300,162 @@ const useDataTableController = ({ checkboxClassNames, columns, data, enableExpan
394
300
  tableColumns
395
301
  };
396
302
  };
397
- //#endregion
398
- //#region src/DataTable/subcomponents/DataTablePagination.tsx
303
+ // src/DataTable/Subcomponents/DataTableCells.tsx
304
+ const getColumnKind = (columnId) => {
305
+ if (columnId === "__expand") return "expansion";
306
+ if (columnId === "__select") return "selection";
307
+ return "data";
308
+ };
309
+ const getCellDataSlot = (columnKind) => {
310
+ if (columnKind === "expansion") return "expansion-cell";
311
+ if (columnKind === "selection") return "selection-cell";
312
+ return "td";
313
+ };
314
+ const getHeaderDataSlot = (columnKind) => {
315
+ if (columnKind === "data") return "th";
316
+ return getCellDataSlot(columnKind);
317
+ };
318
+ const getControlCellContentDataSlot = (columnKind) => {
319
+ if (columnKind === "expansion") return "expansion-cell-content";
320
+ return "selection-cell-content";
321
+ };
322
+ /**
323
+ * Flex sizing for cells in virtualized mode.
324
+ *
325
+ * Because virtual rows are absolutely positioned, we cannot rely on native
326
+ * table layout for column width sync; header/body cells must apply matching
327
+ * explicit sizing rules.
328
+ */
329
+ const getVirtualCellStyle = (columnKind, size) => {
330
+ if (columnKind === "data") return {
331
+ flex: `1 1 ${size}px`,
332
+ minWidth: 0,
333
+ width: size
334
+ };
335
+ return {
336
+ flex: `0 0 ${size}px`,
337
+ width: size
338
+ };
339
+ };
340
+ /** Shared row positioning style for full-width virtual rows. */
341
+ const virtualFullWidthRowStyle = (start) => {
342
+ return {
343
+ display: "flex",
344
+ position: "absolute",
345
+ transform: `translateY(${start}px)`,
346
+ width: "100%"
347
+ };
348
+ };
349
+ /** Shared single-cell style for full-width virtual rows. */
350
+ const virtualFullWidthCellStyle = {
351
+ flex: "1 1 auto",
352
+ width: "100%"
353
+ };
354
+ /**
355
+ * Renders one header cell and encapsulates sortable/non-sortable behavior.
356
+ */
357
+ const DataTableHeaderCell = ({ classNames, header, sortIcons = void 0, virtualized = false }) => {
358
+ const canSort = header.column.getCanSort();
359
+ const columnKind = getColumnKind(header.column.id);
360
+ const isExpansionColumn = columnKind === "expansion";
361
+ const isSelectionColumn = columnKind === "selection";
362
+ const sortState = header.column.getIsSorted();
363
+ const sortIndicator = getSortIndicator(canSort, sortState, sortIcons);
364
+ if (header.isPlaceholder) return /* @__PURE__ */ jsx("th", {
365
+ "aria-label": "Empty column header",
366
+ className: classNames.th,
367
+ "data-slot": getHeaderDataSlot(columnKind)
368
+ }, header.id);
369
+ return /* @__PURE__ */ jsx("th", {
370
+ className: cn(classNames.th, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
371
+ "data-slot": getHeaderDataSlot(columnKind),
372
+ style: virtualized ? {
373
+ alignItems: "center",
374
+ display: "flex",
375
+ ...getVirtualCellStyle(columnKind, header.getSize())
376
+ } : void 0,
377
+ children: canSort ? /* @__PURE__ */ jsxs(Button, {
378
+ className: classNames.sortButton,
379
+ "data-sortable": canSort,
380
+ dataSlot: "sort-button",
381
+ onClick: () => {
382
+ header.column.toggleSorting(sortState === "asc");
383
+ },
384
+ size: "sm",
385
+ variant: "light",
386
+ children: [flexRender(header.column.columnDef.header, header.getContext()), sortIndicator ? /* @__PURE__ */ jsx("span", {
387
+ "aria-hidden": "true",
388
+ className: classNames.sortIcon,
389
+ "data-slot": "sort-icon",
390
+ children: sortIndicator
391
+ }) : null]
392
+ }) : /* @__PURE__ */ jsx("div", {
393
+ className: cn(classNames.nonSortableHeaderContent, isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
394
+ "data-slot": columnKind === "data" ? "non-sortable-header-content" : getControlCellContentDataSlot(columnKind),
395
+ children: flexRender(header.column.columnDef.header, header.getContext())
396
+ })
397
+ }, header.id);
398
+ };
399
+ /**
400
+ * Renders one body cell and hides control-column wrapper details from row loops.
401
+ */
402
+ const DataTableBodyCell = ({ cell, classNames, virtualized = false }) => {
403
+ const columnKind = getColumnKind(cell.column.id);
404
+ const isExpansionColumn = columnKind === "expansion";
405
+ const isSelectionColumn = columnKind === "selection";
406
+ const isControlColumn = columnKind !== "data";
407
+ const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
408
+ const expansionIndent = isExpansionColumn && cell.row.depth > 0 ? { paddingLeft: `${cell.row.depth * 1.25}rem` } : void 0;
409
+ return /* @__PURE__ */ jsx("td", {
410
+ className: cn(classNames.td, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
411
+ "data-slot": getCellDataSlot(columnKind),
412
+ style: virtualized ? getVirtualCellStyle(columnKind, cell.column.getSize()) : void 0,
413
+ children: isControlColumn ? /* @__PURE__ */ jsx("div", {
414
+ className: cn(isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
415
+ "data-slot": getControlCellContentDataSlot(columnKind),
416
+ style: expansionIndent,
417
+ children: cellContent
418
+ }) : cellContent
419
+ }, cell.id);
420
+ };
421
+ // src/DataTable/Subcomponents/DataTableBodyRows.tsx
422
+ /**
423
+ * Standard row renderer used in non-virtualized table mode.
424
+ *
425
+ * It renders:
426
+ * - each data row
427
+ * - an optional sibling expanded-content row that spans all visible columns
428
+ */
429
+ const DataTableBodyRows = ({ classNames, expandableRows = void 0, rows, visibleColumnCount, virtualized = false }) => {
430
+ return rows.map((row) => {
431
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("tr", {
432
+ className: classNames.tr,
433
+ "data-slot": "tr",
434
+ "data-state": row.getIsSelected() ? "selected" : void 0,
435
+ style: virtualized ? {
436
+ display: "flex",
437
+ width: "100%"
438
+ } : void 0,
439
+ children: row.getVisibleCells().map((cell) => {
440
+ return /* @__PURE__ */ jsx(DataTableBodyCell, {
441
+ cell,
442
+ classNames,
443
+ virtualized
444
+ }, cell.id);
445
+ })
446
+ }), expandableRows?.renderContent && row.getIsExpanded() ? /* @__PURE__ */ jsx("tr", {
447
+ className: cn(classNames.tr, classNames.expandedRow),
448
+ "data-slot": "expanded-row",
449
+ children: /* @__PURE__ */ jsx("td", {
450
+ className: classNames.expandedCell,
451
+ colSpan: visibleColumnCount,
452
+ "data-slot": "expanded-cell",
453
+ children: expandableRows.renderContent(row)
454
+ })
455
+ }) : null] }, row.id);
456
+ });
457
+ };
458
+ // src/DataTable/Subcomponents/DataTablePagination.tsx
399
459
  const ChevronDownIcon = () => {
400
460
  return /* @__PURE__ */ jsx("svg", {
401
461
  "aria-hidden": "true",
@@ -413,9 +473,9 @@ const ChevronDownIcon = () => {
413
473
  })
414
474
  });
415
475
  };
416
- /** Footer controls for paging, page size, and selected-row summary */
417
- const DataTablePagination = ({ className: classNames, pageSizeOptions, showRowsPerPage, showSelectionSummary, table, testId = void 0 }) => {
418
- const { pageSize } = table.getState().pagination;
476
+ /** Footer controls for paging, page size, and selected-row summary. */
477
+ const DataTablePagination = ({ classNames, pageSizeOptions, showRowsPerPage, showSelectionSummary, table, testId = void 0 }) => {
478
+ const { pageSize } = table.state.pagination;
419
479
  const selectedRowCount = table.getFilteredSelectedRowModel().rows.length;
420
480
  const pageSizeItems = pageSizeOptions.map((size) => {
421
481
  return {
@@ -475,7 +535,7 @@ const DataTablePagination = ({ className: classNames, pageSizeOptions, showRowsP
475
535
  "data-slot": "page-summary",
476
536
  children: [
477
537
  "Page ",
478
- table.getState().pagination.pageIndex + 1,
538
+ table.state.pagination.pageIndex + 1,
479
539
  " of",
480
540
  " ",
481
541
  Math.max(table.getPageCount(), 1)
@@ -508,217 +568,60 @@ const DataTablePagination = ({ className: classNames, pageSizeOptions, showRowsP
508
568
  ]
509
569
  });
510
570
  };
511
- //#endregion
512
- //#region src/DataTable/subcomponents/dataTableCellHelpers.ts
513
- const getColumnKind = (columnId) => {
514
- if (columnId === "__expand") return "expansion";
515
- if (columnId === "__select") return "selection";
516
- return "data";
517
- };
518
- const getCellDataSlot = (columnKind) => {
519
- if (columnKind === "expansion") return "expansion-cell";
520
- if (columnKind === "selection") return "selection-cell";
521
- return "td";
522
- };
523
- const getHeaderDataSlot = (columnKind) => {
524
- if (columnKind === "data") return "th";
525
- return getCellDataSlot(columnKind);
526
- };
527
- const getControlCellContentDataSlot = (columnKind) => {
528
- if (columnKind === "expansion") return "expansion-cell-content";
529
- return "selection-cell-content";
530
- };
571
+ // src/DataTable/Subcomponents/DataTableViewOptions.tsx
531
572
  /**
532
- * Flex sizing for cells in virtualized mode.
533
- *
534
- * Because virtual rows are absolutely positioned, we cannot rely on native
535
- * table layout for column width sync; header/body cells must apply matching
536
- * explicit sizing rules.
573
+ * Resolves a human-readable label for a column, preferring its string header
574
+ * over the raw TanStack column id (e.g. "Status" instead of "status").
537
575
  */
538
- const getVirtualCellStyle = (columnKind, size) => {
539
- if (columnKind === "data") return {
540
- flex: `1 1 ${size}px`,
541
- minWidth: 0,
542
- width: size
543
- };
544
- return {
545
- flex: `0 0 ${size}px`,
546
- width: size
547
- };
548
- };
549
- /** Shared row positioning style for full-width virtual rows. */
550
- const virtualFullWidthRowStyle = (start) => {
551
- return {
552
- display: "flex",
553
- position: "absolute",
554
- transform: `translateY(${start}px)`,
555
- width: "100%"
556
- };
557
- };
558
- /** Shared single-cell style for full-width virtual rows. */
559
- const virtualFullWidthCellStyle = {
560
- flex: "1 1 auto",
561
- width: "100%"
576
+ const getColumnLabel = (column) => {
577
+ const { header } = column.columnDef;
578
+ return typeof header === "string" ? header : column.id;
562
579
  };
563
- //#endregion
564
- //#region src/DataTable/subcomponents/DataTableBodyCell.tsx
565
- /**
566
- * Renders one body cell and hides control-column wrapper details from row loops.
567
- */
568
- const DataTableBodyCell = ({ cell, className: classNames, virtualized = false }) => {
569
- const columnKind = getColumnKind(cell.column.id);
570
- const isExpansionColumn = columnKind === "expansion";
571
- const isSelectionColumn = columnKind === "selection";
572
- const isControlColumn = columnKind !== "data";
573
- const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
574
- const expansionIndent = isExpansionColumn && cell.row.depth > 0 ? { paddingLeft: `${cell.row.depth * 1.25}rem` } : void 0;
575
- return /* @__PURE__ */ jsx("td", {
576
- className: cn(classNames.td, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
577
- "data-slot": getCellDataSlot(columnKind),
578
- style: virtualized ? getVirtualCellStyle(columnKind, cell.column.getSize()) : void 0,
579
- children: isControlColumn ? /* @__PURE__ */ jsx("div", {
580
- className: cn(isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
581
- "data-slot": getControlCellContentDataSlot(columnKind),
582
- style: expansionIndent,
583
- children: cellContent
584
- }) : cellContent
585
- }, cell.id);
586
- };
587
- //#endregion
588
- //#region src/DataTable/subcomponents/DataTableBodyRows.tsx
589
- /**
590
- * Standard row renderer used in non-virtualized table mode.
591
- *
592
- * It renders:
593
- * - each data row
594
- * - an optional sibling expanded-content row that spans all visible columns
595
- */
596
- const DataTableBodyRows = ({ className: classNames, expandableRows = void 0, rows, visibleColumnCount, virtualized = false }) => {
597
- return rows.map((row) => {
598
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("tr", {
599
- className: classNames.tr,
600
- "data-slot": "tr",
601
- "data-state": row.getIsSelected() ? "selected" : void 0,
602
- style: virtualized ? {
603
- display: "flex",
604
- width: "100%"
605
- } : void 0,
606
- children: row.getVisibleCells().map((cell) => {
607
- return /* @__PURE__ */ jsx(DataTableBodyCell, {
608
- cell,
609
- className: classNames,
610
- virtualized
611
- }, cell.id);
612
- })
613
- }), expandableRows?.renderContent && row.getIsExpanded() ? /* @__PURE__ */ jsx("tr", {
614
- className: cn(classNames.tr, classNames.expandedRow),
615
- "data-slot": "expanded-row",
616
- children: /* @__PURE__ */ jsx("td", {
617
- className: classNames.expandedCell,
618
- colSpan: visibleColumnCount,
619
- "data-slot": "expanded-cell",
620
- children: expandableRows.renderContent(row)
580
+ /** Dropdown for toggling table column visibility. */
581
+ const DataTableViewOptions = ({ classNames, table, triggerIcon = /* @__PURE__ */ jsx(LuColumns3, {}), visibleIcon = "✓", testId = void 0 }) => {
582
+ const hideableColumns = table.getAllColumns().filter((column) => {
583
+ return column.getCanHide();
584
+ });
585
+ const columnsById = new Map(hideableColumns.map((column) => {
586
+ return [column.id, column];
587
+ }));
588
+ const items = hideableColumns.map((column) => {
589
+ const columnLabel = getColumnLabel(column);
590
+ return {
591
+ key: column.id,
592
+ className: classNames.viewOptionsItem,
593
+ dataSlot: "view-options-item",
594
+ textValue: columnLabel,
595
+ label: /* @__PURE__ */ jsxs("span", {
596
+ className: "flex items-center gap-2",
597
+ children: [/* @__PURE__ */ jsx("span", {
598
+ className: classNames.viewOptionsIndicator,
599
+ "data-slot": "view-options-indicator",
600
+ children: column.getIsVisible() && visibleIcon !== false ? visibleIcon : ""
601
+ }), columnLabel]
621
602
  })
622
- }) : null] }, row.id);
603
+ };
623
604
  });
624
- };
625
- //#endregion
626
- //#region src/DataTable/subcomponents/DataTableHeaderCell.tsx
627
- /**
628
- * Renders one header cell and encapsulates sortable/non-sortable behavior.
629
- */
630
- const DataTableHeaderCell = ({ className: classNames, header, sortIcons = void 0, virtualized = false }) => {
631
- const canSort = header.column.getCanSort();
632
- const columnKind = getColumnKind(header.column.id);
633
- const isExpansionColumn = columnKind === "expansion";
634
- const isSelectionColumn = columnKind === "selection";
635
- const sortState = header.column.getIsSorted();
636
- const sortIndicator = getSortIndicator(canSort, sortState, sortIcons);
637
- if (header.isPlaceholder) return /* @__PURE__ */ jsx("th", {
638
- "aria-label": "Empty column header",
639
- className: classNames.th,
640
- "data-slot": getHeaderDataSlot(columnKind)
641
- }, header.id);
642
- const handleSort = () => {
643
- header.column.toggleSorting(sortState === "asc");
644
- };
645
- return /* @__PURE__ */ jsx("th", {
646
- className: cn(classNames.th, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
647
- "data-slot": getHeaderDataSlot(columnKind),
648
- style: virtualized ? {
649
- alignItems: "center",
650
- display: "flex",
651
- ...getVirtualCellStyle(columnKind, header.getSize())
652
- } : void 0,
653
- children: canSort ? /* @__PURE__ */ jsxs(Button, {
654
- className: classNames.sortButton,
655
- "data-sortable": canSort,
656
- dataSlot: "sort-button",
657
- onClick: handleSort,
605
+ return /* @__PURE__ */ jsxs(Menu, {
606
+ items,
607
+ onAction: (key) => {
608
+ const column = columnsById.get(String(key));
609
+ if (!column) return;
610
+ column.toggleVisibility(!column.getIsVisible());
611
+ },
612
+ testId: testId ? `${testId}-column-visibility-trigger` : void 0,
613
+ triggerButtonProps: {
614
+ "aria-label": "Toggle column visibility",
615
+ className: classNames.viewOptionsTrigger,
616
+ dataSlot: "view-options-trigger",
617
+ disableRipple: true,
658
618
  size: "sm",
659
- variant: "light",
660
- children: [flexRender(header.column.columnDef.header, header.getContext()), sortIndicator ? /* @__PURE__ */ jsx("span", {
661
- "aria-hidden": "true",
662
- className: classNames.sortIcon,
663
- "data-slot": "sort-icon",
664
- children: sortIndicator
665
- }) : null]
666
- }) : /* @__PURE__ */ jsx("div", {
667
- className: cn(classNames.nonSortableHeaderContent, isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
668
- "data-slot": columnKind === "data" ? "non-sortable-header-content" : getControlCellContentDataSlot(columnKind),
669
- children: flexRender(header.column.columnDef.header, header.getContext())
670
- })
671
- }, header.id);
672
- };
673
- //#endregion
674
- //#region src/DataTable/subcomponents/DataTableHeaderRows.tsx
675
- /** Column header groups and sorting controls for either table layout */
676
- const DataTableHeaderRows = ({ className: classNames, sortIcons = void 0, table, virtualized = false }) => {
677
- return table.getHeaderGroups().map((headerGroup) => {
678
- return /* @__PURE__ */ jsx("tr", {
679
- className: classNames.tr,
680
- "data-slot": "tr",
681
- style: virtualized ? {
682
- display: "flex",
683
- width: "100%"
684
- } : void 0,
685
- children: headerGroup.headers.map((header) => {
686
- return /* @__PURE__ */ jsx(DataTableHeaderCell, {
687
- className: classNames,
688
- header,
689
- sortIcons,
690
- virtualized
691
- }, header.id);
692
- })
693
- }, headerGroup.id);
619
+ variant: "bordered"
620
+ },
621
+ children: [triggerIcon === false ? null : triggerIcon, "Columns"]
694
622
  });
695
623
  };
696
- //#endregion
697
- //#region src/DataTable/subcomponents/DataTableStateRows.tsx
698
- /** Full-width loading and empty rows without replacing the table structure */
699
- const DataTableStateRows = ({ className: classNames, emptyContent, loading, loadingContent, rowCount, visibleColumnCount }) => {
700
- return /* @__PURE__ */ jsxs(Fragment$1, { children: [loading ? /* @__PURE__ */ jsx("tr", {
701
- className: classNames.tr,
702
- "data-slot": "tr",
703
- children: /* @__PURE__ */ jsx("td", {
704
- className: classNames.loadingCell,
705
- colSpan: visibleColumnCount,
706
- "data-slot": "loading-cell",
707
- children: loadingContent
708
- })
709
- }) : null, !loading && rowCount === 0 ? /* @__PURE__ */ jsx("tr", {
710
- className: classNames.tr,
711
- "data-slot": "tr",
712
- children: /* @__PURE__ */ jsx("td", {
713
- className: classNames.emptyCell,
714
- colSpan: visibleColumnCount,
715
- "data-slot": "empty-cell",
716
- children: emptyContent
717
- })
718
- }) : null] });
719
- };
720
- //#endregion
721
- //#region src/DataTable/hooks/useDataTableVirtualizer.ts
624
+ // src/DataTable/hooks/useDataTableVirtualizer.ts
722
625
  /**
723
626
  * Flattens current table state into virtual render items.
724
627
  *
@@ -838,15 +741,14 @@ const useDataTableVirtualizer = ({ expandableRows, infiniteScroll, rows, scrollE
838
741
  ...virtualizer
839
742
  };
840
743
  };
841
- //#endregion
842
- //#region src/DataTable/subcomponents/DataTableVirtualBodyRows.tsx
744
+ // src/DataTable/Subcomponents/DataTableVirtualBodyRows.tsx
843
745
  /**
844
746
  * Virtualized row renderer for DataTable body.
845
747
  *
846
748
  * It maps virtual items (row/expanded/placeholder/load-more) to absolute
847
749
  * positioned `<tr>` elements and delegates load-more retry handling.
848
750
  */
849
- const DataTableVirtualBodyRows = ({ className: classNames, expandableRows = void 0, infiniteScroll = void 0, loadingMoreContent = "Loading more...", retryContent = "Load next page", rows, scrollElementRef = void 0, virtualized, virtualization = void 0, visibleColumnCount }) => {
751
+ const DataTableVirtualBodyRows = ({ classNames, expandableRows = void 0, infiniteScroll = void 0, loadingMoreContent = "Loading more...", retryContent = "Load next page", rows, scrollElementRef = void 0, virtualized, virtualization = void 0, visibleColumnCount }) => {
850
752
  const { getItem, measureElement, retry, totalSize, virtualItems } = useDataTableVirtualizer({
851
753
  expandableRows,
852
754
  infiniteScroll,
@@ -879,7 +781,7 @@ const DataTableVirtualBodyRows = ({ className: classNames, expandableRows = void
879
781
  children: item.row.getVisibleCells().map((cell) => {
880
782
  return /* @__PURE__ */ jsx(DataTableBodyCell, {
881
783
  cell,
882
- className: classNames,
784
+ classNames,
883
785
  virtualized
884
786
  }, cell.id);
885
787
  })
@@ -940,222 +842,64 @@ const DataTableVirtualBodyRows = ({ className: classNames, expandableRows = void
940
842
  }, item.key);
941
843
  })] });
942
844
  };
943
- //#endregion
944
- //#region src/DataTable/subcomponents/DataTableSurface.tsx
945
- /** Semantic table surface with standard or virtualized row composition */
946
- const DataTableSurface = ({ ariaLabel = void 0, className: classNames, emptyContent = void 0, expandableRows: resolvedExpandableRows = void 0, icons = void 0, infiniteScroll: resolvedInfiniteScroll = void 0, loading = false, loadingContent = void 0, scrollContainerRef, table, virtualization: virtualConfig = void 0, virtualized }) => {
947
- const tableRows = table.getRowModel().rows;
948
- const visibleColumnCount = table.getVisibleLeafColumns().length;
949
- if (virtualized) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("table", {
950
- "aria-hidden": loading && tableRows.length === 0 ? "true" : void 0,
951
- className: classNames.table,
952
- "data-slot": "table",
953
- style: { display: "grid" },
954
- children: /* @__PURE__ */ jsx("thead", {
955
- className: classNames.thead,
956
- "data-slot": "thead",
957
- children: /* @__PURE__ */ jsx(DataTableHeaderRows, {
958
- className: classNames,
959
- sortIcons: icons?.sort,
960
- table,
961
- virtualized: true
962
- })
963
- })
964
- }), /* @__PURE__ */ jsx(ScrollShadow, {
965
- ref: scrollContainerRef,
966
- className: classNames.scrollShadow ? `${classNames.scrollContainer} ${classNames.scrollShadow}` : classNames.scrollContainer,
967
- dataSlot: "scroll-container",
968
- size: virtualConfig?.scrollShadowSize ?? 40,
969
- style: { maxHeight: virtualConfig?.maxHeight },
970
- visibility: resolvedInfiniteScroll?.loadMoreError ? "none" : "auto",
971
- children: /* @__PURE__ */ jsx("table", {
972
- "aria-label": ariaLabel,
973
- className: classNames.table,
974
- "data-slot": "table",
975
- style: { display: "grid" },
976
- children: /* @__PURE__ */ jsxs("tbody", {
977
- className: classNames.tbody,
978
- "data-slot": "tbody",
979
- style: {
980
- display: "grid",
981
- position: "relative"
982
- },
983
- children: [loading ? null : /* @__PURE__ */ jsx(DataTableVirtualBodyRows, {
984
- className: classNames,
985
- expandableRows: resolvedExpandableRows,
986
- infiniteScroll: resolvedInfiniteScroll,
987
- loadingMoreContent: resolvedInfiniteScroll?.loadingMoreContent,
988
- retryContent: resolvedInfiniteScroll?.retryContent,
989
- rows: tableRows,
990
- scrollElementRef: scrollContainerRef,
991
- virtualization: virtualConfig,
992
- virtualized: true,
993
- visibleColumnCount
994
- }), /* @__PURE__ */ jsx(DataTableStateRows, {
995
- className: classNames,
996
- emptyContent,
997
- loading,
998
- loadingContent,
999
- rowCount: tableRows.length,
1000
- visibleColumnCount
1001
- })]
1002
- })
1003
- })
1004
- })] });
1005
- return /* @__PURE__ */ jsxs("table", {
1006
- "aria-label": ariaLabel,
1007
- className: classNames.table,
1008
- "data-slot": "table",
1009
- children: [/* @__PURE__ */ jsx("thead", {
1010
- className: classNames.thead,
1011
- "data-slot": "thead",
1012
- children: /* @__PURE__ */ jsx(DataTableHeaderRows, {
1013
- className: classNames,
1014
- sortIcons: icons?.sort,
1015
- table
1016
- })
1017
- }), /* @__PURE__ */ jsxs("tbody", {
1018
- className: classNames.tbody,
1019
- "data-slot": "tbody",
1020
- children: [loading ? null : /* @__PURE__ */ jsx(DataTableBodyRows, {
1021
- className: classNames,
1022
- expandableRows: resolvedExpandableRows,
1023
- rows: tableRows,
1024
- visibleColumnCount
1025
- }), /* @__PURE__ */ jsx(DataTableStateRows, {
1026
- className: classNames,
1027
- emptyContent,
1028
- loading,
1029
- loadingContent,
1030
- rowCount: tableRows.length,
1031
- visibleColumnCount
1032
- })]
1033
- })]
1034
- });
1035
- };
1036
- //#endregion
1037
- //#region src/DataTable/subcomponents/DataTableSearchInput.tsx
1038
- /** Column search input that commits filters and resets server-side scrolling */
1039
- const DataTableSearchInput = ({ className, infiniteScroll: resolvedInfiniteScroll = void 0, scrollContainerRef, searchFieldCount, searchField, table, testId = void 0 }) => {
1040
- const searchValue = table.getColumn(searchField.column)?.getFilterValue() ?? "";
1041
- let searchTestId;
1042
- if (testId) searchTestId = searchFieldCount === 1 ? `${testId}-search` : `${testId}-search-${searchField.column}`;
1043
- const handleChange = (event) => {
1044
- const { value } = event.target;
1045
- table.getColumn(searchField.column)?.setFilterValue(value);
1046
- if (resolvedInfiniteScroll) {
1047
- resolvedInfiniteScroll.onSearchChange?.(searchField.column, value);
1048
- scrollContainerRef.current?.scrollTo({ top: 0 });
1049
- }
1050
- };
1051
- return /* @__PURE__ */ jsx("input", {
1052
- className,
1053
- "data-focused": Boolean(searchValue),
1054
- "data-slot": "search-input",
1055
- "data-testid": searchTestId,
1056
- onChange: handleChange,
1057
- placeholder: searchField.placeholder ?? "Search...",
1058
- value: searchValue
1059
- });
1060
- };
1061
- //#endregion
1062
- //#region src/DataTable/subcomponents/DataTableViewOptions.tsx
845
+ // src/DataTable/DataTable.tsx
846
+ const dataTableVariants = tv({ slots: {
847
+ base: "w-full",
848
+ checkbox: "relative inline-flex h-4 w-4 shrink-0 cursor-pointer items-center justify-center rounded border border-divider bg-background align-middle text-foreground",
849
+ checkboxIndicator: "pointer-events-none absolute inset-0 flex items-center justify-center text-[10px] leading-none",
850
+ emptyCell: "h-24 text-center text-default-500",
851
+ expandButton: "h-8 min-w-8 px-0 disabled:cursor-not-allowed data-[disabled=true]:pointer-events-auto data-[disabled=true]:cursor-not-allowed",
852
+ expandIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-500",
853
+ expansionCell: "w-10 px-0 text-center",
854
+ expansionCellContent: "flex justify-center",
855
+ expandedRow: "bg-content1",
856
+ expandedCell: "p-4 text-sm text-default-600",
857
+ searchInput: "h-10 w-full max-w-sm rounded-small border-2 border-default-200 bg-transparent px-3 text-sm text-foreground outline-none transition-colors placeholder:text-default-500 hover:border-default-400 data-[focused=true]:border-focus dark:border-default-100",
858
+ loadingCell: "h-24 text-center text-default-500",
859
+ loadingMoreCell: "flex h-14 items-center justify-center text-default-500",
860
+ nonSortableHeaderContent: "inline-flex items-center",
861
+ pageSizeLabel: "flex items-center gap-2 text-sm text-default-500",
862
+ pageSizeSelect: "min-w-16 justify-between gap-2",
863
+ pageSummary: "text-sm text-default-500",
864
+ pagination: "flex items-center gap-2 py-4",
865
+ paginationButton: "",
866
+ placeholderCell: "h-10 animate-pulse bg-default-100/60 p-3 dark:bg-default-100/10",
867
+ selectionSummary: "mr-auto text-sm text-default-500",
868
+ selectionCell: "w-10 px-0 text-center",
869
+ selectionCellContent: "flex justify-center",
870
+ sortButton: "-ml-2 min-w-0 justify-start gap-1.5 px-2 text-left font-medium text-foreground data-[sortable=true]:cursor-pointer",
871
+ sortIcon: "inline-flex h-3.5 w-3.5 shrink-0 items-center justify-center text-default-400",
872
+ scrollContainer: "overflow-y-auto overflow-x-hidden",
873
+ scrollShadow: "",
874
+ table: "w-full caption-bottom text-sm",
875
+ tableWrapper: "overflow-hidden rounded-md border border-divider",
876
+ tbody: "",
877
+ td: "p-3 align-middle text-foreground",
878
+ th: "h-10 px-3 text-left align-middle font-medium text-foreground",
879
+ thead: "bg-content2",
880
+ toolbar: "flex items-center gap-3 py-4",
881
+ toolbarContent: "flex flex-1 items-center",
882
+ tr: "border-b border-divider last:border-b-0 data-[state=selected]:bg-content2/60",
883
+ viewOptionsIndicator: "mr-2 inline-flex w-3 justify-center",
884
+ viewOptionsItem: "data-highlighted:bg-default-100 dark:data-highlighted:bg-default-100/20 flex cursor-pointer items-center rounded px-2 py-1 text-sm text-foreground outline-none",
885
+ viewOptionsMenu: "z-50 min-w-40 rounded-md border border-divider bg-background p-1 shadow-md",
886
+ viewOptionsPositioner: "outline-none",
887
+ viewOptionsTrigger: "ml-auto gap-2"
888
+ } });
1063
889
  /**
1064
- * Resolves a human-readable label for a column, preferring its string header
1065
- * over the raw TanStack column id (e.g. "Status" instead of "status").
890
+ * Generic, feature-composable data table built on TanStack Table.
891
+ *
892
+ * Responsibilities:
893
+ * - Renders semantic table markup (`table`, `thead`, `tbody`, `tr`, `th`, `td`).
894
+ * - Wires sorting/search/visibility/selection/pagination state via
895
+ * `useDataTableController`.
896
+ * - Exposes slot-based styling through `dataTableVariants` + `className`.
897
+ * - Supports optional custom toolbar content (e.g. megapixels `Filter`).
898
+ *
899
+ * Feature configuration:
900
+ * - Configure search/visibility/selection/pagination through `features`.
1066
901
  */
1067
- const getColumnLabel = (column) => {
1068
- const { header } = column.columnDef;
1069
- return typeof header === "string" ? header : column.id;
1070
- };
1071
- /** Dropdown for toggling table column visibility */
1072
- const DataTableViewOptions = ({ className: classNames, table, triggerIcon = /* @__PURE__ */ jsx(LuColumns3, {}), visibleIcon = "✓", testId = void 0 }) => {
1073
- const hideableColumns = table.getAllColumns().filter((column) => {
1074
- return column.getCanHide();
1075
- });
1076
- const columnsById = new Map(hideableColumns.map((column) => {
1077
- return [column.id, column];
1078
- }));
1079
- const items = hideableColumns.map((column) => {
1080
- const columnLabel = getColumnLabel(column);
1081
- return {
1082
- key: column.id,
1083
- className: classNames.viewOptionsItem,
1084
- dataSlot: "view-options-item",
1085
- textValue: columnLabel,
1086
- label: /* @__PURE__ */ jsxs("span", {
1087
- className: "flex items-center gap-2",
1088
- children: [/* @__PURE__ */ jsx("span", {
1089
- className: classNames.viewOptionsIndicator,
1090
- "data-slot": "view-options-indicator",
1091
- children: column.getIsVisible() && visibleIcon !== false ? visibleIcon : ""
1092
- }), columnLabel]
1093
- })
1094
- };
1095
- });
1096
- return /* @__PURE__ */ jsxs(Menu, {
1097
- items,
1098
- onAction: (key) => {
1099
- const column = columnsById.get(String(key));
1100
- if (!column) return;
1101
- column.toggleVisibility(!column.getIsVisible());
1102
- },
1103
- testId: testId ? `${testId}-column-visibility-trigger` : void 0,
1104
- triggerButtonProps: {
1105
- "aria-label": "Toggle column visibility",
1106
- className: classNames.viewOptionsTrigger,
1107
- dataSlot: "view-options-trigger",
1108
- disableRipple: true,
1109
- size: "sm",
1110
- variant: "bordered"
1111
- },
1112
- children: [triggerIcon === false ? null : triggerIcon, "Columns"]
1113
- });
1114
- };
1115
- //#endregion
1116
- //#region src/DataTable/subcomponents/DataTableToolbar.tsx
1117
- /** Search, custom actions and column visibility controls above the table */
1118
- const DataTableToolbar = ({ className: classNames, columnVisibility: resolvedEnableColumnVisibility, icons = void 0, infiniteScroll: resolvedInfiniteScroll = void 0, scrollContainerRef, searchFields: resolvedSearchFields, table, testId = void 0, toolbarContent = void 0 }) => {
1119
- const showToolbar = resolvedSearchFields.length > 0 || resolvedEnableColumnVisibility || Boolean(toolbarContent);
1120
- return /* @__PURE__ */ jsx(Fragment$1, { children: showToolbar ? /* @__PURE__ */ jsxs("div", {
1121
- className: classNames.toolbar,
1122
- "data-slot": "toolbar",
1123
- children: [
1124
- toolbarContent ? /* @__PURE__ */ jsx("div", {
1125
- className: classNames.toolbarContent,
1126
- "data-slot": "toolbar-content",
1127
- children: toolbarContent
1128
- }) : null,
1129
- resolvedSearchFields.map((searchField) => {
1130
- return /* @__PURE__ */ jsx(DataTableSearchInput, {
1131
- className: classNames.searchInput,
1132
- infiniteScroll: resolvedInfiniteScroll,
1133
- scrollContainerRef,
1134
- searchField,
1135
- searchFieldCount: resolvedSearchFields.length,
1136
- table,
1137
- testId
1138
- }, searchField.column);
1139
- }),
1140
- resolvedEnableColumnVisibility ? /* @__PURE__ */ jsx(DataTableViewOptions, {
1141
- className: {
1142
- viewOptionsIndicator: classNames.viewOptionsIndicator,
1143
- viewOptionsItem: classNames.viewOptionsItem,
1144
- viewOptionsTrigger: classNames.viewOptionsTrigger
1145
- },
1146
- table,
1147
- testId,
1148
- triggerIcon: icons?.columnVisibility?.trigger,
1149
- visibleIcon: icons?.columnVisibility?.visible
1150
- }) : null
1151
- ]
1152
- }) : null });
1153
- };
1154
- //#endregion
1155
- //#region src/DataTable/subcomponents/DataTableControl.tsx
1156
- /** Table feature state and composition of toolbar, rows and pagination */
1157
- const DataTableControl = ({ ariaLabel = "Data table", className: classNames, columns, data, emptyContent = "No results.", features = void 0, icons = void 0, loading = false, loadingContent = "Loading...", testId = void 0, toolbarContent = void 0 }) => {
1158
- const scrollContainerRef = useRef(null);
902
+ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data, emptyContent = "No results.", features = void 0, icons = void 0, loading = false, loadingContent = "Loading...", testId = void 0, toolbarContent = void 0 }) => {
1159
903
  const resolvedEnableColumnVisibility = features?.columnVisibility ?? false;
1160
904
  const resolvedExpandableRows = features?.expandableRows;
1161
905
  const resolvedEnableExpandableRows = Boolean(resolvedExpandableRows);
@@ -1176,10 +920,13 @@ const DataTableControl = ({ ariaLabel = "Data table", className: classNames, col
1176
920
  dynamicRowHeight: true,
1177
921
  maxHeight: 600
1178
922
  } : void 0);
923
+ const variants = dataTableVariants();
924
+ const scrollContainerRef = useRef(null);
1179
925
  const handleSortingChange = useCallback((sorting) => {
1180
926
  if (resolvedInfiniteScroll) scrollContainerRef.current?.scrollTo({ top: 0 });
1181
927
  resolvedInfiniteScroll?.onSortingChange?.(sorting);
1182
928
  }, [resolvedInfiniteScroll]);
929
+ const classNames = variantsToClassNames(variants, className, "base");
1183
930
  const checkboxClassNames = useMemo(() => {
1184
931
  return {
1185
932
  checkbox: classNames.checkbox,
@@ -1198,8 +945,8 @@ const DataTableControl = ({ ariaLabel = "Data table", className: classNames, col
1198
945
  data,
1199
946
  enableExpandableRows: resolvedEnableExpandableRows,
1200
947
  enablePagination: resolvedEnablePagination,
1201
- enableRowSelection: resolvedEnableRowSelection,
1202
948
  enableServerMode: Boolean(resolvedInfiniteScroll),
949
+ enableRowSelection: resolvedEnableRowSelection,
1203
950
  expansionClassNames,
1204
951
  expansionIcons: icons?.expandableRows,
1205
952
  getSubRows: resolvedExpandableRows?.getSubRows,
@@ -1208,43 +955,172 @@ const DataTableControl = ({ ariaLabel = "Data table", className: classNames, col
1208
955
  pageSizeOptions: resolvedPageSizeOptions,
1209
956
  selectionIcons: icons?.selection
1210
957
  });
958
+ const visibleColumnCount = table.getVisibleLeafColumns().length;
959
+ const tableRows = table.getRowModel().rows;
960
+ const showToolbar = resolvedSearchFields.length > 0 || resolvedEnableColumnVisibility || Boolean(toolbarContent);
961
+ const renderHeaderRows = (virtualized) => {
962
+ return table.getHeaderGroups().map((headerGroup) => {
963
+ return /* @__PURE__ */ jsx("tr", {
964
+ className: classNames.tr,
965
+ "data-slot": "tr",
966
+ style: virtualized ? {
967
+ display: "flex",
968
+ width: "100%"
969
+ } : void 0,
970
+ children: headerGroup.headers.map((header) => {
971
+ return /* @__PURE__ */ jsx(DataTableHeaderCell, {
972
+ classNames,
973
+ header,
974
+ sortIcons: icons?.sort,
975
+ virtualized
976
+ }, header.id);
977
+ })
978
+ }, headerGroup.id);
979
+ });
980
+ };
981
+ const renderBodyStateRows = () => {
982
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [loading ? /* @__PURE__ */ jsx("tr", {
983
+ className: classNames.tr,
984
+ "data-slot": "tr",
985
+ children: /* @__PURE__ */ jsx("td", {
986
+ className: classNames.loadingCell,
987
+ colSpan: visibleColumnCount,
988
+ "data-slot": "loading-cell",
989
+ children: loadingContent
990
+ })
991
+ }) : null, !loading && tableRows.length === 0 ? /* @__PURE__ */ jsx("tr", {
992
+ className: classNames.tr,
993
+ "data-slot": "tr",
994
+ children: /* @__PURE__ */ jsx("td", {
995
+ className: classNames.emptyCell,
996
+ colSpan: visibleColumnCount,
997
+ "data-slot": "empty-cell",
998
+ children: emptyContent
999
+ })
1000
+ }) : null] });
1001
+ };
1002
+ const renderVirtualizedTable = () => {
1003
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("table", {
1004
+ "aria-hidden": loading && tableRows.length === 0 ? "true" : void 0,
1005
+ className: classNames.table,
1006
+ "data-slot": "table",
1007
+ style: { display: "grid" },
1008
+ children: /* @__PURE__ */ jsx("thead", {
1009
+ className: classNames.thead,
1010
+ "data-slot": "thead",
1011
+ children: renderHeaderRows(true)
1012
+ })
1013
+ }), /* @__PURE__ */ jsx(ScrollShadow, {
1014
+ ref: scrollContainerRef,
1015
+ className: classNames.scrollShadow ? `${classNames.scrollContainer} ${classNames.scrollShadow}` : classNames.scrollContainer,
1016
+ dataSlot: "scroll-container",
1017
+ size: virtualConfig?.scrollShadowSize ?? 40,
1018
+ style: { maxHeight: virtualConfig?.maxHeight },
1019
+ visibility: resolvedInfiniteScroll?.loadMoreError ? "none" : "auto",
1020
+ children: /* @__PURE__ */ jsx("table", {
1021
+ "aria-label": ariaLabel,
1022
+ className: classNames.table,
1023
+ "data-slot": "table",
1024
+ style: { display: "grid" },
1025
+ children: /* @__PURE__ */ jsxs("tbody", {
1026
+ className: classNames.tbody,
1027
+ "data-slot": "tbody",
1028
+ style: {
1029
+ display: "grid",
1030
+ position: "relative"
1031
+ },
1032
+ children: [loading ? null : /* @__PURE__ */ jsx(DataTableVirtualBodyRows, {
1033
+ classNames,
1034
+ expandableRows: resolvedExpandableRows,
1035
+ infiniteScroll: resolvedInfiniteScroll,
1036
+ loadingMoreContent: resolvedInfiniteScroll?.loadingMoreContent,
1037
+ retryContent: resolvedInfiniteScroll?.retryContent,
1038
+ rows: tableRows,
1039
+ scrollElementRef: scrollContainerRef,
1040
+ virtualization: virtualConfig,
1041
+ virtualized: true,
1042
+ visibleColumnCount
1043
+ }), renderBodyStateRows()]
1044
+ })
1045
+ })
1046
+ })] });
1047
+ };
1048
+ const renderStandardTable = () => {
1049
+ return /* @__PURE__ */ jsxs("table", {
1050
+ "aria-label": ariaLabel,
1051
+ className: classNames.table,
1052
+ "data-slot": "table",
1053
+ children: [/* @__PURE__ */ jsx("thead", {
1054
+ className: classNames.thead,
1055
+ "data-slot": "thead",
1056
+ children: renderHeaderRows(false)
1057
+ }), /* @__PURE__ */ jsxs("tbody", {
1058
+ className: classNames.tbody,
1059
+ "data-slot": "tbody",
1060
+ children: [loading ? null : /* @__PURE__ */ jsx(DataTableBodyRows, {
1061
+ classNames,
1062
+ expandableRows: resolvedExpandableRows,
1063
+ rows: tableRows,
1064
+ visibleColumnCount
1065
+ }), renderBodyStateRows()]
1066
+ })]
1067
+ });
1068
+ };
1211
1069
  return /* @__PURE__ */ jsxs("div", {
1212
1070
  className: classNames.base,
1213
- "data-component": "data-table",
1214
1071
  "data-slot": "base",
1215
1072
  "data-testid": testId,
1216
1073
  children: [
1217
- /* @__PURE__ */ jsx(DataTableToolbar, {
1218
- className: classNames,
1219
- columnVisibility: resolvedEnableColumnVisibility,
1220
- icons,
1221
- infiniteScroll: resolvedInfiniteScroll,
1222
- scrollContainerRef,
1223
- searchFields: resolvedSearchFields,
1224
- table,
1225
- testId,
1226
- toolbarContent
1227
- }),
1074
+ showToolbar ? /* @__PURE__ */ jsxs("div", {
1075
+ className: classNames.toolbar,
1076
+ "data-slot": "toolbar",
1077
+ children: [
1078
+ toolbarContent ? /* @__PURE__ */ jsx("div", {
1079
+ className: classNames.toolbarContent,
1080
+ "data-slot": "toolbar-content",
1081
+ children: toolbarContent
1082
+ }) : null,
1083
+ resolvedSearchFields.map((searchField) => {
1084
+ const searchValue = table.getColumn(searchField.column)?.getFilterValue() ?? "";
1085
+ let searchTestId;
1086
+ if (testId) searchTestId = resolvedSearchFields.length === 1 ? `${testId}-search` : `${testId}-search-${searchField.column}`;
1087
+ return /* @__PURE__ */ jsx("input", {
1088
+ className: classNames.searchInput,
1089
+ "data-focused": Boolean(searchValue),
1090
+ "data-slot": "search-input",
1091
+ "data-testid": searchTestId,
1092
+ onChange: (event) => {
1093
+ const { value } = event.target;
1094
+ table.getColumn(searchField.column)?.setFilterValue(value);
1095
+ if (resolvedInfiniteScroll) {
1096
+ resolvedInfiniteScroll.onSearchChange?.(searchField.column, value);
1097
+ scrollContainerRef.current?.scrollTo({ top: 0 });
1098
+ }
1099
+ },
1100
+ placeholder: searchField.placeholder ?? "Search...",
1101
+ value: searchValue
1102
+ }, searchField.column);
1103
+ }),
1104
+ resolvedEnableColumnVisibility ? /* @__PURE__ */ jsx(DataTableViewOptions, {
1105
+ classNames: {
1106
+ viewOptionsIndicator: classNames.viewOptionsIndicator,
1107
+ viewOptionsItem: classNames.viewOptionsItem,
1108
+ viewOptionsTrigger: classNames.viewOptionsTrigger
1109
+ },
1110
+ table,
1111
+ testId,
1112
+ triggerIcon: icons?.columnVisibility?.trigger,
1113
+ visibleIcon: icons?.columnVisibility?.visible
1114
+ }) : null
1115
+ ]
1116
+ }) : null,
1228
1117
  /* @__PURE__ */ jsx("div", {
1229
1118
  className: classNames.tableWrapper,
1230
1119
  "data-slot": "table-wrapper",
1231
- children: /* @__PURE__ */ jsx(DataTableSurface, {
1232
- ariaLabel,
1233
- className: classNames,
1234
- emptyContent,
1235
- expandableRows: resolvedExpandableRows,
1236
- icons,
1237
- infiniteScroll: resolvedInfiniteScroll,
1238
- loading,
1239
- loadingContent,
1240
- scrollContainerRef,
1241
- table,
1242
- virtualization: virtualConfig,
1243
- virtualized: resolvedEnableVirtualization
1244
- })
1120
+ children: resolvedEnableVirtualization ? renderVirtualizedTable() : renderStandardTable()
1245
1121
  }),
1246
1122
  resolvedEnablePagination ? /* @__PURE__ */ jsx(DataTablePagination, {
1247
- className: {
1123
+ classNames: {
1248
1124
  pageSizeLabel: classNames.pageSizeLabel,
1249
1125
  pageSizeSelect: classNames.pageSizeSelect,
1250
1126
  pageSummary: classNames.pageSummary,
@@ -1261,30 +1137,8 @@ const DataTableControl = ({ ariaLabel = "Data table", className: classNames, col
1261
1137
  ]
1262
1138
  });
1263
1139
  };
1264
- //#endregion
1265
- //#region src/DataTable/DataTable.tsx
1266
- /**
1267
- * Configurable data table built on TanStack Table with semantic table markup
1268
- *
1269
- * Configure search, sorting, column visibility, row selection and pagination
1270
- * through column definitions and `features`, with optional custom toolbar content
1271
- *
1272
- * Supports virtual scrolling and cursor-based loading for larger datasets
1273
- * Customize individual slots through `className`
1274
- */
1275
- const DataTable = ({ className = void 0, ...props }) => {
1276
- const styling = useStyling();
1277
- const variants = styling.resolve(dataTableVariants);
1278
- const classNames = styling.variantsToClassNames(variants, className, "base");
1279
- return /* @__PURE__ */ jsx(DataTableControl, {
1280
- ...props,
1281
- className: classNames
1282
- });
1283
- };
1284
- //#endregion
1285
- //#region src/DataTable/index.ts
1140
+ // src/DataTable/index.ts
1286
1141
  var DataTable_default = DataTable;
1287
- //#endregion
1288
1142
  export { DataTable as n, dataTableVariants as r, DataTable_default as t };
1289
1143
 
1290
- //# sourceMappingURL=DataTable-Ml6QySfA.mjs.map
1144
+ //# sourceMappingURL=DataTable-CRSjenVg.mjs.map