@fuf-stack/megapixels 1.0.1 → 2.0.0-next.1

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 (32) hide show
  1. package/README.md +3 -1
  2. package/dist/DataTable/index.d.mts +1 -1
  3. package/dist/DataTable/index.mjs +1 -1
  4. package/dist/{DataTable-CRSjenVg.mjs → DataTable-C7xhLtzy.mjs} +577 -442
  5. package/dist/DataTable-C7xhLtzy.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-BTmKbroE.mjs → Filter-CAx3DWjI.mjs} +136 -83
  9. package/dist/Filter-CAx3DWjI.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-bHSDnmsA.mjs → Notification-DrpqGoyn.mjs} +4 -4
  13. package/dist/{Notification-bHSDnmsA.mjs.map → Notification-DrpqGoyn.mjs.map} +1 -1
  14. package/dist/VirtualList/index.d.mts +1 -1
  15. package/dist/VirtualList/index.mjs +1 -1
  16. package/dist/VirtualList-Cz---_Jm.mjs +188 -0
  17. package/dist/VirtualList-Cz---_Jm.mjs.map +1 -0
  18. package/dist/{index-C20kbsap.d.mts → index-B8MLX5QP.d.mts} +80 -63
  19. package/dist/{index-C20kbsap.d.mts.map → index-B8MLX5QP.d.mts.map} +1 -1
  20. package/dist/{index-QjwjR0tT.d.mts → index-BYi0H0wJ.d.mts} +2 -2
  21. package/dist/{index-QjwjR0tT.d.mts.map → index-BYi0H0wJ.d.mts.map} +1 -1
  22. package/dist/{index-CNLdZuF-.d.mts → index-Bhg-2LmV.d.mts} +281 -202
  23. package/dist/{index-CNLdZuF-.d.mts.map → index-Bhg-2LmV.d.mts.map} +1 -1
  24. package/dist/{index-BxhYTX-_.d.mts → index-xNVpv6cI.d.mts} +29 -12
  25. package/dist/{index-BxhYTX-_.d.mts.map → index-xNVpv6cI.d.mts.map} +1 -1
  26. package/dist/index.d.mts +4 -4
  27. package/dist/index.mjs +4 -4
  28. package/package.json +9 -9
  29. package/dist/DataTable-CRSjenVg.mjs.map +0 -1
  30. package/dist/Filter-BTmKbroE.mjs.map +0 -1
  31. package/dist/VirtualList-C7T47V_m.mjs +0 -152
  32. package/dist/VirtualList-C7T47V_m.mjs.map +0 -1
@@ -1,13 +1,108 @@
1
1
  import { t as useInfiniteVirtualizer } from "./useInfiniteVirtualizer-CHBE4y7W.mjs";
2
+ import { useStyling } from "@fuf-stack/pixels/StylingProvider";
3
+ import { cn, tv } from "@fuf-stack/pixel-utils";
2
4
  import { Fragment, useCallback, useMemo, useRef, useState } from "react";
3
- import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
4
- import { ScrollShadow } from "@fuf-stack/pixels/ScrollShadow";
5
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 { Checkbox } from "@base-ui/react/checkbox";
7
+ import { CheckboxButton, CheckboxField } from "react-aria-components";
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";
10
11
  import { LuColumns3 } from "react-icons/lu";
12
+ // 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
+ } });
11
106
  // src/DataTable/features.ts
