@bwp-web/components 0.11.6 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -467,6 +467,7 @@ function BiampLayout({
467
467
  import {
468
468
  Box as Box3,
469
469
  Checkbox,
470
+ IconButton,
470
471
  Table as MuiTable,
471
472
  TableBody,
472
473
  TableCell,
@@ -476,11 +477,12 @@ import {
476
477
  TableSortLabel
477
478
  } from "@mui/material";
478
479
  import {
480
+ ChevronRightIcon,
479
481
  DropdownChevronDownIcon,
480
482
  DropdownChevronUpIcon
481
483
  } from "@bwp-web/assets";
482
484
  import { flexRender } from "@tanstack/react-table";
483
- import { useCallback, useEffect as useEffect2, useRef as useRef2 } from "react";
485
+ import { useRef as useRef2 } from "react";
484
486
 
485
487
  // src/BiampTable/BiampTableEmptyState.tsx
486
488
  import { NoResultsIcon } from "@bwp-web/assets";
@@ -577,6 +579,7 @@ function BiampTable({
577
579
  error,
578
580
  empty,
579
581
  enableRowSelection = false,
582
+ enableExpanding = false,
580
583
  hideSelectAll,
581
584
  getRowLabel,
582
585
  sx,
@@ -590,24 +593,9 @@ function BiampTable({
590
593
  enableRowSelection ? 48 : 0
591
594
  );
592
595
  const containerRef = useRef2(null);
593
- const lastScrollLeftRef = useRef2(null);
594
- const onContainerScroll = useCallback((target) => {
595
- const { scrollLeft, scrollWidth, clientWidth } = target;
596
- if (!containerRef.current || lastScrollLeftRef.current === scrollLeft)
597
- return;
598
- containerRef.current.dataset["rightShadow"] = scrollWidth - clientWidth > scrollLeft ? "true" : "false";
599
- lastScrollLeftRef.current = scrollLeft;
600
- }, []);
601
- useEffect2(() => {
602
- if (!containerRef.current) return;
603
- const observer = new ResizeObserver(
604
- ([{ target }]) => onContainerScroll(target)
605
- );
606
- observer.observe(containerRef.current);
607
- return () => observer.disconnect();
608
- }, [onContainerScroll]);
609
596
  const showLoading = useLoadingDelay(!!loading);
610
597
  const rows = table.getRowModel().rows;
598
+ const hasExpandableRows = enableExpanding && rows.some((r) => r.getCanExpand());
611
599
  const showError = !!error && !loading;
612
600
  const showEmpty = !showError && !loading && rows.length === 0;
613
601
  return /* @__PURE__ */ jsxs5(
@@ -616,7 +604,6 @@ function BiampTable({
616
604
  component: Box3,
617
605
  ...boxProps,
618
606
  ref: containerRef,
619
- onScroll: (e) => onContainerScroll(e.currentTarget),
620
607
  sx: {
621
608
  display: "flex",
622
609
  flexDirection: "column",
@@ -624,12 +611,6 @@ function BiampTable({
624
611
  overflow: "auto",
625
612
  overscrollBehavior: "none",
626
613
  position: "relative",
627
- '& [data-sticky="right"]': {
628
- transition: "box-shadow .2s"
629
- },
630
- '&[data-right-shadow="true"] [data-sticky="right"]': {
631
- boxShadow: ({ palette }) => `-16px 0px 12px -2px ${palette.background.default}`
632
- },
633
614
  ...sx
634
615
  },
635
616
  children: [
@@ -656,6 +637,7 @@ function BiampTable({
656
637
  checked: table.getIsAllPageRowsSelected(),
657
638
  indeterminate: table.getIsSomePageRowsSelected(),
658
639
  onChange: table.getToggleAllPageRowsSelectedHandler(),
640
+ sx: rows.length === 0 ? { visibility: "hidden" } : void 0,
659
641
  slotProps: { input: { "aria-label": "Select all rows" } }
660
642
  }
661
643
  )
@@ -744,6 +726,7 @@ function BiampTable({
744
726
  disabled: !row.getCanSelect(),
745
727
  onChange: row.getToggleSelectedHandler(),
746
728
  onClick: (e) => e.stopPropagation(),
729
+ sx: !row.getCanSelect() ? { visibility: "hidden" } : void 0,
747
730
  slotProps: {
748
731
  input: {
749
732
  "aria-label": getRowLabel ? `Select ${getRowLabel(row.original)}` : `Select row ${row.index + 1}`
@@ -753,8 +736,11 @@ function BiampTable({
753
736
  )
754
737
  }
755
738
  ),
756
- row.getVisibleCells().map((cell) => {
739
+ row.getVisibleCells().map((cell, cellIndex, cells) => {
757
740
  const sticky = cell.column.columnDef.meta?.sticky;
741
+ const isExpandCell = enableExpanding && !sticky && cellIndex === cells.findIndex(
742
+ (c) => !c.column.columnDef.meta?.sticky
743
+ );
758
744
  return /* @__PURE__ */ jsx7(
759
745
  TableCell,
760
746
  {
@@ -774,7 +760,45 @@ function BiampTable({
774
760
  }
775
761
  }
776
762
  },
777
- children: flexRender(
763
+ children: isExpandCell ? /* @__PURE__ */ jsxs5(
764
+ Box3,
765
+ {
766
+ sx: {
767
+ display: "flex",
768
+ alignItems: "center",
769
+ pl: `${row.depth * 12}px`
770
+ },
771
+ children: [
772
+ row.getCanExpand() ? /* @__PURE__ */ jsx7(
773
+ IconButton,
774
+ {
775
+ variant: "none",
776
+ onClick: (e) => {
777
+ e.stopPropagation();
778
+ row.toggleExpanded();
779
+ },
780
+ "aria-label": row.getIsExpanded() ? `Collapse ${getRowLabel ? getRowLabel(row.original) : `row ${row.index + 1}`}` : `Expand ${getRowLabel ? getRowLabel(row.original) : `row ${row.index + 1}`}`,
781
+ "aria-expanded": row.getIsExpanded(),
782
+ children: /* @__PURE__ */ jsx7(
783
+ ChevronRightIcon,
784
+ {
785
+ variant: "xs",
786
+ sx: {
787
+ color: ({ palette }) => palette.text.secondary,
788
+ transition: "transform 150ms ease",
789
+ transform: row.getIsExpanded() ? "rotate(90deg)" : "rotate(0deg)"
790
+ }
791
+ }
792
+ )
793
+ }
794
+ ) : hasExpandableRows ? /* @__PURE__ */ jsx7(Box3, { sx: { width: 28 } }) : null,
795
+ flexRender(
796
+ cell.column.columnDef.cell,
797
+ cell.getContext()
798
+ )
799
+ ]
800
+ }
801
+ ) : flexRender(
778
802
  cell.column.columnDef.cell,
779
803
  cell.getContext()
780
804
  )
@@ -864,7 +888,7 @@ function BiampTableContainer({
864
888
  }
865
889
 
866
890
  // src/BiampTable/BiampTableCellActionButton.tsx
867
- import { IconButton, Tooltip } from "@mui/material";
891
+ import { IconButton as IconButton2, Tooltip } from "@mui/material";
868
892
  import { jsx as jsx9 } from "react/jsx-runtime";
869
893
  function BiampTableCellActionButton({ label, icon, ...props }) {
870
894
  return /* @__PURE__ */ jsx9(
@@ -875,7 +899,7 @@ function BiampTableCellActionButton({ label, icon, ...props }) {
875
899
  enterDelay: 500,
876
900
  enterNextDelay: 500,
877
901
  disableInteractive: true,
878
- children: /* @__PURE__ */ jsx9("span", { children: /* @__PURE__ */ jsx9(IconButton, { "aria-label": label, ...props, children: icon }) })
902
+ children: /* @__PURE__ */ jsx9("span", { children: /* @__PURE__ */ jsx9(IconButton2, { "aria-label": label, ...props, children: icon }) })
879
903
  }
880
904
  );
881
905
  }
@@ -960,6 +984,7 @@ function BiampTableColumnVisibility({
960
984
  /* @__PURE__ */ jsxs6(
961
985
  ListItem,
962
986
  {
987
+ dense: true,
963
988
  sx: columnListItemSx,
964
989
  onClick: () => table.toggleAllColumnsVisible(!allVisible),
965
990
  children: [
@@ -968,39 +993,45 @@ function BiampTableColumnVisibility({
968
993
  {
969
994
  checked: allVisible,
970
995
  indeterminate: !allVisible && someVisible,
971
- size: "small",
972
996
  slotProps: { input: { "aria-label": `${showAllLabel} columns` } }
973
997
  }
974
998
  ),
975
- /* @__PURE__ */ jsx10(Typography3, { variant: "caption", children: showAllLabel })
999
+ /* @__PURE__ */ jsx10(Typography3, { variant: "caption", fontWeight: 600, children: showAllLabel })
976
1000
  ]
977
1001
  }
978
1002
  ),
979
1003
  /* @__PURE__ */ jsx10(Divider, {}),
980
- /* @__PURE__ */ jsx10(Box4, { sx: { maxHeight: 340, overflow: "auto" }, children: table.getAllLeafColumns().map((column) => {
981
- const columnName = typeof column.columnDef.header === "string" ? column.columnDef.header : column.id;
982
- return /* @__PURE__ */ jsxs6(
983
- ListItem,
984
- {
985
- sx: columnListItemSx,
986
- onClick: column.getToggleVisibilityHandler(),
987
- children: [
988
- /* @__PURE__ */ jsx10(
989
- Checkbox2,
990
- {
991
- checked: column.getIsVisible(),
992
- size: "small",
993
- slotProps: {
994
- input: { "aria-label": `Show ${columnName}` }
995
- }
996
- }
997
- ),
998
- /* @__PURE__ */ jsx10(Typography3, { variant: "caption", children: columnName })
999
- ]
1000
- },
1001
- column.id
1002
- );
1003
- }) })
1004
+ /* @__PURE__ */ jsx10(
1005
+ Box4,
1006
+ {
1007
+ sx: { maxHeight: 340, overflow: "auto", overscrollBehavior: "none" },
1008
+ children: table.getAllLeafColumns().map((column) => {
1009
+ const columnName = column.columnDef.meta?.columnLabel ?? (typeof column.columnDef.header === "string" ? column.columnDef.header : column.id);
1010
+ return /* @__PURE__ */ jsxs6(
1011
+ ListItem,
1012
+ {
1013
+ dense: true,
1014
+ sx: columnListItemSx,
1015
+ onClick: column.getToggleVisibilityHandler(),
1016
+ children: [
1017
+ /* @__PURE__ */ jsx10(
1018
+ Checkbox2,
1019
+ {
1020
+ checked: column.getIsVisible(),
1021
+ sx: { py: 1 },
1022
+ slotProps: {
1023
+ input: { "aria-label": `Show ${columnName}` }
1024
+ }
1025
+ }
1026
+ ),
1027
+ /* @__PURE__ */ jsx10(Typography3, { variant: "caption", children: columnName })
1028
+ ]
1029
+ },
1030
+ column.id
1031
+ );
1032
+ })
1033
+ }
1034
+ )
1004
1035
  ] })
1005
1036
  }
1006
1037
  );
@@ -1013,7 +1044,7 @@ import { useState as useState2 } from "react";
1013
1044
  // src/BiampTable/BiampTableToolbarActionButton.tsx
1014
1045
  import {
1015
1046
  Badge,
1016
- IconButton as IconButton2
1047
+ IconButton as IconButton3
1017
1048
  } from "@mui/material";
1018
1049
  import { jsx as jsx11 } from "react/jsx-runtime";
1019
1050
  function BiampTableToolbarActionButton({
@@ -1024,7 +1055,7 @@ function BiampTableToolbarActionButton({
1024
1055
  }) {
1025
1056
  const showBadge = badgeContent != null && badgeContent !== 0;
1026
1057
  return /* @__PURE__ */ jsx11(
1027
- IconButton2,
1058
+ IconButton3,
1028
1059
  {
1029
1060
  "aria-label": showBadge ? `${label} (${badgeContent})` : label,
1030
1061
  ...props,
@@ -1181,7 +1212,18 @@ function BiampTableToolbarActions({
1181
1212
  children,
1182
1213
  ...props
1183
1214
  }) {
1184
- return /* @__PURE__ */ jsx15(Box6, { display: "flex", alignItems: "center", gap: 1, ml: "auto", ...props, children });
1215
+ return /* @__PURE__ */ jsx15(
1216
+ Box6,
1217
+ {
1218
+ display: "flex",
1219
+ alignItems: "center",
1220
+ ml: "auto",
1221
+ gap: { xs: 0, md: 1 },
1222
+ mr: { xs: 1, md: 0 },
1223
+ ...props,
1224
+ children
1225
+ }
1226
+ );
1185
1227
  }
1186
1228
 
1187
1229
  // src/BiampTable/BiampTableToolbarExport.tsx
@@ -1214,7 +1256,7 @@ import {
1214
1256
  Button,
1215
1257
  Divider as Divider2,
1216
1258
  Drawer,
1217
- IconButton as IconButton3,
1259
+ IconButton as IconButton4,
1218
1260
  Typography as Typography4
1219
1261
  } from "@mui/material";
1220
1262
  import { CloseIcon, FilterIcon } from "@bwp-web/assets";
@@ -1291,7 +1333,7 @@ function BiampTableToolbarFilters({
1291
1333
  )
1292
1334
  ] }),
1293
1335
  /* @__PURE__ */ jsx17(
1294
- IconButton3,
1336
+ IconButton4,
1295
1337
  {
1296
1338
  size: "medium",
1297
1339
  onClick: handleClose,
@@ -1352,26 +1394,28 @@ function BiampTableToolbarFilters({
1352
1394
  import {
1353
1395
  Box as Box8,
1354
1396
  Collapse,
1355
- IconButton as IconButton4,
1397
+ IconButton as IconButton5,
1356
1398
  InputAdornment as InputAdornment2,
1357
- TextField as TextField2
1399
+ InputBase,
1400
+ TextField as TextField2,
1401
+ useMediaQuery
1358
1402
  } from "@mui/material";
1359
1403
  import { CloseIcon as CloseIcon2, SearchIcon as SearchIcon2 } from "@bwp-web/assets";
1360
- import { useEffect as useEffect4, useState as useState4 } from "react";
1404
+ import { useEffect as useEffect3, useState as useState4 } from "react";
1361
1405
 
1362
1406
  // src/BiampTable/useDebouncedCallback.ts
1363
- import { useCallback as useCallback2, useEffect as useEffect3, useRef as useRef4 } from "react";
1407
+ import { useCallback, useEffect as useEffect2, useRef as useRef4 } from "react";
1364
1408
  var BIAMP_TABLE_DEBOUNCE_DELAY = 300;
1365
1409
  function useDebouncedCallback(callback, delay = BIAMP_TABLE_DEBOUNCE_DELAY) {
1366
1410
  const timeoutRef = useRef4(null);
1367
1411
  const callbackRef = useRef4(callback);
1368
1412
  callbackRef.current = callback;
1369
- useEffect3(() => {
1413
+ useEffect2(() => {
1370
1414
  return () => {
1371
1415
  if (timeoutRef.current !== null) clearTimeout(timeoutRef.current);
1372
1416
  };
1373
1417
  }, []);
1374
- return useCallback2(
1418
+ return useCallback(
1375
1419
  (...args) => {
1376
1420
  if (timeoutRef.current !== null) clearTimeout(timeoutRef.current);
1377
1421
  timeoutRef.current = setTimeout(
@@ -1404,13 +1448,15 @@ function BiampTableToolbarSearch({
1404
1448
  clearLabel = "Clear search",
1405
1449
  expandable = false,
1406
1450
  expandLabel,
1451
+ enableMobileView = true,
1407
1452
  sx,
1408
1453
  ...textFieldProps
1409
1454
  }) {
1455
+ const isMobile = useMediaQuery((t) => t.breakpoints.down("md"));
1410
1456
  const [inputValue, setInputValue] = useState4(defaultValue);
1411
1457
  const [isExpanded, setIsExpanded] = useState4(false);
1412
1458
  const debouncedOnChange = useDebouncedCallback(onChange, debounceDelay);
1413
- useEffect4(() => {
1459
+ useEffect3(() => {
1414
1460
  setInputValue(defaultValue);
1415
1461
  }, [defaultValue]);
1416
1462
  const handleChange = (e) => {
@@ -1427,7 +1473,7 @@ function BiampTableToolbarSearch({
1427
1473
  }
1428
1474
  };
1429
1475
  const clearButton = inputValue ? /* @__PURE__ */ jsx18(InputAdornment2, { position: "end", children: /* @__PURE__ */ jsx18(
1430
- IconButton4,
1476
+ IconButton5,
1431
1477
  {
1432
1478
  size: "small",
1433
1479
  onClick: handleClear,
@@ -1470,10 +1516,34 @@ function BiampTableToolbarSearch({
1470
1516
  ...textFieldProps
1471
1517
  }
1472
1518
  );
1519
+ if (isMobile && enableMobileView) {
1520
+ return /* @__PURE__ */ jsxs9(Box8, { display: "flex", alignItems: "center", width: "100%", pr: 1, gap: 1, children: [
1521
+ /* @__PURE__ */ jsx18(SearchIcon2, { sx: { width: 16, height: 16 } }),
1522
+ /* @__PURE__ */ jsx18(
1523
+ InputBase,
1524
+ {
1525
+ name: "search",
1526
+ type: "text",
1527
+ placeholder,
1528
+ inputProps: { maxLength, "aria-label": "Search" },
1529
+ fullWidth: true,
1530
+ value: inputValue,
1531
+ sx: {
1532
+ paddingLeft: 1,
1533
+ height: "36px !important",
1534
+ minHeight: "36px !important",
1535
+ fontSize: (t) => t.typography.body2.fontSize
1536
+ },
1537
+ onChange: handleChange,
1538
+ endAdornment: clearButton
1539
+ }
1540
+ )
1541
+ ] });
1542
+ }
1473
1543
  if (expandable) {
1474
1544
  return /* @__PURE__ */ jsxs9(Box8, { display: "flex", alignItems: "center", minWidth: 28, children: [
1475
1545
  /* @__PURE__ */ jsx18(
1476
- IconButton4,
1546
+ IconButton5,
1477
1547
  {
1478
1548
  "aria-label": expandLabel ?? placeholder,
1479
1549
  onClick: () => setIsExpanded(true),