ms-react-table 2.0.1 → 2.1.1

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
@@ -17,7 +17,7 @@ var useTable = () => {
17
17
  };
18
18
 
19
19
  // src/components/HeaderActionMenu/HeaderActionMenu.tsx
20
- import { useCallback, useEffect, useState as useState2 } from "react";
20
+ import { useEffect, useState as useState2 } from "react";
21
21
 
22
22
  // src/_assets/icons/index.tsx
23
23
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -55,11 +55,11 @@ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
55
55
  var CheckBox = (props) => {
56
56
  const { id, name, checked, onChange, disabled } = props;
57
57
  return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsxs2("label", { className: "ms-checkbox-wrapper", children: [
58
- /* @__PURE__ */ jsx2("input", { type: "checkbox", className: "ms-promoted-input-checkbox", disabled, checked, onChange: disabled ? () => {
58
+ /* @__PURE__ */ jsx2("input", { id: `ms_checkbox_${id}`, type: "checkbox", className: "ms-promoted-input-checkbox", disabled, checked, onChange: disabled ? () => {
59
59
  } : onChange }),
60
60
  /* @__PURE__ */ jsx2("span", { className: "ms-checkbox-box" }),
61
- /* @__PURE__ */ jsx2("svg", { children: /* @__PURE__ */ jsx2("use", { xlinkHref: `#${id}` }) }),
62
- /* @__PURE__ */ jsx2("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ jsx2("symbol", { id, viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeMiterlimit: "10", fill: "none", d: "M22.9 3.7l-15.2 16.6-6.6-7.1" }) }) })
61
+ /* @__PURE__ */ jsx2("svg", { children: /* @__PURE__ */ jsx2("use", { xlinkHref: `#svg_ms_checkbox_${id}` }) }),
62
+ /* @__PURE__ */ jsx2("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, children: /* @__PURE__ */ jsx2("symbol", { id: `svg_ms_checkbox_${id}`, viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx2("path", { strokeLinecap: "round", strokeMiterlimit: "10", fill: "none", d: "M22.9 3.7l-15.2 16.6-6.6-7.1" }) }) })
63
63
  ] }) });
64
64
  };
65
65
  var CheckBox_default = memo(CheckBox);
@@ -74,12 +74,12 @@ var HeaderActionMenu = (props) => {
74
74
  useEffect(() => {
75
75
  setColumnList(state.colConfigs);
76
76
  onSearchHeader(searchkey);
77
- }, [state.colConfigs]);
78
- const onCheckboxChange = useCallback((dataIndex, e) => {
79
- let newConfig = state.colConfigs.map((item) => {
77
+ }, []);
78
+ const onCheckboxChange = (dataIndex, e) => {
79
+ let newConfig = columnList.map((item) => {
80
80
  return {
81
81
  ...item,
82
- isHidden: item.dataIndex == dataIndex ? !e.target.checked : item.isHidden || false
82
+ isHidden: item.dataIndex == dataIndex ? e.target.checked ? false : true : item.isHidden
83
83
  };
84
84
  });
85
85
  updateState({
@@ -87,7 +87,7 @@ var HeaderActionMenu = (props) => {
87
87
  colConfigs: newConfig
88
88
  });
89
89
  setColumnList(newConfig);
90
- }, []);
90
+ };
91
91
  const onSearchHeader = (value) => {
92
92
  let newlist = [];
93
93
  if (value) {
@@ -362,7 +362,9 @@ var TableProvider = forwardRef((props, ref) => {
362
362
  }
363
363
  setState((prevState) => ({
364
364
  ...prevState,
365
- currentPage: goToPageNo
365
+ currentPage: goToPageNo,
366
+ selectedIndex: [],
367
+ selectedRows: []
366
368
  }));
367
369
  if (!isClientSideRendering) {
368
370
  setRefreshPage(true);
@@ -391,17 +393,6 @@ var TableProvider = forwardRef((props, ref) => {
391
393
  rowData: list
392
394
  }));
393
395
  };
394
- const toggleActionMenu = (dataIndex, showMenu, ref2) => {
395
- const position = ref2.current.getBoundingClientRect();
396
- let left = position.x + position.width;
397
- setMenuPosition({
398
- top: position.height,
399
- right: 0,
400
- left: left > 200 ? left - 200 : position.x
401
- });
402
- setActionMenu(true);
403
- setHeaderCell(dataIndex);
404
- };
405
396
  const onSortColumn = (dataIndex, sortBy) => {
406
397
  let columns2 = state.colConfigs.map((item) => {
407
398
  return {
@@ -453,21 +444,11 @@ var TableProvider = forwardRef((props, ref) => {
453
444
  }
454
445
  };
455
446
  const onColumnReset = () => {
456
- setState({
447
+ setState((prevState) => ({
448
+ ...prevState,
457
449
  prevColConfig: columns,
458
- colConfigs: columns,
459
- rowData: data,
460
- allRowData: data,
461
- currentPage: 1,
462
- pageSize: pageSizeOptions.length > 0 ? pageSizeOptions[0] : 50,
463
- totalRecords: isClientSideRendering ? data.length : props?.totalRecords || 0,
464
- selectedRows: [],
465
- selectedIndex: [],
466
- pageSizeOptions: pageSizeOptions.length > 0 ? pageSizeOptions : [20, 50, 100],
467
- isAutoSizeAllColumns: false,
468
- hideDefaultFilterButton,
469
- filters: {}
470
- });
450
+ colConfigs: columns
451
+ }));
471
452
  setActionMenu(false);
472
453
  };
473
454
  const onFilterApply = (filters) => {
@@ -495,7 +476,6 @@ var TableProvider = forwardRef((props, ref) => {
495
476
  onAutoColumnResize,
496
477
  onPageChange,
497
478
  onPageSizeChange,
498
- toggleActionMenu,
499
479
  onColumnPin,
500
480
  onSortColumn,
501
481
  updateState,
@@ -504,7 +484,7 @@ var TableProvider = forwardRef((props, ref) => {
504
484
  onFilterReset,
505
485
  toggleModalFilter
506
486
  }),
507
- [onRowSelectionChange, onColumnResize, onAutoColumnResize, onPageChange, onPageSizeChange, toggleActionMenu, onColumnPin, onSortColumn, updateState, onColumnReset]
487
+ [onRowSelectionChange, onColumnResize, onAutoColumnResize, onPageChange, onPageSizeChange, onColumnPin, onSortColumn, updateState, onColumnReset]
508
488
  );
509
489
  const contextValue = { state, api, ssrList, totalSSRCount };
510
490
  useEffect2(() => {
@@ -587,9 +567,29 @@ var TableProvider = forwardRef((props, ref) => {
587
567
  },
588
568
  getSelectedRows() {
589
569
  return state.selectedRows;
570
+ },
571
+ reloadServerSideData() {
572
+ setRefreshPage(true);
590
573
  }
591
574
  }), [refreshPage]);
592
- return /* @__PURE__ */ jsx5(MsTableContext_default.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs4("div", { className: `ms-table-wrapper ${props.className} ${state.isAutoSizeAllColumns ? "ms-auto-width" : ""}`, children: [
575
+ const handleClick = (e) => {
576
+ const target = e.target;
577
+ const spanElement = target.closest("span.ms-table-header-action");
578
+ if (!spanElement) return;
579
+ const rect = e.currentTarget.getBoundingClientRect();
580
+ const dataIndex = spanElement.id;
581
+ const parentWidth = rect.width;
582
+ const x = e.clientX - rect.left;
583
+ const popupWidth = actionMenuRef.current ? actionMenuRef.current.offsetWidth : 200;
584
+ setMenuPosition({
585
+ top: 42,
586
+ right: 0,
587
+ left: parentWidth / 2 > x ? x - 20 : x - popupWidth
588
+ });
589
+ setActionMenu(true);
590
+ setHeaderCell(dataIndex);
591
+ };
592
+ return /* @__PURE__ */ jsx5(MsTableContext_default.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs4("div", { className: `ms-table-wrapper ${props.className} ${state.isAutoSizeAllColumns ? "ms-auto-width" : ""}`, onClick: handleClick, children: [
593
593
  children,
594
594
  state.rowData.length == 0 && /* @__PURE__ */ jsx5(Overlay_default, { customComponentForNoRecords }),
595
595
  showActionMenu && /* @__PURE__ */ jsx5(HeaderActionMenu_default, { ref: actionMenuRef, dataIndex: selectedHeaderCell, style: { top: menuPosition.top, left: menuPosition.left } })
@@ -653,7 +653,7 @@ var HeaderCell = (props) => {
653
653
  rest.filters[dataIndex] ? /* @__PURE__ */ jsx6("sup", { children: "*" }) : "",
654
654
  props.sortKey == "asc" ? angleUpIcon : props.sortKey == "desc" ? angleDownIcon : null
655
655
  ] }),
656
- !hideActionMenu && /* @__PURE__ */ jsx6("span", { className: "ms-table-header-action", title: "View Menu", onClick: () => api.toggleActionMenu(dataIndex, true, thRef), children: verticleThreeDotsIcon })
656
+ !hideActionMenu && /* @__PURE__ */ jsx6("span", { className: "ms-table-header-action", title: "View Menu", id: dataIndex, children: verticleThreeDotsIcon })
657
657
  ] }),
658
658
  /* @__PURE__ */ jsx6("div", { className: `ms-table-column-resizer ${resizable ? "" : "disabled"}`, onMouseDown: resizable ? onMouseDown : void 0 })
659
659
  ] })
@@ -801,15 +801,15 @@ var MsTableFooter = (props) => {
801
801
  ] }) }),
802
802
  /* @__PURE__ */ jsx11("div", { className: "record-info", children: /* @__PURE__ */ jsx11("label", { children: `${(currentPage - 1) * pageSize + 1} to ${Math.min(currentPage * pageSize, totalRecords)} of ${totalRecords}` }) }),
803
803
  /* @__PURE__ */ jsxs8("div", { className: "pagination-buttons", children: [
804
- /* @__PURE__ */ jsx11("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Go to First Page", onClick: () => api.onPageChange("first"), children: angleLeftIcon }),
805
- /* @__PURE__ */ jsx11("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Previous Page", onClick: () => api.onPageChange("prev"), children: prevIcon }),
804
+ /* @__PURE__ */ jsx11("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Go to First Page", onClick: () => currentPage == 1 ? {} : api.onPageChange("first"), children: angleLeftIcon }),
805
+ /* @__PURE__ */ jsx11("span", { className: `${currentPage == 1 ? "cursor-disabled" : ""}`, title: "Previous Page", onClick: () => currentPage == 1 ? {} : api.onPageChange("prev"), children: prevIcon }),
806
806
  /* @__PURE__ */ jsxs8("span", { className: "current-page", children: [
807
807
  currentPage,
808
808
  " of ",
809
809
  Math.ceil(totalRecords / pageSize)
810
810
  ] }),
811
- /* @__PURE__ */ jsx11("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Next Page", onClick: () => api.onPageChange("next"), children: nextIcon }),
812
- /* @__PURE__ */ jsx11("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Go to Last Page", onClick: () => api.onPageChange("last"), children: angleRightIcon })
811
+ /* @__PURE__ */ jsx11("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Next Page", onClick: () => currentPage == lastPageNo ? {} : api.onPageChange("next"), children: nextIcon }),
812
+ /* @__PURE__ */ jsx11("span", { className: `${currentPage == lastPageNo ? "cursor-disabled" : ""}`, title: "Go to Last Page", onClick: () => currentPage == lastPageNo ? {} : api.onPageChange("last"), children: angleRightIcon })
813
813
  ] })
814
814
  ] })
