@ctlyst.id/internal-ui 3.4.3 → 3.4.5

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -938,6 +938,7 @@ var getCommonPinningStyles = (column) => {
938
938
  const isFirstLeftPinnedColumn = isPinned === "left" && column.getIsFirstColumn("left");
939
939
  const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
940
940
  const isFirstRightPinnedColumn = isPinned === "right" && column.getIsFirstColumn("right");
941
+ const isLastRightPinnedColumn = isPinned === "right" && column.getIsLastColumn("right");
941
942
  return {
942
943
  left: isPinned === "left" ? `${column.getStart("left")}px` : void 0,
943
944
  right: isPinned === "right" ? `${column.getAfter("right")}px` : void 0,
@@ -947,6 +948,9 @@ var getCommonPinningStyles = (column) => {
947
948
  ...isFirstLeftPinnedColumn ? {
948
949
  pl: "16px"
949
950
  } : { pl: "8px" },
951
+ ...isLastRightPinnedColumn ? {
952
+ pr: "16px"
953
+ } : { pr: "8px" },
950
954
  ...isLastLeftPinnedColumn ? {
951
955
  py: "16px",
952
956
  pr: "8px",
@@ -966,7 +970,7 @@ var getCommonPinningStyles = (column) => {
966
970
  } : {},
967
971
  ...isFirstRightPinnedColumn ? {
968
972
  py: "16px",
969
- px: "8px",
973
+ pl: "8px",
970
974
  "&:after": {
971
975
  transition: "all 0.3s",
972
976
  content: "''",
@@ -1077,18 +1081,27 @@ var useDataTable = ({
1077
1081
  };
1078
1082
  };
1079
1083
  var DataTable = React5.forwardRef((props, ref) => {
1080
- var _a, _b;
1084
+ var _a, _b, _c, _d, _e, _f, _g;
1081
1085
  const { isLoading, styles, headerSticky, onRowClick, container, columnPinning } = props;
1082
1086
  const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
1083
1087
  const refTable = React5.useRef(null);
1084
1088
  React5.useImperativeHandle(ref, () => ({
1085
1089
  toggleAllRowsSelected
1086
1090
  }));
1091
+ const tableResizeHandler = () => {
1092
+ var _a2, _b2, _c2, _d2, _e2;
1093
+ if (((_a2 = refTable.current) == null ? void 0 : _a2.offsetWidth) === ((_b2 = refTable.current) == null ? void 0 : _b2.scrollWidth)) {
1094
+ (_c2 = refTable.current) == null ? void 0 : _c2.removeAttribute("data-pin-right");
1095
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-left");
1096
+ } else {
1097
+ (_e2 = refTable.current) == null ? void 0 : _e2.setAttribute("data-pin-right", "true");
1098
+ }
1099
+ };
1087
1100
  let lastPinnedColumn = 0;
1088
1101
  React5.useEffect(() => {
1089
1102
  var _a2;
1090
1103
  (_a2 = refTable.current) == null ? void 0 : _a2.addEventListener("scroll", (s) => {
1091
- var _a3, _b2, _c, _d;
1104
+ var _a3, _b2, _c2, _d2;
1092
1105
  const element = s.currentTarget;
1093
1106
  if (element.scrollLeft > 0) {
1094
1107
  (_a3 = refTable.current) == null ? void 0 : _a3.setAttribute("data-pin-left", "true");
@@ -1096,32 +1109,29 @@ var DataTable = React5.forwardRef((props, ref) => {
1096
1109
  (_b2 = refTable.current) == null ? void 0 : _b2.removeAttribute("data-pin-left");
1097
1110
  }
1098
1111
  if (element.scrollLeft < element.scrollWidth - (lastPinnedColumn + element.offsetWidth)) {
1099
- (_c = refTable.current) == null ? void 0 : _c.setAttribute("data-pin-right", "true");
1112
+ (_c2 = refTable.current) == null ? void 0 : _c2.setAttribute("data-pin-right", "true");
1100
1113
  } else {
1101
- (_d = refTable.current) == null ? void 0 : _d.removeAttribute("data-pin-right");
1102
- }
1103
- });
1104
- window.addEventListener("resize", (ev) => {
1105
- var _a3, _b2, _c, _d, _e;
1106
- if (((_a3 = refTable.current) == null ? void 0 : _a3.offsetWidth) === ((_b2 = refTable.current) == null ? void 0 : _b2.scrollWidth)) {
1107
- (_c = refTable.current) == null ? void 0 : _c.removeAttribute("data-pin-right");
1108
- (_d = refTable.current) == null ? void 0 : _d.removeAttribute("data-pin-left");
1109
- } else {
1110
- (_e = refTable.current) == null ? void 0 : _e.setAttribute("data-pin-right", "true");
1114
+ (_d2 = refTable.current) == null ? void 0 : _d2.removeAttribute("data-pin-right");
1111
1115
  }
1112
1116
  });
1117
+ window.addEventListener("resize", tableResizeHandler);
1118
+ return () => {
1119
+ window.removeEventListener("resize", tableResizeHandler);
1120
+ };
1113
1121
  }, []);
1122
+ 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);
1114
1123
  return /* @__PURE__ */ jsx24(
1115
1124
  Box11,
1116
1125
  {
1117
1126
  overflowX: "auto",
1118
1127
  overflowY: "hidden",
1119
1128
  position: "relative",
1120
- pl: ((_a = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _a.length) ? 0 : 4,
1121
- pr: ((_b = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _b.length) ? 0 : 4,
1129
+ pl: ((_e = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _e.length) ? 0 : 4,
1130
+ pr: ((_f = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _f.length) ? 0 : 4,
1122
1131
  maxW: "100%",
1123
1132
  w: "full",
1124
1133
  ref: refTable,
1134
+ ...((_g = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _g.length) && hasScroll ? { "data-pin-right": true } : {},
1125
1135
  ...container,
1126
1136
  children: isLoading ? /* @__PURE__ */ jsxs8(Table, { ...styles == null ? void 0 : styles.table, "data-loading": "true", children: [
1127
1137
  /* @__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(
@@ -1174,17 +1184,17 @@ var DataTable = React5.forwardRef((props, ref) => {
1174
1184
  gap: 2,
1175
1185
  children: [
1176
1186
  flexRender(header.column.columnDef.header, header.getContext()),
1177
- /* @__PURE__ */ jsx24(
1187
+ (_b2 = header.column.getCanSort() && {
1188
+ asc: /* @__PURE__ */ jsx24(ChevronUpIcon, { h: 4, w: 4, color: "neutral.500" }),
1189
+ desc: /* @__PURE__ */ jsx24(ChevronDownIcon, { h: 4, w: 4, color: "neutral.500" })
1190
+ }[header.column.getIsSorted()]) != null ? _b2 : /* @__PURE__ */ jsx24(
1178
1191
  Box11,
1179
1192
  {
1180
1193
  as: "span",
1181
1194
  cursor: header.column.getCanSort() ? "pointer" : "default",
1182
1195
  "data-test-id": `CT_Container_SortingIcon_${header.id}`,
1183
1196
  onClick: header.column.getToggleSortingHandler(),
1184
- children: (_b2 = header.column.getCanSort() && {
1185
- asc: /* @__PURE__ */ jsx24(ChevronUpIcon, { h: 4, w: 4, color: "neutral.500" }),
1186
- desc: /* @__PURE__ */ jsx24(ChevronDownIcon, { h: 4, w: 4, color: "neutral.500" })
1187
- }[header.column.getIsSorted()]) != null ? _b2 : /* @__PURE__ */ jsx24(Box11, { display: "flex", justifyContent: "center", alignItems: "center", boxSize: 4, children: /* @__PURE__ */ jsx24(UpDownIcon, { color: "neutral.500" }) })
1197
+ children: /* @__PURE__ */ jsx24(Box11, { display: "flex", justifyContent: "center", alignItems: "center", boxSize: 4, children: /* @__PURE__ */ jsx24(UpDownIcon, { color: "neutral.500" }) })
1188
1198
  }
1189
1199
  )
1190
1200
  ]