12
107
  const dataTableFeatures = tableFeatures({
13
108
  ...stockFeatures,
@@ -18,25 +113,30 @@ const dataTableFeatures = tableFeatures({
18
113
  filterFns,
19
114
  sortFns
20
115
  });
21
- // src/DataTable/Subcomponents/DataTableCheckbox.tsx
22
- /** Small checkbox wrapper used by DataTable selection UI. */
116
+ // src/DataTable/subcomponents/DataTableCheckbox.tsx
117
+ /**
118
+ * Row selection checkbox with a mixed state for partially selected pages
119
+ *
120
+ * @see https://react-aria.adobe.com/Checkbox
121
+ */
23
122
  const DataTableCheckbox = ({ ariaLabel, checked, className = void 0, checkedIcon = "✓", indeterminate = false, indeterminateIcon = "−", onCheckedChange, testId = void 0 }) => {
24
123
  const indicatorIcon = indeterminate ? indeterminateIcon : checkedIcon;
25
124
  const resolvedIndicatorIcon = indicatorIcon === false ? null : indicatorIcon;
26
- return /* @__PURE__ */ jsx(Checkbox.Root, {
125
+ return /* @__PURE__ */ jsx(CheckboxField, {
27
126
  "aria-label": ariaLabel,
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
127
+ isIndeterminate: indeterminate,
128
+ isSelected: checked,
129
+ onChange: onCheckedChange,
130
+ children: /* @__PURE__ */ jsx(CheckboxButton, {
131
+ className: className?.checkbox,
132
+ "data-slot": "checkbox",
133
+ "data-testid": testId,
134
+ children: checked || indeterminate ? /* @__PURE__ */ jsx("span", {
135
+ "aria-hidden": "true",
136
+ className: className?.checkboxIndicator,
137
+ "data-slot": "checkbox-indicator",
138
+ children: resolvedIndicatorIcon
139
+ }) : null
40
140
  })
41
141
  });
42
142
  };
@@ -300,162 +400,7 @@ const useDataTableController = ({ checkboxClassNames, columns, data, enableExpan
300
400
  tableColumns
301
401
  };
302
402
  };
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
403
+ // src/DataTable/subcomponents/DataTablePagination.tsx
459
404
  const ChevronDownIcon = () => {
460
405
  return /* @__PURE__ */ jsx("svg", {
461
406
  "aria-hidden": "true",
@@ -473,8 +418,8 @@ const ChevronDownIcon = () => {
473
418
  })
474
419
  });
475
420
  };
476
- /** Footer controls for paging, page size, and selected-row summary. */
477
- const DataTablePagination = ({ classNames, pageSizeOptions, showRowsPerPage, showSelectionSummary, table, testId = void 0 }) => {
421
+ /** Footer controls for paging, page size, and selected-row summary */
422
+ const DataTablePagination = ({ className: classNames, pageSizeOptions, showRowsPerPage, showSelectionSummary, table, testId = void 0 }) => {
478
423
  const { pageSize } = table.state.pagination;
479
424
  const selectedRowCount = table.getFilteredSelectedRowModel().rows.length;
480
425
  const pageSizeItems = pageSizeOptions.map((size) => {
@@ -568,59 +513,209 @@ const DataTablePagination = ({ classNames, pageSizeOptions, showRowsPerPage, sho
568
513
  ]
569
514
  });
570
515
  };
571
- // src/DataTable/Subcomponents/DataTableViewOptions.tsx
516
+ // src/DataTable/subcomponents/dataTableCellHelpers.ts
517
+ const getColumnKind = (columnId) => {
518
+ if (columnId === "__expand") return "expansion";
519
+ if (columnId === "__select") return "selection";
520
+ return "data";
521
+ };
522
+ const getCellDataSlot = (columnKind) => {
523
+ if (columnKind === "expansion") return "expansion-cell";
524
+ if (columnKind === "selection") return "selection-cell";
525
+ return "td";
526
+ };
527
+ const getHeaderDataSlot = (columnKind) => {
528
+ if (columnKind === "data") return "th";
529
+ return getCellDataSlot(columnKind);
530
+ };
531
+ const getControlCellContentDataSlot = (columnKind) => {
532
+ if (columnKind === "expansion") return "expansion-cell-content";
533
+ return "selection-cell-content";
534
+ };
572
535
  /**
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").
536
+ * Flex sizing for cells in virtualized mode.
537
+ *
538
+ * Because virtual rows are absolutely positioned, we cannot rely on native
539
+ * table layout for column width sync; header/body cells must apply matching
540
+ * explicit sizing rules.
575
541
  */
576
- const getColumnLabel = (column) => {
577
- const { header } = column.columnDef;
578
- return typeof header === "string" ? header : column.id;
542
+ const getVirtualCellStyle = (columnKind, size) => {
543
+ if (columnKind === "data") return {
544
+ flex: `1 1 ${size}px`,
545
+ minWidth: 0,
546
+ width: size
547
+ };
548
+ return {
549
+ flex: `0 0 ${size}px`,
550
+ width: size
551
+ };
579
552
  };
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]
602
- })
603
- };
553
+ /** Shared row positioning style for full-width virtual rows. */
554
+ const virtualFullWidthRowStyle = (start) => {
555
+ return {
556
+ display: "flex",
557
+ position: "absolute",
558
+ transform: `translateY(${start}px)`,
559
+ width: "100%"
560
+ };
561
+ };
562
+ /** Shared single-cell style for full-width virtual rows. */
563
+ const virtualFullWidthCellStyle = {
564
+ flex: "1 1 auto",
565
+ width: "100%"
566
+ };
567
+ // src/DataTable/subcomponents/DataTableBodyCell.tsx
568
+ /**
569
+ * Renders one body cell and hides control-column wrapper details from row loops.
570
+ */
571
+ const DataTableBodyCell = ({ cell, className: classNames, virtualized = false }) => {
572
+ const columnKind = getColumnKind(cell.column.id);
573
+ const isExpansionColumn = columnKind === "expansion";
574
+ const isSelectionColumn = columnKind === "selection";
575
+ const isControlColumn = columnKind !== "data";
576
+ const cellContent = flexRender(cell.column.columnDef.cell, cell.getContext());
577
+ const expansionIndent = isExpansionColumn && cell.row.depth > 0 ? { paddingLeft: `${cell.row.depth * 1.25}rem` } : void 0;
578
+ return /* @__PURE__ */ jsx("td", {
579
+ className: cn(classNames.td, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
580
+ "data-slot": getCellDataSlot(columnKind),
581
+ style: virtualized ? getVirtualCellStyle(columnKind, cell.column.getSize()) : void 0,
582
+ children: isControlColumn ? /* @__PURE__ */ jsx("div", {
583
+ className: cn(isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
584
+ "data-slot": getControlCellContentDataSlot(columnKind),
585
+ style: expansionIndent,
586
+ children: cellContent
587
+ }) : cellContent
588
+ }, cell.id);
589
+ };
590
+ // src/DataTable/subcomponents/DataTableBodyRows.tsx
591
+ /**
592
+ * Standard row renderer used in non-virtualized table mode.
593
+ *
594
+ * It renders:
595
+ * - each data row
596
+ * - an optional sibling expanded-content row that spans all visible columns
597
+ */
598
+ const DataTableBodyRows = ({ className: classNames, expandableRows = void 0, rows, visibleColumnCount, virtualized = false }) => {
599
+ return rows.map((row) => {
600
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("tr", {
601
+ className: classNames.tr,
602
+ "data-slot": "tr",
603
+ "data-state": row.getIsSelected() ? "selected" : void 0,
604
+ style: virtualized ? {
605
+ display: "flex",
606
+ width: "100%"
607
+ } : void 0,
608
+ children: row.getVisibleCells().map((cell) => {
609
+ return /* @__PURE__ */ jsx(DataTableBodyCell, {
610
+ cell,
611
+ className: classNames,
612
+ virtualized
613
+ }, cell.id);
614
+ })
615
+ }), expandableRows?.renderContent && row.getIsExpanded() ? /* @__PURE__ */ jsx("tr", {
616
+ className: cn(classNames.tr, classNames.expandedRow),
617
+ "data-slot": "expanded-row",
618
+ children: /* @__PURE__ */ jsx("td", {
619
+ className: classNames.expandedCell,
620
+ colSpan: visibleColumnCount,
621
+ "data-slot": "expanded-cell",
622
+ children: expandableRows.renderContent(row)
623
+ })
624
+ }) : null] }, row.id);
604
625
  });
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,
626
+ };
627
+ // src/DataTable/subcomponents/DataTableHeaderCell.tsx
628
+ /**
629
+ * Renders one header cell and encapsulates sortable/non-sortable behavior.
630
+ */
631
+ const DataTableHeaderCell = ({ className: classNames, header, sortIcons = void 0, virtualized = false }) => {
632
+ const canSort = header.column.getCanSort();
633
+ const columnKind = getColumnKind(header.column.id);
634
+ const isExpansionColumn = columnKind === "expansion";
635
+ const isSelectionColumn = columnKind === "selection";
636
+ const sortState = header.column.getIsSorted();
637
+ const sortIndicator = getSortIndicator(canSort, sortState, sortIcons);
638
+ if (header.isPlaceholder) return /* @__PURE__ */ jsx("th", {
639
+ "aria-label": "Empty column header",
640
+ className: classNames.th,
641
+ "data-slot": getHeaderDataSlot(columnKind)
642
+ }, header.id);
643
+ const handleSort = () => {
644
+ header.column.toggleSorting(sortState === "asc");
645
+ };
646
+ return /* @__PURE__ */ jsx("th", {
647
+ className: cn(classNames.th, isExpansionColumn && classNames.expansionCell, isSelectionColumn && classNames.selectionCell),
648
+ "data-slot": getHeaderDataSlot(columnKind),
649
+ style: virtualized ? {
650
+ alignItems: "center",
651
+ display: "flex",
652
+ ...getVirtualCellStyle(columnKind, header.getSize())
653
+ } : void 0,
654
+ children: canSort ? /* @__PURE__ */ jsxs(Button, {
655
+ className: classNames.sortButton,
656
+ "data-sortable": canSort,
657
+ dataSlot: "sort-button",
658
+ onClick: handleSort,
618
659
  size: "sm",
619
- variant: "bordered"
620
- },
621
- children: [triggerIcon === false ? null : triggerIcon, "Columns"]
660
+ variant: "light",
661
+ children: [flexRender(header.column.columnDef.header, header.getContext()), sortIndicator ? /* @__PURE__ */ jsx("span", {
662
+ "aria-hidden": "true",
663
+ className: classNames.sortIcon,
664
+ "data-slot": "sort-icon",
665
+ children: sortIndicator
666
+ }) : null]
667
+ }) : /* @__PURE__ */ jsx("div", {
668
+ className: cn(classNames.nonSortableHeaderContent, isExpansionColumn && classNames.expansionCellContent, isSelectionColumn && classNames.selectionCellContent),
669
+ "data-slot": columnKind === "data" ? "non-sortable-header-content" : getControlCellContentDataSlot(columnKind),
670
+ children: flexRender(header.column.columnDef.header, header.getContext())
671
+ })
672
+ }, header.id);
673
+ };
674
+ // 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);
622
694
  });
