@ctlyst.id/internal-ui 5.0.4 → 5.2.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.mjs CHANGED
@@ -1007,23 +1007,23 @@ var isCellDisabled = (row, cellId) => {
1007
1007
  }
1008
1008
  return false;
1009
1009
  };
1010
- var getCommonPinningStyles = (column) => {
1010
+ var getCommonPinningStyles = (column, paddingRowX) => {
1011
1011
  const isPinned = column.getIsPinned();
1012
1012
  const isFirstLeftPinnedColumn = isPinned === "left" && column.getIsFirstColumn("left");
1013
1013
  const isLastLeftPinnedColumn = isPinned === "left" && column.getIsLastColumn("left");
1014
1014
  const isFirstRightPinnedColumn = isPinned === "right" && column.getIsFirstColumn("right");
1015
1015
  const isLastRightPinnedColumn = isPinned === "right" && column.getIsLastColumn("right");
1016
1016
  return {
1017
- left: isPinned === "left" ? `${column.getStart("left") + (!isFirstLeftPinnedColumn ? 8 : 0)}px` : void 0,
1018
- right: isPinned === "right" ? `${column.getAfter("right") + (!isLastRightPinnedColumn ? 8 : 0)}px` : void 0,
1017
+ left: isPinned === "left" ? `${column.getStart("left") + (!isFirstLeftPinnedColumn ? paddingRowX : 0)}px` : void 0,
1018
+ right: isPinned === "right" ? `${column.getAfter("right") + (!isLastRightPinnedColumn ? paddingRowX : 0)}px` : void 0,
1019
1019
  position: isPinned ? "sticky" : "relative",
1020
1020
  zIndex: isPinned ? 1 : 0,
1021
1021
  ...isFirstLeftPinnedColumn ? {
1022
- pl: "16px"
1023
- } : { pl: "8px" },
1022
+ pl: `${paddingRowX + 8}px`
1023
+ } : {},
1024
1024
  ...isLastRightPinnedColumn ? {
1025
- pr: "16px"
1026
- } : { pr: "8px" },
1025
+ pr: `${paddingRowX + 8}px`
1026
+ } : {},
1027
1027
  ...isLastLeftPinnedColumn ? {
1028
1028
  py: "16px",
1029
1029
  pr: "8px",
@@ -1079,6 +1079,7 @@ var useDataTable = ({
1079
1079
  const [isFirstLoad, setIsFirstLoad] = React5.useState(true);
1080
1080
  const [sorting, setSorting] = React5.useState(sortingState != null ? sortingState : []);
1081
1081
  const dataColumns = React5.useMemo(() => columns, [columns]);
1082
+ const action = React5.useRef("");
1082
1083
  const checkboxColumn = React5.useMemo(
1083
1084
  () => [
1084
1085
  {
@@ -1090,9 +1091,10 @@ var useDataTable = ({
1090
1091
  "data-test-id": "select-header-data-table",
1091
1092
  ...{
1092
1093
  isDisabled: table2.getPaginationRowModel().rows.filter((row) => !(disabledRow == null ? void 0 : disabledRow(row.original))).length === 0,
1093
- isChecked: table2.getIsAllRowsSelected(),
1094
- isIndeterminate: table2.getIsSomeRowsSelected(),
1094
+ isChecked: table2.getIsAllPageRowsSelected(),
1095
+ isIndeterminate: table2.getIsSomePageRowsSelected(),
1095
1096
  onChange: () => {
1097
+ action.current = "selectAll";
1096
1098
  if (table2.getIsAllRowsSelected()) {
1097
1099
  table2.toggleAllRowsSelected();
1098
1100
  } else if (disabledRow) {
@@ -1122,7 +1124,7 @@ var useDataTable = ({
1122
1124
  ) })
1123
1125
  }
1124
1126
  ],
1125
- [disabledRow]
1127
+ [dataSource]
1126
1128
  );
1127
1129
  const generateColumn = () => {
1128
1130
  if (withSelectedRow) {
@@ -1152,15 +1154,16 @@ var useDataTable = ({
1152
1154
  });
1153
1155
  const { getSelectedRowModel, toggleAllRowsSelected } = table;
1154
1156
  const { flatRows } = getSelectedRowModel();
1155
- React5.useEffect(() => {
1156
- table.setRowSelection(selectedRow != null ? selectedRow : {});
1157
- }, [selectedRow]);
1158
1157
  React5.useEffect(() => {
1159
1158
  const rowData = flatRows.map((row) => row.original);
1160
1159
  if (onSelectedRow) {
1161
- onSelectedRow(rowData);
1160
+ onSelectedRow(rowData, action.current);
1162
1161
  }
1163
1162
  }, [flatRows]);
1163
+ React5.useEffect(() => {
1164
+ action.current = "newData";
1165
+ table.setRowSelection(selectedRow != null ? selectedRow : {});
1166
+ }, [selectedRow]);
1164
1167
  React5.useEffect(() => {
1165
1168
  if (onSort && !isFirstLoad) {
1166
1169
  onSort(sorting);
@@ -1171,12 +1174,13 @@ var useDataTable = ({
1171
1174
  }, []);
1172
1175
  return {
1173
1176
  table,
1177
+ action,
1174
1178
  toggleAllRowsSelected,
1175
1179
  generateColumn
1176
1180
  };
1177
1181
  };
1178
1182
  var DataTable = React5.forwardRef((props, ref) => {
1179
- var _a, _b, _c, _d, _e, _f, _g;
1183
+ var _a, _b, _c, _d, _e;
1180
1184
  const {
1181
1185
  isLoading,
1182
1186
  styles,
@@ -1188,10 +1192,11 @@ var DataTable = React5.forwardRef((props, ref) => {
1188
1192
  highlightedRow,
1189
1193
  withSelectedRow,
1190
1194
  highlightRowColor,
1191
- cellLineClamp = 2
1195
+ cellLineClamp = 2,
1196
+ paddingRowX = 8
1192
1197
  } = props;
1193
1198
  const { clickOrDragged, getDragOrClickProps } = useDragOrClick();
1194
- const { table, toggleAllRowsSelected, generateColumn } = useDataTable(props);
1199
+ const { table, action, toggleAllRowsSelected, generateColumn } = useDataTable(props);
1195
1200
  const refTable = React5.useRef(null);
1196
1201
  React5.useImperativeHandle(ref, () => ({
1197
1202
  toggleAllRowsSelected
@@ -1235,18 +1240,28 @@ var DataTable = React5.forwardRef((props, ref) => {
1235
1240
  };
1236
1241
  }, []);
1237
1242
  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);
1243
+ const getTableHeaderSize = (header, index, totalColumn) => {
1244
+ if (header.column.getIsFirstColumn("left") || header.column.getIsLastColumn("right")) {
1245
+ return { width: `${header.getSize() + paddingRowX}px` };
1246
+ }
1247
+ if (index === 0) {
1248
+ return { width: `${header.getSize() + paddingRowX}px`, paddingLeft: `${8 + paddingRowX}` };
1249
+ }
1250
+ if (index === totalColumn - 1) {
1251
+ return { width: `${header.getSize() + paddingRowX}px`, paddingRight: `${8 + paddingRowX}` };
1252
+ }
1253
+ return { width: `${header.getSize()}px` };
1254
+ };
1238
1255
  return /* @__PURE__ */ jsx24(
1239
1256
  Box11,
1240
1257
  {
1241
1258
  overflowX: "auto",
1242
1259
  overflowY: "hidden",
1243
1260
  position: "relative",
1244
- pl: ((_e = columnPinning == null ? void 0 : columnPinning.left) == null ? void 0 : _e.length) ? 0 : 2,
1245
- pr: ((_f = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _f.length) ? 0 : 2,
1246
1261
  maxW: "100%",
1247
1262
  w: "full",
1248
1263
  ref: refTable,
1249
- ...((_g = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _g.length) && hasScroll ? { "data-pin-right": true } : {},
1264
+ ...((_e = columnPinning == null ? void 0 : columnPinning.right) == null ? void 0 : _e.length) && hasScroll ? { "data-pin-right": true } : {},
1250
1265
  ...container,
1251
1266
  children: isLoading ? /* @__PURE__ */ jsxs8(Table, { ...styles == null ? void 0 : styles.table, "data-loading": "true", children: [
1252
1267
  /* @__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(
@@ -1284,8 +1299,10 @@ var DataTable = React5.forwardRef((props, ref) => {
1284
1299
  Th,
1285
1300
  {
1286
1301
  colSpan: header.colSpan,
1287
- sx: getCommonPinningStyles(header.column),
1288
- width: header.column.getIsFirstColumn("left") || header.column.getIsLastColumn("right") ? `${header.getSize() + 8}px` : `${header.getSize()}px`,
1302
+ _first: { paddingLeft: `${paddingRowX + 8}px` },
1303
+ _last: { paddingRight: `${paddingRowX + 8}px` },
1304
+ sx: getCommonPinningStyles(header.column, paddingRowX),
1305
+ ...getTableHeaderSize(header, index, headerGroup.headers.length),
1289
1306
  ...styles == null ? void 0 : styles.tableColumnHeader,
1290
1307
  children: /* @__PURE__ */ jsxs8(
1291
1308
  Flex2,
@@ -1321,7 +1338,7 @@ var DataTable = React5.forwardRef((props, ref) => {
1321
1338
  }) }, headerGroup.id))
1322
1339
  }
1323
1340
  ),
1324
- /* @__PURE__ */ jsx24(Tbody, { ...styles == null ? void 0 : styles.tableBody, children: table.getRowModel().rows.map((row) => {
1341
+ /* @__PURE__ */ jsx24(Tbody, { ...styles == null ? void 0 : styles.tableBody, children: table.getRowModel().rows.map((row, index) => {
1325
1342
  const isDisabledRow = disabledRow && disabledRow(row.original);
1326
1343
  const isHighlightedRow = highlightedRow && highlightedRow(row.original);
1327
1344
  return /* @__PURE__ */ jsx24(
@@ -1352,6 +1369,7 @@ var DataTable = React5.forwardRef((props, ref) => {
1352
1369
  (_a2 = e.currentTarget) == null ? void 0 : _a2.removeAttribute("data-active");
1353
1370
  },
1354
1371
  onClick: () => {
1372
+ action.current = "selectRow";
1355
1373
  if (withSelectedRow) row.toggleSelected();
1356
1374
  if (onRowClick) {
1357
1375
  if (isDisabledRow) return;
@@ -1369,8 +1387,10 @@ var DataTable = React5.forwardRef((props, ref) => {
1369
1387
  {
1370
1388
  "data-test-id": `CT_Component_TableCell_${cell.id}`,
1371
1389
  fontSize: "text.sm",
1390
+ _first: { paddingLeft: `${paddingRowX + 8}px` },
1391
+ _last: { paddingRight: `${paddingRowX + 8}px` },
1372
1392
  sx: {
1373
- ...getCommonPinningStyles(cell.column)
1393
+ ...getCommonPinningStyles(cell.column, paddingRowX)
1374
1394
  },
1375
1395
  ...styles == null ? void 0 : styles.tableCell,
1376
1396
  children: /* @__PURE__ */ jsx24(
@@ -1382,14 +1402,22 @@ var DataTable = React5.forwardRef((props, ref) => {
1382
1402
  align: "center",
1383
1403
  "data-test-id": `CT_Component_TableCell_Content-${cell.id}`,
1384
1404
  opacity: isDisabled ? 0.5 : 1,
1385
- ...cellLineClamp > 0 ? {
1386
- noOfLines: cellLineClamp,
1387
- sx: {
1388
- display: "-webkit-inline-box"
1389
- }
1390
- } : {},
1391
1405
  sx: { ...meta && meta.columnStyles ? meta.columnStyles : {} },
1392
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
1406
+ children: /* @__PURE__ */ jsx24(
1407
+ Box11,
1408
+ {
1409
+ onMouseUp: (e) => {
1410
+ e.stopPropagation();
1411
+ },
1412
+ ...cellLineClamp > 0 ? {
1413
+ noOfLines: cellLineClamp,
1414
+ sx: {
1415
+ display: "-webkit-inline-box"
1416
+ }
1417
+ } : {},
1418
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
1419
+ }
1420
+ )
1393
1421
  }
1394
1422
  )
1395
1423
  },