@ctlyst.id/internal-ui 3.4.2 → 3.4.4

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.mjs CHANGED
@@ -1077,40 +1077,57 @@ var useDataTable = ({
1077
1077
  };
1078
1078
  };
1079
1079
  var DataTable = React5.forwardRef((props, ref) => {
1080
- var _a, _b, _c, _d;
1080
+ var _a, _b, _c, _d, _e, _f, _g;
1081
1081
  const { isLoading, styles, headerSticky, onRowClick, container, columnPinning } = props;
1082
1082
  const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
1083
1083
  const refTable = React5.useRef(null);
1084
1084
  React5.useImperativeHandle(ref, () => ({
1085
1085
  toggleAllRowsSelected
1086
1086
  }));
1087
- let lastPinnedColumn = 0;
1088
- (_a = refTable.current) == null ? void 0 : _a.addEventListener("scroll", (s) => {
1089
- var _a2, _b2, _c2, _d2;
1090
- const element = s.currentTarget;
1091
- if (element.scrollLeft > 0) {
1092
- (_a2 = refTable.current) == null ? void 0 : _a2.setAttribute("data-pin-left", "true");
1093
- } else {
1094
- (_b2 = refTable.current) == null ? void 0 : _b2.removeAttribute("data-pin-left");
1095
- }
1096
- if (element.scrollLeft < element.scrollWidth - (lastPinnedColumn + element.offsetWidth)) {
1097
- (_c2 = refTable.current) == null ? void 0 : _c2.setAttribute("data-pin-right", "true");
1087
+ const tableResizeHandler = () => {
1088
+ var _a2, _b2, _c2, _d2, _e2;
1089
+ if (((_a2 = refTable.current) == null ? void 0 : _a2.offsetWidth) === ((_b2 = refTable.current) == null ? void 0 : _b2.scrollWidth)) {
1090
+ (_c2 = refTable.current) == null ? void 0 : _c2.removeAttribute("data-pin-right");
1091
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-left");
1098
1092
  } else {
1099
- (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-right");
1093
+ (_e2 = refTable.current) == null ? void 0 : _e2.setAttribute("data-pin-right", "true");
1100
1094
  }
1101
- });
1095
+ };
1096
+ let lastPinnedColumn = 0;
1097
+ React5.useEffect(() => {
1098
+ var _a2;
1099
+ (_a2 = refTable.current) == null ? void 0 : _a2.addEventListener("scroll", (s) => {
1100
+ var _a3, _b2, _c2, _d2;
1101
+ const element = s.currentTarget;
1102
+ if (element.scrollLeft > 0) {
1103
+ (_a3 = refTable.current) == null ? void 0 : _a3.setAttribute("data-pin-left", "true");
1104
+ } else {
1105
+ (_b2 = refTable.current) == null ? void 0 : _b2.removeAttribute("data-pin-left");
1106
+ }
1107
+ if (element.scrollLeft < element.scrollWidth - (lastPinnedColumn + element.offsetWidth)) {
1108
+ (_c2 = refTable.current) == null ? void 0 : _c2.setAttribute("data-pin-right", "true");
1109
+ } else {
1110
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-right");
1111
+ }
1112
+ });
1113
+ window.addEventListener("resize", tableResizeHandler);
1114
+ return () => {
1115
+ window.removeEventListener("resize", tableResizeHandler);
1116
+ };
1117
+ }, []);
1118
+ 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);
1102
1119
  return /* @__PURE__ */ jsx24(
1103
1120
  Box11,
1104
1121
  {
1105
1122
  overflowX: "auto",
1106
1123
  overflowY: "hidden",
1107
1124
  position: "relative",
1108
- pl: ((_b = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _b.length) ? 0 : 4,
1109
- pr: ((_c = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _c.length) ? 0 : 4,
1125
+ pl: ((_e = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _e.length) ? 0 : 4,
1126
+ pr: ((_f = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _f.length) ? 0 : 4,
1110
1127
  maxW: "100%",
1111
1128
  w: "full",
1112
1129
  ref: refTable,
1113
- ...((_d = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _d.length) ? { "data-pin-right": true } : {},
1130
+ ...((_g = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _g.length) && hasScroll ? { "data-pin-right": true } : {},
1114
1131
  ...container,
1115
1132
  children: isLoading ? /* @__PURE__ */ jsxs8(Table, { ...styles == null ? void 0 : styles.table, "data-loading": "true", children: [
1116
1133
  /* @__PURE__ */ jsx24(Thead, { ...(styles == null ? void 0 : styles.tableHead, headerSticky ? { position: "sticky", top: 0, bg: "white", zIndex: 1 } : {}), children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx24(Tr, { mx: "2", ...styles == null ? void 0 : styles.tableRow, children: headerGroup.headers.map((header, index) => /* @__PURE__ */ jsx24(