623
695
  };
696
+ // src/DataTable/subcomponents/DataTableStateRows.tsx
697
+ /** Full-width loading and empty rows without replacing the table structure */
698
+ const DataTableStateRows = ({ className: classNames, emptyContent, loading, loadingContent, rowCount, visibleColumnCount }) => {
699
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [loading ? /* @__PURE__ */ jsx("tr", {
700
+ className: classNames.tr,
701
+ "data-slot": "tr",
702
+ children: /* @__PURE__ */ jsx("td", {
703
+ className: classNames.loadingCell,
704
+ colSpan: visibleColumnCount,
705
+ "data-slot": "loading-cell",
706
+ children: loadingContent
707
+ })
708
+ }) : null, !loading && rowCount === 0 ? /* @__PURE__ */ jsx("tr", {
709
+ className: classNames.tr,
710
+ "data-slot": "tr",
711
+ children: /* @__PURE__ */ jsx("td", {
712
+ className: classNames.emptyCell,
713
+ colSpan: visibleColumnCount,
714
+ "data-slot": "empty-cell",
715
+ children: emptyContent
716
+ })
717
+ }) : null] });
718
+ };
624
719
  // src/DataTable/hooks/useDataTableVirtualizer.ts
625
720
  /**
626
721
  * Flattens current table state into virtual render items.
@@ -741,14 +836,14 @@ const useDataTableVirtualizer = ({ expandableRows, infiniteScroll, rows, scrollE
741
836
  ...virtualizer
742
837
  };
743
838
  };
744
- // src/DataTable/Subcomponents/DataTableVirtualBodyRows.tsx
839
+ // src/DataTable/subcomponents/DataTableVirtualBodyRows.tsx
745
840
  /**
746
841
  * Virtualized row renderer for DataTable body.
747
842
  *
748
843
  * It maps virtual items (row/expanded/placeholder/load-more) to absolute
749
844
  * positioned `<tr>` elements and delegates load-more retry handling.
750
845
  */
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 }) => {
846
+ 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 }) => {
752
847
  const { getItem, measureElement, retry, totalSize, virtualItems } = useDataTableVirtualizer({
753
848
  expandableRows,
754
849
  infiniteScroll,
@@ -781,7 +876,7 @@ const DataTableVirtualBodyRows = ({ classNames, expandableRows = void 0, infinit
781
876
  children: item.row.getVisibleCells().map((cell) => {
782
877
  return /* @__PURE__ */ jsx(DataTableBodyCell, {
783
878
  cell,
784
- classNames,
879
+ className: classNames,
785
880
  virtualized
786
881
  }, cell.id);
787
882
  })
@@ -842,64 +937,217 @@ const DataTableVirtualBodyRows = ({ classNames, expandableRows = void 0, infinit
842
937
  }, item.key);
843
938
  })] });