815
815
  ] });
@@ -1165,12 +1165,14 @@ var FilterModal = (props) => {
1165
1165
  var FilterModal_default = memo4(FilterModal);
1166
1166
 
1167
1167
  // src/components/Loader.tsx
1168
- import { jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
1169
- var Loader = () => {
1168
+ import { Fragment as Fragment7, jsx as jsx19, jsxs as jsxs14 } from "react/jsx-runtime";
1169
+ var Loader = ({ CustomComponentForLoading }) => {
1170
1170
  return /* @__PURE__ */ jsxs14("div", { className: "ms-loader-wrapper", children: [
1171
1171
  /* @__PURE__ */ jsx19("div", { className: "ms-loader-overlay" }),
1172
- /* @__PURE__ */ jsx19("div", { className: "ms-loader" }),
1173
- /* @__PURE__ */ jsx19("span", { children: "Loading..." })
1172
+ CustomComponentForLoading ? /* @__PURE__ */ jsx19("div", { style: { zIndex: 1 }, children: CustomComponentForLoading }) : /* @__PURE__ */ jsxs14(Fragment7, { children: [
1173
+ /* @__PURE__ */ jsx19("div", { className: "ms-loader" }),
1174
+ /* @__PURE__ */ jsx19("span", { children: "Loading..." })
1175
+ ] })
1174
1176
  ] });
1175
1177
  };
1176
1178
  var Loader_default = Loader;
@@ -1178,7 +1180,7 @@ var Loader_default = Loader;
1178
1180
  // src/MsReactTable.tsx
1179
1181
  import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
1180
1182
  var MsReactTable = (props) => {
1181
- const { showPagination = true, ref, isLoading } = props;
1183
+ const { showPagination = true, ref, isLoading, CustomComponentForLoading = null } = props;
1182
1184
  const containerRef = React12.useRef(null);
1183
1185
  const tbodyRef = React12.useRef(null);
1184
1186
  const theadRef = React12.useRef(null);
@@ -1192,7 +1194,7 @@ var MsReactTable = (props) => {
1192
1194
  /* @__PURE__ */ jsxs15("div", { children: [
1193
1195
  showModalFilter && /* @__PURE__ */ jsx20(FilterModal_default, { isVisible: showModalFilter, toggleFilterModal: toggleModalFilter, containerRef }),
1194
1196
  /* @__PURE__ */ jsx20("div", { className: "ms-overlay", style: showModalFilter ? { width: "100%" } : {} }),
1195
- isLoading && /* @__PURE__ */ jsx20(Loader_default, {})
1197
+ isLoading && /* @__PURE__ */ jsx20(Loader_default, { CustomComponentForLoading })
1196
1198
  ] })
1197
1199
  ] });
1198
1200
  };