pixelize-design-library 2.2.182 → 2.2.183

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.
@@ -16,7 +16,7 @@ var Pagination = function (_a) {
16
16
  // const isRightDisabled = currentPage >= pages - 1;
17
17
  var isLeftDisabled = dataLength === 0 || currentPage === 0;
18
18
  var isRightDisabled = dataLength === 0 || currentPage >= pages - 1;
19
- return (react_1.default.createElement(react_2.Flex, { justify: "flex-end", align: "center", minW: 0, overflow: "hidden", flexWrap: "nowrap" },
19
+ return (react_1.default.createElement(react_2.Flex, { justify: "flex-end", align: "center", flexWrap: "nowrap" },
20
20
  (!isServerPagination || paginationSelectOptions) && (react_1.default.createElement(react_2.Select, { onChange: handlePageSizeChange, value: rowsPerPage, size: "xs", borderRadius: 3, width: 20, isDisabled: dataLength === 0 },
21
21
  !paginationSelectOptions && dataLength < 100 ? react_1.default.createElement("option", { value: 0 }) : null,
22
22
  computedOptions.map(function (size, index) { return (react_1.default.createElement("option", { key: index, value: size }, String(size))); }))),
@@ -45,10 +45,10 @@ var TableActions_1 = __importDefault(require("./TableActions"));
45
45
  var lucide_react_1 = require("lucide-react");
46
46
  var Checkbox_1 = __importDefault(require("../../Checkbox/Checkbox"));
47
47
  var TableBody = function (_a) {
48
- var _b, _c, _d;
48
+ var _b, _c, _d, _e, _f;
49
49
  var data = _a.data, isCheckbox = _a.isCheckbox, columns = _a.columns, startRow = _a.startRow, columnWidths = _a.columnWidths, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, selections = _a.selections, isLoading = _a.isLoading, onRowClick = _a.onRowClick, isContent = _a.isContent, isLink = _a.isLink, isActionFreeze = _a.isActionFreeze, loadingSkeletonRows = _a.loadingSkeletonRows;
50
50
  var theme = (0, useCustomTheme_1.useCustomTheme)();
51
- var _e = (0, react_2.useState)(new Set()), expandedRows = _e[0], setExpandedRows = _e[1];
51
+ var _g = (0, react_2.useState)(new Set()), expandedRows = _g[0], setExpandedRows = _g[1];
52
52
  var toggleRowExpansion = function (rowIndex) {
53
53
  setExpandedRows(function (prev) {
54
54
  var newSet = new Set(prev);
@@ -84,68 +84,73 @@ var TableBody = function (_a) {
84
84
  (isCheckbox ? 1 : 0) +
85
85
  (isContent ? 1 : 0) +
86
86
  (isLink ? 1 : 0);
87
- if (isLoading) {
87
+ if (isLoading && data.length === 0) {
88
88
  return (react_2.default.createElement(TableLoading_1.TableBodyLoading, { noOfColumns: totalVisibleColumns, borderColor: theme.colors.gray[300], rowsCount: typeof loadingSkeletonRows === "number" ? loadingSkeletonRows : 4 }));
89
89
  }
90
- if (data.length === 0) {
90
+ if (!isLoading && data.length === 0) {
91
91
  return (react_2.default.createElement(react_1.Tr, { backgroundColor: (_b = theme.colors.background) === null || _b === void 0 ? void 0 : _b[50] },
92
92
  react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, textAlign: "center", py: 4 },
93
93
  react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14, color: (_d = (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d[500] },
94
94
  react_2.default.createElement("p", null, "No data found")))));
95
95
  }
96
- return (react_2.default.createElement(react_2.default.Fragment, null, data.map(function (row, index) {
97
- var _a;
98
- var rowIndex = startRow + index;
99
- var isExpanded = expandedRows.has(rowIndex);
100
- var isChecked = selections.includes(row.id);
101
- return (react_2.default.createElement(react_2.default.Fragment, { key: rowIndex },
102
- react_2.default.createElement(react_1.Tr, { key: index + 1, sx: isChecked
103
- ? {
104
- "& td": {
105
- backgroundColor: theme.colors.disabled[100],
106
- },
107
- }
108
- : {} },
109
- isContent && (react_2.default.createElement(RenderContent, { rowIndex: rowIndex, isExpanded: isExpanded, isContent: !!((_a = row === null || row === void 0 ? void 0 : row.content) === null || _a === void 0 ? void 0 : _a.call(row)) })),
110
- isCheckbox && react_2.default.createElement(RenderCheckbox, { row: row, isChecked: isChecked }),
111
- columns.map(function (header, headerIndex) {
112
- var _a, _b, _c, _d, _e, _f, _g;
113
- if (header.isHidden)
114
- return null;
115
- var isFrozen = header.isFreeze;
116
- var leftOffset = (0, table_1.TableCellCalculation)({
117
- isFrozen: isFrozen,
118
- columnWidths: columnWidths,
119
- headerIndex: headerIndex,
120
- isCheckbox: isCheckbox,
121
- header: header,
122
- row: row,
123
- freezedBgColor: freezedBgColor,
124
- index: index,
125
- }).leftOffset;
126
- return (react_2.default.createElement(react_1.Td, { maxWidth: 500, minWidth: 120, height: 45, key: headerIndex + 1, onClick: function () {
127
- return !header.node
128
- ? handleRowClick(row, {
129
- label: header.label,
130
- id: header.id,
131
- })
132
- : null;
133
- }, fontSize: 14, fontWeight: 400, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffset : undefined, zIndex: isFrozen ? 1 : 0, backgroundColor: (_a = theme.colors.background) === null || _a === void 0 ? void 0 : _a[50], textOverflow: "ellipsis", borderBottom: noBorders
134
- ? "none"
135
- : "0.063rem solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[isFrozen || isChecked ? 300 : 200]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns"), boxSizing: "border-box", color: (_d = (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d[500], _hover: ((_e = row.cellStyle) === null || _e === void 0 ? void 0 : _e[header.id]) || row.rowStyle
136
- ? {}
137
- : {
138
- backgroundColor: (_g = (_f = theme.colors.secondary) === null || _f === void 0 ? void 0 : _f.opacity) === null || _g === void 0 ? void 0 : _g[4],
139
- } },
140
- react_2.default.createElement(react_1.Box, { display: "block", overflow: "hidden", whiteSpace: "normal", overflowWrap: "break-word" }, (0, table_1.normalizeTableCellValue)(header.node ? header.node(row) : row[header.id]))));
141
- }),
142
- isLink && react_2.default.createElement(RenderView, { row: row })),
143
- row.content && isExpanded && (react_2.default.createElement(react_1.Tr, null,
144
- react_2.default.createElement(react_1.Td, { colSpan: columns.length +
145
- (isCheckbox ? 1 : 0) +
146
- (isContent ? 1 : 0) +
147
- (isLink ? 1 : 0), p: 2 },
148
- react_2.default.createElement(react_1.Box, { p: 2, bg: theme.colors.white, borderRadius: "md" }, row === null || row === void 0 ? void 0 : row.content(row)))))));
149
- })));
96
+ return (react_2.default.createElement(react_2.default.Fragment, null,
97
+ isLoading && data.length > 0 && (react_2.default.createElement(react_1.Tr, null,
98
+ react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, p: 0, border: "none", position: "relative", height: 0 },
99
+ react_2.default.createElement(react_1.Box, { position: "absolute", top: 4, left: "50%", transform: "translateX(-50%)", zIndex: 10 },
100
+ react_2.default.createElement(react_1.Spinner, { size: "sm", color: ((_f = (_e = theme.colors) === null || _e === void 0 ? void 0 : _e.primary) === null || _f === void 0 ? void 0 : _f[500]) || "blue.500" }))))),
101
+ data.map(function (row, index) {
102
+ var rowIndex = startRow + index;
103
+ var isExpanded = expandedRows.has(rowIndex);
104
+ var isChecked = selections.includes(row.id);
105
+ return (react_2.default.createElement(react_2.default.Fragment, { key: rowIndex },
106
+ react_2.default.createElement(react_1.Tr, { key: index + 1, opacity: isLoading ? 0.4 : 1, pointerEvents: isLoading ? "none" : "auto", transition: "opacity 0.2s", sx: isChecked
107
+ ? {
108
+ "& td": {
109
+ backgroundColor: theme.colors.disabled[100],
110
+ },
111
+ }
112
+ : {} },
113
+ isContent && (react_2.default.createElement(RenderContent, { rowIndex: rowIndex, isExpanded: isExpanded, isContent: !!(row === null || row === void 0 ? void 0 : row.content) })),
114
+ isCheckbox && react_2.default.createElement(RenderCheckbox, { row: row, isChecked: isChecked }),
115
+ columns.map(function (header, headerIndex) {
116
+ var _a, _b, _c, _d, _e, _f, _g;
117
+ if (header.isHidden)
118
+ return null;
119
+ var isFrozen = header.isFreeze;
120
+ var leftOffset = (0, table_1.TableCellCalculation)({
121
+ isFrozen: isFrozen,
122
+ columnWidths: columnWidths,
123
+ headerIndex: headerIndex,
124
+ isCheckbox: isCheckbox,
125
+ header: header,
126
+ row: row,
127
+ freezedBgColor: freezedBgColor,
128
+ index: index,
129
+ theme: theme,
130
+ }).leftOffset;
131
+ return (react_2.default.createElement(react_1.Td, { maxWidth: 500, minWidth: 120, height: 45, key: headerIndex + 1, onClick: function () {
132
+ return !header.node
133
+ ? handleRowClick(row, {
134
+ label: header.label,
135
+ id: header.id,
136
+ })
137
+ : null;
138
+ }, fontSize: 14, fontWeight: 400, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffset : undefined, zIndex: isFrozen ? 1 : 0, backgroundColor: (_a = theme.colors.background) === null || _a === void 0 ? void 0 : _a[50], textOverflow: "ellipsis", borderBottom: noBorders
139
+ ? "none"
140
+ : "0.063rem solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[isFrozen || isChecked ? 300 : 200]), className: "columns ".concat(isFrozen ? "sticky-columns" : "scrollable-columns"), boxSizing: "border-box", color: (_d = (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.text) === null || _d === void 0 ? void 0 : _d[500], _hover: ((_e = row.cellStyle) === null || _e === void 0 ? void 0 : _e[header.id]) || row.rowStyle
141
+ ? {}
142
+ : {
143
+ backgroundColor: (_g = (_f = theme.colors.secondary) === null || _f === void 0 ? void 0 : _f.opacity) === null || _g === void 0 ? void 0 : _g[4],
144
+ } },
145
+ react_2.default.createElement(react_1.Box, { display: "block", overflow: "hidden", whiteSpace: "normal", overflowWrap: "break-word" }, (0, table_1.normalizeTableCellValue)(header.node ? header.node(row) : row[header.id]))));
146
+ }),
147
+ isLink && react_2.default.createElement(RenderView, { row: row })),
148
+ row.content && isExpanded && (react_2.default.createElement(react_1.Tr, null,
149
+ react_2.default.createElement(react_1.Td, { colSpan: columns.length +
150
+ (isCheckbox ? 1 : 0) +
151
+ (isContent ? 1 : 0) +
152
+ (isLink ? 1 : 0), p: 2 },
153
+ react_2.default.createElement(react_1.Box, { p: 2, bg: theme.colors.white, borderRadius: "md" }, row === null || row === void 0 ? void 0 : row.content(row)))))));
154
+ })));
150
155
  };
151
156
  exports.default = TableBody;
@@ -41,6 +41,5 @@ declare const useTable: ({ tableBorderColor, data, isPagination, selections, onS
41
41
  setCurrentPage: import("react").Dispatch<import("react").SetStateAction<number>>;
42
42
  columnsList: TableHeaderProps[];
43
43
  handleColumnPreferences: (columns: any) => void;
44
- handleGlobalSearch: (query: string) => void;
45
44
  };
46
45
  export default useTable;
@@ -23,7 +23,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
23
23
  var react_1 = require("react");
24
24
  var useCustomTheme_1 = require("../../../Theme/useCustomTheme");
25
25
  var table_1 = require("../../../Utils/table");
26
- var defaultPageSize = 50;
26
+ var defaultPageSize = 20;
27
27
  var mergeColumnWithPreference = function (pref, originalCol) {
28
28
  if (!pref || typeof pref !== "object") {
29
29
  return __assign({}, originalCol);
@@ -46,16 +46,17 @@ var useTable = function (_a) {
46
46
  var _d = (0, react_1.useState)([]), columnsSort = _d[0], setColumnsSort = _d[1];
47
47
  var _e = (0, react_1.useState)(0), currentPage = _e[0], setCurrentPage = _e[1];
48
48
  var _f = (0, react_1.useState)(noOfRowsPerPage !== null && noOfRowsPerPage !== void 0 ? noOfRowsPerPage : defaultPageSize), rowsPerPage = _f[0], setRowsPerPage = _f[1];
49
- (0, react_1.useEffect)(function () {
50
- if (noOfRowsPerPage !== undefined) {
49
+ var prevRowsPerPageProp = (0, react_1.useRef)(noOfRowsPerPage);
50
+ if (noOfRowsPerPage !== prevRowsPerPageProp.current) {
51
+ prevRowsPerPageProp.current = noOfRowsPerPage;
52
+ if (noOfRowsPerPage !== undefined && noOfRowsPerPage !== rowsPerPage) {
51
53
  setRowsPerPage(noOfRowsPerPage);
52
54
  }
53
- }, [noOfRowsPerPage]);
54
- var tableData = (0, react_1.useMemo)(function () { return data; }, [data]);
55
- var _g = (0, react_1.useState)(tableData), filteredData = _g[0], setFilteredData = _g[1];
56
- var _h = (0, react_1.useState)(function () {
55
+ }
56
+ var tableData = data;
57
+ var _g = (0, react_1.useState)(function () {
57
58
  return columns.map(function (col) { return (__assign({}, col)); });
58
- }), columnsList = _h[0], setColumnsList = _h[1];
59
+ }), columnsList = _g[0], setColumnsList = _g[1];
59
60
  (0, react_1.useEffect)(function () {
60
61
  var _a;
61
62
  var columnPreference = (_a = tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.columns) !== null && _a !== void 0 ? _a : [];
@@ -72,9 +73,6 @@ var useTable = function (_a) {
72
73
  setColumnsList(columns.map(function (col) { return (__assign({}, col)); }));
73
74
  }
74
75
  }, [tablePreferences, columns]);
75
- (0, react_1.useEffect)(function () {
76
- setFilteredData(tableData);
77
- }, [tableData]);
78
76
  var tableContainerStyles = (0, react_1.useMemo)(function () {
79
77
  var _a;
80
78
  return ({
@@ -106,13 +104,12 @@ var useTable = function (_a) {
106
104
  ]);
107
105
  var startRow = (0, react_1.useMemo)(function () { return (!isPagination ? 0 : currentPage * rowsPerPage); }, [currentPage, isPagination, rowsPerPage]);
108
106
  var endRow = (0, react_1.useMemo)(function () { return (!isPagination ? tableData.length : startRow + rowsPerPage); }, [isPagination, rowsPerPage, startRow, tableData.length]);
109
- (0, react_1.useEffect)(function () {
107
+ var filteredData = (0, react_1.useMemo)(function () {
110
108
  if (isServerPagination) {
111
- return setFilteredData(tableData);
109
+ return tableData;
112
110
  }
113
111
  var sortedData = (0, table_1.SortMultiColumnData)(tableData, columnsSort);
114
- var data = sortedData.slice(startRow, endRow);
115
- return setFilteredData(data);
112
+ return sortedData.slice(startRow, endRow);
116
113
  }, [columnsSort, startRow, endRow, tableData, isServerPagination]);
117
114
  var handlePageSizeChange = function (event) {
118
115
  var value = Number(event.target.value);
@@ -166,11 +163,6 @@ var useTable = function (_a) {
166
163
  savePreferences &&
167
164
  savePreferences(__assign(__assign({}, tablePreferences), { columns: columns }));
168
165
  };
169
- var handleGlobalSearch = function (query) {
170
- if (!query)
171
- setFilteredData(tableData);
172
- setFilteredData((0, table_1.globalSearchFilter)(tableData, query));
173
- };
174
166
  return {
175
167
  tableData: tableData,
176
168
  tableContainerStyles: tableContainerStyles,
@@ -192,7 +184,6 @@ var useTable = function (_a) {
192
184
  setCurrentPage: setCurrentPage,
193
185
  columnsList: columnsList,
194
186
  handleColumnPreferences: handleColumnPreferences,
195
- handleGlobalSearch: handleGlobalSearch,
196
187
  };
197
188
  };
198
189
  exports.default = useTable;
@@ -142,7 +142,7 @@ function Table(_a) {
142
142
  onPaginationRef.current(currentPage + 1, rowsPerPage, record, direction);
143
143
  prevPageRef.current = currentPage;
144
144
  }
145
- }, [currentPage, rowsPerPage, pages]);
145
+ }, [currentPage, rowsPerPage]);
146
146
  var tablePaginationText = "".concat(startRow + 1, " - ").concat(endRow > tableData.length ? tableData.length : endRow, " of ").concat(isServerPagination ? totalRecords : tableData.length);
147
147
  var controlsHeight = 45;
148
148
  var estimatedRowHeight = 45;
@@ -223,7 +223,7 @@ function Table(_a) {
223
223
  react_1.default.createElement(HeaderActions_1.default, { actions: headerActions, selections: selection }))) : null,
224
224
  react_1.default.createElement(ActiveFilters_1.default, { columns: columnsList, columnsSearch: columnsSearch, setColumnsSearch: setColumnsSearch }),
225
225
  react_1.default.createElement(react_2.Box, { ml: "auto", display: "flex", alignItems: "center", gap: 2 },
226
- (isPagination || isServerPagination) && !isCompactHeader && (react_1.default.createElement(react_2.Box, { flex: "0 1 280px", minW: 0, overflow: "hidden" },
226
+ (isPagination || isServerPagination) && !isCompactHeader && (react_1.default.createElement(react_2.Box, { flex: "0 0 auto" },
227
227
  react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: tablePaginationText, handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: isServerPagination, paginationSelectOptions: paginationSelectOptions, isVisiblity: true }))),
228
228
  (isPagination || isServerPagination) && isCompactHeader && tableData.length > 0 && (react_1.default.createElement(react_2.Popover, { placement: "bottom-end" },
229
229
  react_1.default.createElement(react_2.PopoverTrigger, null,
@@ -23,8 +23,9 @@ type TableCellCalculationProps = {
23
23
  row: DataObject;
24
24
  freezedBgColor?: string;
25
25
  index: number;
26
+ theme: any;
26
27
  };
27
- export declare const TableCellCalculation: ({ isFrozen, columnWidths, headerIndex, isCheckbox, header, row, freezedBgColor, index, }: TableCellCalculationProps) => {
28
+ export declare const TableCellCalculation: ({ isFrozen, columnWidths, headerIndex, isCheckbox, header, row, freezedBgColor, index, theme, }: TableCellCalculationProps) => {
28
29
  leftOffset: number;
29
30
  cellBgColor: any;
30
31
  rowBgColor: any;
@@ -49,7 +49,6 @@ exports.debounce = debounce;
49
49
  exports.useDebounce = useDebounce;
50
50
  exports.globalSearchFilter = globalSearchFilter;
51
51
  var react_1 = __importStar(require("react"));
52
- var useCustomTheme_1 = require("../Theme/useCustomTheme");
53
52
  function SortMultiColumnData(data, sortConfig) {
54
53
  if (!sortConfig.length)
55
54
  return data;
@@ -210,8 +209,7 @@ var pageSizeCalculation = function (records) {
210
209
  exports.pageSizeCalculation = pageSizeCalculation;
211
210
  var TableCellCalculation = function (_a) {
212
211
  var _b, _c, _d, _e, _f, _g, _h, _j, _k;
213
- var isFrozen = _a.isFrozen, columnWidths = _a.columnWidths, headerIndex = _a.headerIndex, isCheckbox = _a.isCheckbox, header = _a.header, row = _a.row, freezedBgColor = _a.freezedBgColor, index = _a.index;
214
- var theme = (0, useCustomTheme_1.useCustomTheme)();
212
+ var isFrozen = _a.isFrozen, columnWidths = _a.columnWidths, headerIndex = _a.headerIndex, isCheckbox = _a.isCheckbox, header = _a.header, row = _a.row, freezedBgColor = _a.freezedBgColor, index = _a.index, theme = _a.theme;
215
213
  var leftOffset = isFrozen
216
214
  ? (0, exports.calculateLeftOffset)(columnWidths, headerIndex) + (isCheckbox ? 50 : 0)
217
215
  : 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "2.2.182",
3
+ "version": "2.2.183",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",