844
939
  };
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
- } });
940
+ // src/DataTable/subcomponents/DataTableSurface.tsx
941
+ /** Semantic table surface with standard or virtualized row composition */
942
+ 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 }) => {
943
+ const tableRows = table.getRowModel().rows;
944
+ const visibleColumnCount = table.getVisibleLeafColumns().length;
945
+ if (virtualized) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("table", {
946
+ "aria-hidden": loading && tableRows.length === 0 ? "true" : void 0,
947
+ className: classNames.table,
948
+ "data-slot": "table",
949
+ style: { display: "grid" },
950
+ children: /* @__PURE__ */ jsx("thead", {
951
+ className: classNames.thead,
952
+ "data-slot": "thead",
953
+ children: /* @__PURE__ */ jsx(DataTableHeaderRows, {
954
+ className: classNames,
955
+ sortIcons: icons?.sort,
956
+ table,
957
+ virtualized: true
958
+ })
959
+ })
960
+ }), /* @__PURE__ */ jsx(ScrollShadow, {
961
+ ref: scrollContainerRef,
962
+ className: classNames.scrollShadow ? `${classNames.scrollContainer} ${classNames.scrollShadow}` : classNames.scrollContainer,
963
+ dataSlot: "scroll-container",
964
+ size: virtualConfig?.scrollShadowSize ?? 40,
965
+ style: { maxHeight: virtualConfig?.maxHeight },
966
+ visibility: resolvedInfiniteScroll?.loadMoreError ? "none" : "auto",
967
+ children: /* @__PURE__ */ jsx("table", {
968
+ "aria-label": ariaLabel,
969
+ className: classNames.table,
970
+ "data-slot": "table",
971
+ style: { display: "grid" },
972
+ children: /* @__PURE__ */ jsxs("tbody", {
973
+ className: classNames.tbody,
974
+ "data-slot": "tbody",
975
+ style: {
976
+ display: "grid",
977
+ position: "relative"
978
+ },
979
+ children: [loading ? null : /* @__PURE__ */ jsx(DataTableVirtualBodyRows, {
980
+ className: classNames,
981
+ expandableRows: resolvedExpandableRows,
982
+ infiniteScroll: resolvedInfiniteScroll,
983
+ loadingMoreContent: resolvedInfiniteScroll?.loadingMoreContent,
984
+ retryContent: resolvedInfiniteScroll?.retryContent,
985
+ rows: tableRows,
986
+ scrollElementRef: scrollContainerRef,
987
+ virtualization: virtualConfig,
988
+ virtualized: true,
989
+ visibleColumnCount
990
+ }), /* @__PURE__ */ jsx(DataTableStateRows, {
991
+ className: classNames,
992
+ emptyContent,
993
+ loading,
994
+ loadingContent,
995
+ rowCount: tableRows.length,
996
+ visibleColumnCount
997
+ })]
998
+ })
999
+ })
1000
+ })] });
1001
+ return /* @__PURE__ */ jsxs("table", {
1002
+ "aria-label": ariaLabel,
1003
+ className: classNames.table,
1004
+ "data-slot": "table",
1005
+ children: [/* @__PURE__ */ jsx("thead", {
1006
+ className: classNames.thead,
1007
+ "data-slot": "thead",
1008
+ children: /* @__PURE__ */ jsx(DataTableHeaderRows, {
1009
+ className: classNames,
1010
+ sortIcons: icons?.sort,
1011
+ table
1012
+ })
1013
+ }), /* @__PURE__ */ jsxs("tbody", {
1014
+ className: classNames.tbody,
1015
+ "data-slot": "tbody",
1016
+ children: [loading ? null : /* @__PURE__ */ jsx(DataTableBodyRows, {
1017
+ className: classNames,
1018
+ expandableRows: resolvedExpandableRows,
1019
+ rows: tableRows,
1020
+ visibleColumnCount
1021
+ }), /* @__PURE__ */ jsx(DataTableStateRows, {
1022
+ className: classNames,
1023
+ emptyContent,
1024
+ loading,
1025
+ loadingContent,
1026
+ rowCount: tableRows.length,
1027
+ visibleColumnCount
1028
+ })]
1029
+ })]
1030
+ });
1031
+ };
1032
+ // src/DataTable/subcomponents/DataTableSearchInput.tsx
1033
+ /** Column search input that commits filters and resets server-side scrolling */
1034
+ const DataTableSearchInput = ({ className, infiniteScroll: resolvedInfiniteScroll = void 0, scrollContainerRef, searchFieldCount, searchField, table, testId = void 0 }) => {
1035
+ const searchValue = table.getColumn(searchField.column)?.getFilterValue() ?? "";
1036
+ let searchTestId;
1037
+ if (testId) searchTestId = searchFieldCount === 1 ? `${testId}-search` : `${testId}-search-${searchField.column}`;
1038
+ const handleChange = (event) => {
1039
+ const { value } = event.target;
1040
+ table.getColumn(searchField.column)?.setFilterValue(value);
1041
+ if (resolvedInfiniteScroll) {
1042
+ resolvedInfiniteScroll.onSearchChange?.(searchField.column, value);
1043
+ scrollContainerRef.current?.scrollTo({ top: 0 });
1044
+ }
1045
+ };
1046
+ return /* @__PURE__ */ jsx("input", {
1047
+ className,
1048
+ "data-focused": Boolean(searchValue),
1049
+ "data-slot": "search-input",
1050
+ "data-testid": searchTestId,
1051
+ onChange: handleChange,
1052
+ placeholder: searchField.placeholder ?? "Search...",
1053
+ value: searchValue
1054
+ });
1055
+ };
1056
+ // src/DataTable/subcomponents/DataTableViewOptions.tsx
889
1057
  /**
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`.
1058
+ * Resolves a human-readable label for a column, preferring its string header
1059
+ * over the raw TanStack column id (e.g. "Status" instead of "status").
901
1060
  */
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 }) => {
1061
+ const getColumnLabel = (column) => {
1062
+ const { header } = column.columnDef;
1063
+ return typeof header === "string" ? header : column.id;
1064
+ };
1065
+ /** Dropdown for toggling table column visibility */
1066
+ const DataTableViewOptions = ({ className: classNames, table, triggerIcon = /* @__PURE__ */ jsx(LuColumns3, {}), visibleIcon = "✓", testId = void 0 }) => {
1067
+ const hideableColumns = table.getAllColumns().filter((column) => {
1068
+ return column.getCanHide();
1069
+ });
1070
+ const columnsById = new Map(hideableColumns.map((column) => {
1071
+ return [column.id, column];
1072
+ }));
1073
+ const items = hideableColumns.map((column) => {
1074
+ const columnLabel = getColumnLabel(column);
1075
+ return {
1076
+ key: column.id,
1077
+ className: classNames.viewOptionsItem,
1078
+ dataSlot: "view-options-item",
1079
+ textValue: columnLabel,
1080
+ label: /* @__PURE__ */ jsxs("span", {
1081
+ className: "flex items-center gap-2",
1082
+ children: [/* @__PURE__ */ jsx("span", {
1083
+ className: classNames.viewOptionsIndicator,
1084
+ "data-slot": "view-options-indicator",
1085
+ children: column.getIsVisible() && visibleIcon !== false ? visibleIcon : ""
1086
+ }), columnLabel]
1087
+ })
1088
+ };
1089
+ });
1090
+ return /* @__PURE__ */ jsxs(Menu, {
1091
+ items,
1092
+ onAction: (key) => {
1093
+ const column = columnsById.get(String(key));
1094
+ if (!column) return;
1095
+ column.toggleVisibility(!column.getIsVisible());
1096
+ },
1097
+ testId: testId ? `${testId}-column-visibility-trigger` : void 0,
1098
+ triggerButtonProps: {
1099
+ "aria-label": "Toggle column visibility",
1100
+ className: classNames.viewOptionsTrigger,
1101
+ dataSlot: "view-options-trigger",
1102
+ disableRipple: true,
1103
+ size: "sm",
1104
+ variant: "bordered"
1105
+ },
1106
+ children: [triggerIcon === false ? null : triggerIcon, "Columns"]
1107
+ });
1108
+ };
1109
+ // src/DataTable/subcomponents/DataTableToolbar.tsx
1110
+ /** Search, custom actions and column visibility controls above the table */
1111
+ const DataTableToolbar = ({ className: classNames, columnVisibility: resolvedEnableColumnVisibility, icons = void 0, infiniteScroll: resolvedInfiniteScroll = void 0, scrollContainerRef, searchFields: resolvedSearchFields, table, testId = void 0, toolbarContent = void 0 }) => {
1112
+ const showToolbar = resolvedSearchFields.length > 0 || resolvedEnableColumnVisibility || Boolean(toolbarContent);
1113
+ return /* @__PURE__ */ jsx(Fragment$1, { children: showToolbar ? /* @__PURE__ */ jsxs("div", {
1114
+ className: classNames.toolbar,
1115
+ "data-slot": "toolbar",
1116
+ children: [
1117
+ toolbarContent ? /* @__PURE__ */ jsx("div", {
1118
+ className: classNames.toolbarContent,
1119
+ "data-slot": "toolbar-content",
1120
+ children: toolbarContent
1121
+ }) : null,
1122
+ resolvedSearchFields.map((searchField) => {
1123
+ return /* @__PURE__ */ jsx(DataTableSearchInput, {
1124
+ className: classNames.searchInput,
1125
+ infiniteScroll: resolvedInfiniteScroll,
1126
+ scrollContainerRef,
1127
+ searchField,
1128
+ searchFieldCount: resolvedSearchFields.length,
1129
+ table,
1130
+ testId
1131
+ }, searchField.column);
1132
+ }),
1133
+ resolvedEnableColumnVisibility ? /* @__PURE__ */ jsx(DataTableViewOptions, {
1134
+ className: {
1135
+ viewOptionsIndicator: classNames.viewOptionsIndicator,
1136
+ viewOptionsItem: classNames.viewOptionsItem,
1137
+ viewOptionsTrigger: classNames.viewOptionsTrigger
1138
+ },
1139
+ table,
1140
+ testId,
1141
+ triggerIcon: icons?.columnVisibility?.trigger,
1142
+ visibleIcon: icons?.columnVisibility?.visible
1143
+ }) : null
1144
+ ]
1145
+ }) : null });
1146
+ };
1147
+ // src/DataTable/subcomponents/DataTableControl.tsx
1148
+ /** Table feature state and composition of toolbar, rows and pagination */
1149
+ 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 }) => {
1150
+ const scrollContainerRef = useRef(null);
903
1151
  const resolvedEnableColumnVisibility = features?.columnVisibility ?? false;
904
1152
  const resolvedExpandableRows = features?.expandableRows;
905
1153
  const resolvedEnableExpandableRows = Boolean(resolvedExpandableRows);
@@ -920,13 +1168,10 @@ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data
920
1168
  dynamicRowHeight: true,
921
1169
  maxHeight: 600
922
1170
  } : void 0);
