@ctlyst.id/internal-ui 3.4.3 → 3.4.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.js CHANGED
@@ -1419,18 +1419,27 @@ var useDataTable = ({
1419
1419
  };
1420
1420
  };
1421
1421
  var DataTable = React5.forwardRef((props, ref) => {
1422
- var _a, _b;
1422
+ var _a, _b, _c, _d, _e, _f, _g;
1423
1423
  const { isLoading, styles, headerSticky, onRowClick, container, columnPinning } = props;
1424
1424
  const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
1425
1425
  const refTable = React5.useRef(null);
1426
1426
  React5.useImperativeHandle(ref, () => ({
1427
1427
  toggleAllRowsSelected
1428
1428
  }));
1429
+ const tableResizeHandler = () => {
1430
+ var _a2, _b2, _c2, _d2, _e2;
1431
+ if (((_a2 = refTable.current) == null ? void 0 : _a2.offsetWidth) === ((_b2 = refTable.current) == null ? void 0 : _b2.scrollWidth)) {
1432
+ (_c2 = refTable.current) == null ? void 0 : _c2.removeAttribute("data-pin-right");
1433
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-left");
1434
+ } else {
1435
+ (_e2 = refTable.current) == null ? void 0 : _e2.setAttribute("data-pin-right", "true");
1436
+ }
1437
+ };
1429
1438
  let lastPinnedColumn = 0;
1430
1439
  React5.useEffect(() => {
1431
1440
  var _a2;
1432
1441
  (_a2 = refTable.current) == null ? void 0 : _a2.addEventListener("scroll", (s) => {
1433
- var _a3, _b2, _c, _d;
1442
+ var _a3, _b2, _c2, _d2;
1434
1443
  const element = s.currentTarget;
1435
1444
  if (element.scrollLeft > 0) {
1436
1445
  (_a3 = refTable.current) == null ? void 0 : _a3.setAttribute("data-pin-left", "true");
@@ -1438,32 +1447,29 @@ var DataTable = React5.forwardRef((props, ref) => {
1438
1447
  (_b2 = refTable.current) == null ? void 0 : _b2.removeAttribute("data-pin-left");
1439
1448
  }
1440
1449
  if (element.scrollLeft < element.scrollWidth - (lastPinnedColumn + element.offsetWidth)) {
1441
- (_c = refTable.current) == null ? void 0 : _c.setAttribute("data-pin-right", "true");
1450
+ (_c2 = refTable.current) == null ? void 0 : _c2.setAttribute("data-pin-right", "true");
1442
1451
  } else {
1443
- (_d = refTable.current) == null ? void 0 : _d.removeAttribute("data-pin-right");
1444
- }
1445
- });
1446
- window.addEventListener("resize", (ev) => {
1447
- var _a3, _b2, _c, _d, _e;
1448
- if (((_a3 = refTable.current) == null ? void 0 : _a3.offsetWidth) === ((_b2 = refTable.current) == null ? void 0 : _b2.scrollWidth)) {
1449
- (_c = refTable.current) == null ? void 0 : _c.removeAttribute("data-pin-right");
1450
- (_d = refTable.current) == null ? void 0 : _d.removeAttribute("data-pin-left");
1451
- } else {
1452
- (_e = refTable.current) == null ? void 0 : _e.setAttribute("data-pin-right", "true");
1452
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-right");
1453
1453
  }
1454
1454
  });
1455
+ window.addEventListener("resize", tableResizeHandler);
1456
+ return () => {
1457
+ window.removeEventListener("resize", tableResizeHandler);
1458
+ };
1455
1459
  }, []);
1460
+ const hasScroll = ((_a = refTable == null ? void 0 : refTable.current) == null ? void 0 : _a.offsetWidth) && ((_b = refTable == null ? void 0 : refTable.current) == null ? void 0 : _b.scrollWidth) && ((_c = refTable == null ? void 0 : refTable.current) == null ? void 0 : _c.offsetWidth) < ((_d = refTable == null ? void 0 : refTable.current) == null ? void 0 : _d.scrollWidth);
1456
1461
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
1457
1462
  import_react28.Box,
1458
1463
  {
1459
1464
  overflowX: "auto",
1460
1465
  overflowY: "hidden",
1461
1466
  position: "relative",
1462
- pl: ((_a = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _a.length) ? 0 : 4,
1463
- pr: ((_b = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _b.length) ? 0 : 4,
1467
+ pl: ((_e = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _e.length) ? 0 : 4,
1468
+ pr: ((_f = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _f.length) ? 0 : 4,
1464
1469
  maxW: "100%",
1465
1470
  w: "full",
1466
1471
  ref: refTable,
1472
+ ...((_g = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _g.length) && hasScroll ? { "data-pin-right": true } : {},
1467
1473
  ...container,
1468
1474
  children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime24.jsxs)(import_react28.Table, { ...styles == null ? void 0 : styles.table, "data-loading": "true", children: [
1469
1475
  /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react28.Thead, { ...(styles == null ? void 0 : styles.tableHead, headerSticky ? { position: "sticky", top: 0, bg: "white", zIndex: 1 } : {}), children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react28.Tr, { mx: "2", ...styles == null ? void 0 : styles.tableRow, children: headerGroup.headers.map((header, index) => /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(