@bwp-web/components 0.13.1 → 0.13.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -467,7 +467,6 @@ function BiampLayout({
467
467
  import {
468
468
  Box as Box4,
469
469
  Checkbox,
470
- IconButton,
471
470
  Table as MuiTable,
472
471
  TableBody,
473
472
  TableCell,
@@ -482,7 +481,7 @@ import {
482
481
  DropdownChevronUpIcon
483
482
  } from "@bwp-web/assets";
484
483
  import { flexRender } from "@tanstack/react-table";
485
- import { useRef as useRef3 } from "react";
484
+ import React2, { useRef as useRef3 } from "react";
486
485
 
487
486
  // src/BiampTable/BiampTableEmptyState.tsx
488
487
  import { NoResultsIcon } from "@bwp-web/assets";
@@ -648,6 +647,144 @@ function cellSx(sticky, minWidth, zIndex) {
648
647
  const mw = minWidth ?? 40;
649
648
  return { minWidth: mw, maxWidth: mw };
650
649
  }
650
+ var rowCursorPointerSx = { cursor: "pointer" };
651
+ var selectionCellSx = {
652
+ position: "sticky",
653
+ left: 0,
654
+ zIndex: 2,
655
+ bgcolor: "background.paper",
656
+ ...stickyHoverBg
657
+ };
658
+ var checkboxHiddenSx = { visibility: "hidden" };
659
+ var expandCellBaseSx = {
660
+ display: "flex",
661
+ alignItems: "center",
662
+ gap: 1
663
+ };
664
+ var chevronExpandedSx = {
665
+ color: ({ palette }) => palette.text.secondary,
666
+ transition: "transform 150ms ease",
667
+ transform: "rotate(90deg)",
668
+ width: 16,
669
+ height: 16,
670
+ cursor: "pointer"
671
+ };
672
+ var chevronCollapsedSx = {
673
+ color: ({ palette }) => palette.text.secondary,
674
+ transition: "transform 150ms ease",
675
+ transform: "rotate(0deg)",
676
+ width: 16,
677
+ height: 16,
678
+ cursor: "pointer"
679
+ };
680
+ var expandPlaceholderSx = { width: 16 };
681
+ var headerSelectionCellSx = {
682
+ position: "sticky",
683
+ left: 0,
684
+ zIndex: 3,
685
+ bgcolor: "background.paper"
686
+ };
687
+ var checkboxHiddenHeaderSx = { visibility: "hidden" };
688
+ function BiampTableRowInner({
689
+ row,
690
+ onRowClick,
691
+ isRowClickable,
692
+ enableRowSelection,
693
+ enableExpanding,
694
+ selectChildrenWithParent,
695
+ getRowLabel,
696
+ hasExpandableRows
697
+ }) {
698
+ const clickable = onRowClick ? isRowClickable ? isRowClickable(row.original) : true : false;
699
+ return /* @__PURE__ */ jsxs5(
700
+ TableRow,
701
+ {
702
+ hover: clickable,
703
+ selected: enableRowSelection ? row.getIsSelected() : void 0,
704
+ role: clickable ? "button" : void 0,
705
+ tabIndex: clickable ? 0 : void 0,
706
+ sx: clickable ? rowCursorPointerSx : void 0,
707
+ onClick: clickable && onRowClick ? () => onRowClick(row.original) : void 0,
708
+ onKeyDown: clickable && onRowClick ? (e) => {
709
+ if (e.key === "Enter" || e.key === " ") {
710
+ e.preventDefault();
711
+ onRowClick(row.original);
712
+ }
713
+ } : void 0,
714
+ children: [
715
+ enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: selectionCellSx, children: /* @__PURE__ */ jsx8(
716
+ Checkbox,
717
+ {
718
+ checked: row.getIsSelected(),
719
+ disabled: !row.getCanSelect(),
720
+ onChange: (e) => row.toggleSelected(e.target.checked, {
721
+ selectChildren: selectChildrenWithParent
722
+ }),
723
+ onClick: (e) => e.stopPropagation(),
724
+ sx: !row.getCanSelect() ? checkboxHiddenSx : void 0,
725
+ slotProps: {
726
+ input: {
727
+ "aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${row.index + 1}`
728
+ }
729
+ }
730
+ }
731
+ ) }),
732
+ row.getVisibleCells().map((cell, cellIndex, cells) => {
733
+ const sticky = cell.column.columnDef.meta?.sticky;
734
+ const isExpandCell = enableExpanding && !sticky && cellIndex === cells.findIndex((c) => !c.column.columnDef.meta?.sticky);
735
+ return /* @__PURE__ */ jsx8(
736
+ TableCell,
737
+ {
738
+ "data-sticky": sticky || void 0,
739
+ sx: cellSx(sticky, cell.column.columnDef.meta?.minWidth, 2),
740
+ children: (() => {
741
+ const content = flexRender(
742
+ cell.column.columnDef.cell,
743
+ cell.getContext()
744
+ );
745
+ if (sticky) return content;
746
+ const truncated = /* @__PURE__ */ jsx8(BiampTableTruncatedCell, { children: content });
747
+ if (!isExpandCell) return truncated;
748
+ const rowLabel = getRowLabel ? getRowLabel(row.original) : `row ${row.index + 1}`;
749
+ return /* @__PURE__ */ jsxs5(
750
+ Box4,
751
+ {
752
+ sx: row.depth > 0 ? { ...expandCellBaseSx, pl: `${row.depth * 12}px` } : expandCellBaseSx,
753
+ children: [
754
+ row.getCanExpand() ? /* @__PURE__ */ jsx8(
755
+ ChevronRightIcon,
756
+ {
757
+ onClick: (e) => {
758
+ e.stopPropagation();
759
+ row.toggleExpanded();
760
+ },
761
+ "aria-label": row.getIsExpanded() ? `Collapse ${rowLabel}` : `Expand ${rowLabel}`,
762
+ "aria-expanded": row.getIsExpanded(),
763
+ variant: "xs",
764
+ sx: row.getIsExpanded() ? chevronExpandedSx : chevronCollapsedSx
765
+ }
766
+ ) : hasExpandableRows ? /* @__PURE__ */ jsx8(Box4, { sx: expandPlaceholderSx }) : null,
767
+ truncated
768
+ ]
769
+ }
770
+ );
771
+ })()
772
+ },
773
+ cell.id
774
+ );
775
+ })
776
+ ]
777
+ },
778
+ row.id
779
+ );
780
+ }
781
+ function biampTableRowPropsAreEqual(prev, next) {
782
+ return prev.row.id === next.row.id && prev.row.original === next.row.original && prev.row.getIsSelected() === next.row.getIsSelected() && prev.row.getIsExpanded() === next.row.getIsExpanded() && prev.row.getVisibleCells().length === next.row.getVisibleCells().length && prev.enableRowSelection === next.enableRowSelection && prev.enableExpanding === next.enableExpanding && prev.hasExpandableRows === next.hasExpandableRows && prev.selectChildrenWithParent === next.selectChildrenWithParent && prev.onRowClick === next.onRowClick && prev.isRowClickable === next.isRowClickable && prev.getRowLabel === next.getRowLabel;
783
+ }
784
+ var BiampTableRow = React2.memo(
785
+ BiampTableRowInner,
786
+ biampTableRowPropsAreEqual
787
+ );
651
788
  function BiampTable({
652
789
  table,
653
790
  onRowClick,
@@ -699,28 +836,16 @@ function BiampTable({
699
836
  sx: { minWidth: tableMinWidth, tableLayout: "auto" },
700
837
  children: [
701
838
  /* @__PURE__ */ jsx8(TableHead, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsxs5(TableRow, { children: [
702
- enableRowSelection && /* @__PURE__ */ jsx8(
703
- TableCell,
839
+ enableRowSelection && /* @__PURE__ */ jsx8(TableCell, { padding: "checkbox", sx: headerSelectionCellSx, children: !hideSelectAll && /* @__PURE__ */ jsx8(
840
+ Checkbox,
704
841
  {
705
- padding: "checkbox",
706
- sx: {
707
- position: "sticky",
708
- left: 0,
709
- zIndex: 3,
710
- bgcolor: "background.paper"
711
- },
712
- children: !hideSelectAll && /* @__PURE__ */ jsx8(
713
- Checkbox,
714
- {
715
- checked: table.getIsAllPageRowsSelected(),
716
- indeterminate: table.getIsSomePageRowsSelected(),
717
- onChange: table.getToggleAllPageRowsSelectedHandler(),
718
- sx: rows.length === 0 ? { visibility: "hidden" } : void 0,
719
- slotProps: { input: { "aria-label": "Select all rows" } }
720
- }
721
- )
842
+ checked: table.getIsAllPageRowsSelected(),
843
+ indeterminate: table.getIsSomePageRowsSelected(),
844
+ onChange: table.getToggleAllPageRowsSelectedHandler(),
845
+ sx: rows.length === 0 ? checkboxHiddenHeaderSx : void 0,
846
+ slotProps: { input: { "aria-label": "Select all rows" } }
722
847
  }
723
- ),
848
+ ) }),
724
849
  headerGroup.headers.map((header) => {
725
850
  const sticky = header.column.columnDef.meta?.sticky;
726
851
  return /* @__PURE__ */ jsx8(
@@ -759,125 +884,20 @@ function BiampTable({
759
884
  );
760
885
  })
761
886
  ] }, headerGroup.id)) }),
762
- /* @__PURE__ */ jsx8(TableBody, { sx: { opacity: showLoading ? 0.3 : 1 }, children: !showError && rows.map((row) => {
763
- const clickable = onRowClick ? isRowClickable ? isRowClickable(row.original) : true : false;
764
- return /* @__PURE__ */ jsxs5(
765
- TableRow,
766
- {
767
- hover: clickable,
768
- selected: enableRowSelection ? row.getIsSelected() : void 0,
769
- role: clickable ? "button" : void 0,
770
- tabIndex: clickable ? 0 : void 0,
771
- sx: { cursor: clickable ? "pointer" : void 0 },
772
- onClick: clickable && onRowClick ? () => onRowClick(row.original) : void 0,
773
- onKeyDown: clickable && onRowClick ? (e) => {
774
- if (e.key === "Enter" || e.key === " ") {
775
- e.preventDefault();
776
- onRowClick(row.original);
777
- }
778
- } : void 0,
779
- children: [
780
- enableRowSelection && /* @__PURE__ */ jsx8(
781
- TableCell,
782
- {
783
- padding: "checkbox",
784
- sx: {
785
- position: "sticky",
786
- left: 0,
787
- zIndex: 2,
788
- bgcolor: "background.paper",
789
- ".MuiTableRow-hover:hover > &, .Mui-selected > &": {
790
- bgcolor: ({ palette }) => palette.mode === "dark" ? palette.grey[800] : palette.grey[100]
791
- }
792
- },
793
- children: /* @__PURE__ */ jsx8(
794
- Checkbox,
795
- {
796
- checked: row.getIsSelected(),
797
- disabled: !row.getCanSelect(),
798
- onChange: (e) => row.toggleSelected(e.target.checked, {
799
- selectChildren: selectChildrenWithParent
800
- }),
801
- onClick: (e) => e.stopPropagation(),
802
- sx: !row.getCanSelect() ? { visibility: "hidden" } : void 0,
803
- slotProps: {
804
- input: {
805
- "aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${row.index + 1}`
806
- }
807
- }
808
- }
809
- )
810
- }
811
- ),
812
- row.getVisibleCells().map((cell, cellIndex, cells) => {
813
- const sticky = cell.column.columnDef.meta?.sticky;
814
- const isExpandCell = enableExpanding && !sticky && cellIndex === cells.findIndex(
815
- (c) => !c.column.columnDef.meta?.sticky
816
- );
817
- return /* @__PURE__ */ jsx8(
818
- TableCell,
819
- {
820
- "data-sticky": sticky || void 0,
821
- sx: cellSx(
822
- sticky,
823
- cell.column.columnDef.meta?.minWidth,
824
- 2
825
- ),
826
- children: (() => {
827
- const content = flexRender(
828
- cell.column.columnDef.cell,
829
- cell.getContext()
830
- );
831
- if (sticky) return content;
832
- const truncated = /* @__PURE__ */ jsx8(BiampTableTruncatedCell, { children: content });
833
- if (!isExpandCell) return truncated;
834
- const rowLabel = getRowLabel ? getRowLabel(row.original) : `row ${row.index + 1}`;
835
- return /* @__PURE__ */ jsxs5(
836
- Box4,
837
- {
838
- sx: {
839
- display: "flex",
840
- alignItems: "center",
841
- pl: `${row.depth * 12}px`
842
- },
843
- children: [
844
- row.getCanExpand() ? /* @__PURE__ */ jsx8(
845
- IconButton,
846
- {
847
- variant: "none",
848
- onClick: (e) => {
849
- e.stopPropagation();
850
- row.toggleExpanded();
851
- },
852
- "aria-label": row.getIsExpanded() ? `Collapse ${rowLabel}` : `Expand ${rowLabel}`,
853
- "aria-expanded": row.getIsExpanded(),
854
- children: /* @__PURE__ */ jsx8(
855
- ChevronRightIcon,
856
- {
857
- variant: "xs",
858
- sx: {
859
- color: ({ palette }) => palette.text.secondary,
860
- transition: "transform 150ms ease",
861
- transform: row.getIsExpanded() ? "rotate(90deg)" : "rotate(0deg)"
862
- }
863
- }
864
- )
865
- }
866
- ) : hasExpandableRows ? /* @__PURE__ */ jsx8(Box4, { sx: { width: 28 } }) : null,
867
- truncated
868
- ]
869
- }
870
- );
871
- })()
872
- },
873
- cell.id
874
- );
875
- })
876
- ]
877
- },
878
- row.id
879
- );
880
- }) })
887
+ /* @__PURE__ */ jsx8(TableBody, { sx: { opacity: showLoading ? 0.3 : 1 }, children: !showError && rows.map((row) => /* @__PURE__ */ jsx8(
888
+ BiampTableRow,
889
+ {
890
+ row,
891
+ onRowClick,
892
+ isRowClickable,
893
+ enableRowSelection,
894
+ enableExpanding,
895
+ selectChildrenWithParent,
896
+ getRowLabel,
897
+ hasExpandableRows
898
+ },
899
+ row.id
900
+ )) })
881
901
  ]
882
902
  }
883
903
  ),
@@ -923,7 +943,7 @@ function BiampTableContainer({
923
943
  }
924
944
 
925
945
  // src/BiampTable/BiampTableCellActionButton.tsx
926
- import { IconButton as IconButton2, Tooltip as Tooltip2 } from "@mui/material";
946
+ import { IconButton, Tooltip as Tooltip2 } from "@mui/material";
927
947
  import { jsx as jsx10 } from "react/jsx-runtime";
928
948
  function BiampTableCellActionButton({ label, icon, ...props }) {
929
949
  return /* @__PURE__ */ jsx10(
@@ -934,7 +954,7 @@ function BiampTableCellActionButton({ label, icon, ...props }) {
934
954
  enterDelay: 500,
935
955
  enterNextDelay: 500,
936
956
  disableInteractive: true,
937
- children: /* @__PURE__ */ jsx10("span", { children: /* @__PURE__ */ jsx10(IconButton2, { "aria-label": label, ...props, children: icon }) })
957
+ children: /* @__PURE__ */ jsx10("span", { children: /* @__PURE__ */ jsx10(IconButton, { "aria-label": label, ...props, children: icon }) })
938
958
  }
939
959
  );
940
960
  }
@@ -1077,7 +1097,7 @@ import { useState as useState3 } from "react";
1077
1097
  // src/BiampTable/BiampTableToolbarActionButton.tsx
1078
1098
  import {
1079
1099
  Badge,
1080
- IconButton as IconButton3
1100
+ IconButton as IconButton2
1081
1101
  } from "@mui/material";
1082
1102
  import { jsx as jsx12 } from "react/jsx-runtime";
1083
1103
  function BiampTableToolbarActionButton({
@@ -1088,7 +1108,7 @@ function BiampTableToolbarActionButton({
1088
1108
  }) {
1089
1109
  const showBadge = badgeContent != null && badgeContent !== 0;
1090
1110
  return /* @__PURE__ */ jsx12(
1091
- IconButton3,
1111
+ IconButton2,
1092
1112
  {
1093
1113
  "aria-label": showBadge ? `${label} (${badgeContent})` : label,
1094
1114
  ...props,
@@ -1291,7 +1311,7 @@ import {
1291
1311
  Button,
1292
1312
  Divider as Divider2,
1293
1313
  Drawer,
1294
- IconButton as IconButton4,
1314
+ IconButton as IconButton3,
1295
1315
  Typography as Typography4
1296
1316
  } from "@mui/material";
1297
1317
  import { CloseIcon, FilterIcon } from "@bwp-web/assets";
@@ -1368,7 +1388,7 @@ function BiampTableToolbarFilters({
1368
1388
  )
1369
1389
  ] }),
1370
1390
  /* @__PURE__ */ jsx18(
1371
- IconButton4,
1391
+ IconButton3,
1372
1392
  {
1373
1393
  size: "medium",
1374
1394
  onClick: handleClose,
@@ -1429,7 +1449,7 @@ function BiampTableToolbarFilters({
1429
1449
  import {
1430
1450
  Box as Box9,
1431
1451
  Collapse,
1432
- IconButton as IconButton5,
1452
+ IconButton as IconButton4,
1433
1453
  InputAdornment as InputAdornment2,
1434
1454
  InputBase,
1435
1455
  TextField as TextField2,
@@ -1508,7 +1528,7 @@ function BiampTableToolbarSearch({
1508
1528
  }
1509
1529
  };
1510
1530
  const clearButton = inputValue ? /* @__PURE__ */ jsx19(InputAdornment2, { position: "end", children: /* @__PURE__ */ jsx19(
1511
- IconButton5,
1531
+ IconButton4,
1512
1532
  {
1513
1533
  size: "small",
1514
1534
  onClick: handleClear,
@@ -1578,7 +1598,7 @@ function BiampTableToolbarSearch({
1578
1598
  if (expandable) {
1579
1599
  return /* @__PURE__ */ jsxs9(Box9, { display: "flex", alignItems: "center", minWidth: 28, children: [
1580
1600
  /* @__PURE__ */ jsx19(
1581
- IconButton5,
1601
+ IconButton4,
1582
1602
  {
1583
1603
  "aria-label": expandLabel ?? placeholder,
1584
1604
  onClick: () => setIsExpanded(true),
@@ -1671,10 +1691,11 @@ function getDirtyColumnVisibility(visibility, defaults) {
1671
1691
  // src/BiampTable/useBiampServerSideTable.ts
1672
1692
  var coreRowModel = getCoreRowModel();
1673
1693
  var expandedRowModel = getExpandedRowModel();
1694
+ var defaultGetRowId = (row) => row.id;
1674
1695
  function useBiampServerSideTable({
1675
1696
  data,
1676
1697
  columns,
1677
- getRowId = (row) => row.id,
1698
+ getRowId = defaultGetRowId,
1678
1699
  order,
1679
1700
  onOrderChange,
1680
1701
  page,
@@ -1690,12 +1711,11 @@ function useBiampServerSideTable({
1690
1711
  onExpandedChange,
1691
1712
  getSubRows
1692
1713
  }) {
1693
- const defaultColumnVisibility = useMemo(
1694
- () => getDefaultColumnVisibilityFromDefs(columns),
1695
- [columns]
1696
- );
1697
- const { columnIdToField, fieldToColumnId } = useMemo(
1698
- () => getOrderFieldMappings(columns),
1714
+ const { defaultColumnVisibility, columnIdToField, fieldToColumnId } = useMemo(
1715
+ () => ({
1716
+ defaultColumnVisibility: getDefaultColumnVisibilityFromDefs(columns),
1717
+ ...getOrderFieldMappings(columns)
1718
+ }),
1699
1719
  [columns]
1700
1720
  );
1701
1721
  const sorting = useMemo(
@@ -1764,8 +1784,10 @@ function useBiampServerSideTable({
1764
1784
  },
1765
1785
  // Expanding — only when expanded state is provided
1766
1786
  ...expanded != null && {
1767
- getExpandedRowModel: expandedRowModel,
1768
- getSubRows,
1787
+ // Only attach getExpandedRowModel when getSubRows is provided.
1788
+ // Without it, the expanded model recomputes on every state change
1789
+ // (including selection), adding unnecessary overhead.
1790
+ ...getSubRows && { getExpandedRowModel: expandedRowModel, getSubRows },
1769
1791
  onExpandedChange: onExpandedChange ? (updater) => {
1770
1792
  const next = typeof updater === "function" ? updater(expanded) : updater;
1771
1793
  onExpandedChange(next);