923
- const variants = dataTableVariants();
924
- const scrollContainerRef = useRef(null);
925
1171
  const handleSortingChange = useCallback((sorting) => {
926
1172
  if (resolvedInfiniteScroll) scrollContainerRef.current?.scrollTo({ top: 0 });
927
1173
  resolvedInfiniteScroll?.onSortingChange?.(sorting);
928
1174
  }, [resolvedInfiniteScroll]);
929
- const classNames = variantsToClassNames(variants, className, "base");
930
1175
  const checkboxClassNames = useMemo(() => {
931
1176
  return {
932
1177
  checkbox: classNames.checkbox,
@@ -945,8 +1190,8 @@ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data
945
1190
  data,
946
1191
  enableExpandableRows: resolvedEnableExpandableRows,
947
1192
  enablePagination: resolvedEnablePagination,
948
- enableServerMode: Boolean(resolvedInfiniteScroll),
949
1193
  enableRowSelection: resolvedEnableRowSelection,
1194
+ enableServerMode: Boolean(resolvedInfiniteScroll),
950
1195
  expansionClassNames,
951
1196
  expansionIcons: icons?.expandableRows,
952
1197
  getSubRows: resolvedExpandableRows?.getSubRows,
@@ -955,172 +1200,43 @@ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data
955
1200
  pageSizeOptions: resolvedPageSizeOptions,
956
1201
  selectionIcons: icons?.selection
957
1202
  });
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
- };
1069
1203
  return /* @__PURE__ */ jsxs("div", {
1070
1204
  className: classNames.base,
1205
+ "data-component": "data-table",
1071
1206
  "data-slot": "base",
1072
1207
  "data-testid": testId,
1073
1208
  children: [
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,
1209
+ /* @__PURE__ */ jsx(DataTableToolbar, {
1210
+ className: classNames,
1211
+ columnVisibility: resolvedEnableColumnVisibility,
1212
+ icons,
1213
+ infiniteScroll: resolvedInfiniteScroll,
1214
+ scrollContainerRef,
1215
+ searchFields: resolvedSearchFields,
1216
+ table,
1217
+ testId,
1218
+ toolbarContent
1219
+ }),
1117
1220
  /* @__PURE__ */ jsx("div", {
1118
1221
  className: classNames.tableWrapper,
1119
1222
  "data-slot": "table-wrapper",
1120
- children: resolvedEnableVirtualization ? renderVirtualizedTable() : renderStandardTable()
1223
+ children: /* @__PURE__ */ jsx(DataTableSurface, {
1224
+ ariaLabel,
1225
+ className: classNames,
1226
+ emptyContent,
1227
+ expandableRows: resolvedExpandableRows,
1228
+ icons,
1229
+ infiniteScroll: resolvedInfiniteScroll,
1230
+ loading,
1231
+ loadingContent,
1232
+ scrollContainerRef,
1233
+ table,
1234
+ virtualization: virtualConfig,
1235
+ virtualized: resolvedEnableVirtualization
1236
+ })
1121
1237
  }),
1122
1238
  resolvedEnablePagination ? /* @__PURE__ */ jsx(DataTablePagination, {
1123
- classNames: {
1239
+ className: {
1124
1240
  pageSizeLabel: classNames.pageSizeLabel,
1125
1241
  pageSizeSelect: classNames.pageSizeSelect,
1126
1242
  pageSummary: classNames.pageSummary,
@@ -1137,8 +1253,27 @@ const DataTable = ({ ariaLabel = "Data table", className = void 0, columns, data
1137
1253
  ]
1138
1254
  });
1139
1255
  };
1256
+ // src/DataTable/DataTable.tsx
1257
+ /**
1258
+ * Configurable data table built on TanStack Table with semantic table markup
1259
+ *
1260
+ * Configure search, sorting, column visibility, row selection and pagination
1261
+ * through column definitions and `features`, with optional custom toolbar content
1262
+ *
1263
+ * Supports virtual scrolling and cursor-based loading for larger datasets
1264
+ * Customize individual slots through `className`
1265
+ */
1266
+ const DataTable = ({ className = void 0, ...props }) => {
1267
+ const styling = useStyling();
1268
+ const variants = styling.resolve(dataTableVariants);
1269
+ const classNames = styling.variantsToClassNames(variants, className, "base");
1270
+ return /* @__PURE__ */ jsx(DataTableControl, {
1271
+ ...props,
1272
+ className: classNames
1273
+ });
1274
+ };
1140
1275
  // src/DataTable/index.ts
1141
1276
  var DataTable_default = DataTable;
1142
1277
  export { DataTable as n, dataTableVariants as r, DataTable_default as t };
1143
1278
 
1144
- //# sourceMappingURL=DataTable-CRSjenVg.mjs.map
1279
+ //# sourceMappingURL=DataTable-C7xhLtzy.mjs.map