pixelize-design-library 2.2.108 → 2.2.110

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.
@@ -1,3 +1,3 @@
1
1
  import React from "react";
2
2
  import { TableProps } from "./TableProps";
3
- export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, preferences, paginationMode, noOfRowsPerPage, totalRecords, onPagination, isTableSettings, headerActions, onGlobalSearch, onNoOfRowsPerPageChange, paginationSelectOptions, tableMaxHeight, tableSettings, filterSidebar }: TableProps): React.JSX.Element;
3
+ export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, preferences, paginationMode, noOfRowsPerPage, totalRecords, onPagination, isTableSettings, headerActions, onGlobalSearch, onNoOfRowsPerPageChange, paginationSelectOptions, tableMaxHeight, minVisibleRows, maxVisibleRows, autoFitViewport, tableSettings, filterSidebar }: TableProps): React.JSX.Element;
@@ -54,20 +54,22 @@ function Table(_a) {
54
54
  name: "",
55
55
  page: "",
56
56
  orgId: "",
57
- } : _u, _v = _a.paginationMode, paginationMode = _v === void 0 ? "client" : _v, _w = _a.noOfRowsPerPage, noOfRowsPerPage = _w === void 0 ? 50 : _w, _x = _a.totalRecords, totalRecords = _x === void 0 ? 0 : _x, onPagination = _a.onPagination, _y = _a.isTableSettings, isTableSettings = _y === void 0 ? false : _y, headerActions = _a.headerActions, onGlobalSearch = _a.onGlobalSearch, onNoOfRowsPerPageChange = _a.onNoOfRowsPerPageChange, paginationSelectOptions = _a.paginationSelectOptions, tableMaxHeight = _a.tableMaxHeight, tableSettings = _a.tableSettings, filterSidebar = _a.filterSidebar
57
+ } : _u, _v = _a.paginationMode, paginationMode = _v === void 0 ? "client" : _v, _w = _a.noOfRowsPerPage, noOfRowsPerPage = _w === void 0 ? 50 : _w, _x = _a.totalRecords, totalRecords = _x === void 0 ? 0 : _x, onPagination = _a.onPagination, _y = _a.isTableSettings, isTableSettings = _y === void 0 ? false : _y, headerActions = _a.headerActions, onGlobalSearch = _a.onGlobalSearch, onNoOfRowsPerPageChange = _a.onNoOfRowsPerPageChange, paginationSelectOptions = _a.paginationSelectOptions, tableMaxHeight = _a.tableMaxHeight, minVisibleRows = _a.minVisibleRows, maxVisibleRows = _a.maxVisibleRows, autoFitViewport = _a.autoFitViewport, tableSettings = _a.tableSettings, filterSidebar = _a.filterSidebar
58
58
  // onColumnFilter
59
59
  ;
60
60
  var theme = (0, useCustomTheme_1.useCustomTheme)();
61
61
  var _z = (0, react_1.useState)({}), columnsSearch = _z[0], setColumnsSearch = _z[1];
62
+ var tableContainerRef = (0, react_1.useRef)(null);
63
+ var _0 = (0, react_1.useState)(500), viewportAvailableH = _0[0], setViewportAvailableH = _0[1];
62
64
  var isServerPagination = paginationMode === "server";
63
- var _0 = (0, usePreferences_1.useGetPreferences)({
65
+ var _1 = (0, usePreferences_1.useGetPreferences)({
64
66
  baseUrl: preferences.url,
65
67
  page: preferences.page,
66
68
  key: preferences.key,
67
69
  name: preferences.name,
68
70
  authToken: preferences.token,
69
71
  orgId: preferences.orgId,
70
- }), tablePreferencesData = _0.preferences, loading = _0.loading;
72
+ }), tablePreferencesData = _1.preferences, loading = _1.loading;
71
73
  var savePreferences = (0, usePreferences_1.useSavePreferences)({
72
74
  baseUrl: preferences.url,
73
75
  page: preferences.page,
@@ -85,7 +87,7 @@ function Table(_a) {
85
87
  }
86
88
  return {};
87
89
  }, [tablePreferencesData]);
88
- var _1 = (0, useTable_1.default)({
90
+ var _2 = (0, useTable_1.default)({
89
91
  tableBorderColor: tableBorderColor,
90
92
  data: data,
91
93
  isPagination: isPagination,
@@ -98,7 +100,7 @@ function Table(_a) {
98
100
  totalRecords: totalRecords,
99
101
  isServerPagination: isServerPagination,
100
102
  onNoOfRowsPerPageChange: onNoOfRowsPerPageChange,
101
- }), tableData = _1.tableData, isContent = _1.isContent, isLink = _1.isLink, headerRefs = _1.headerRefs, columnWidths = _1.columnWidths, handleSort = _1.handleSort, handleCheckbox = _1.handleCheckbox, filteredData = _1.filteredData, startRow = _1.startRow, endRow = _1.endRow, selection = _1.selection, columnsSort = _1.columnsSort, currentPage = _1.currentPage, pages = _1.pages, rowsPerPage = _1.rowsPerPage, handlePageSizeChange = _1.handlePageSizeChange, setCurrentPage = _1.setCurrentPage, columnsList = _1.columnsList, handleColumnPreferences = _1.handleColumnPreferences;
103
+ }), tableData = _2.tableData, isContent = _2.isContent, isLink = _2.isLink, headerRefs = _2.headerRefs, columnWidths = _2.columnWidths, handleSort = _2.handleSort, handleCheckbox = _2.handleCheckbox, filteredData = _2.filteredData, startRow = _2.startRow, endRow = _2.endRow, selection = _2.selection, columnsSort = _2.columnsSort, currentPage = _2.currentPage, pages = _2.pages, rowsPerPage = _2.rowsPerPage, handlePageSizeChange = _2.handlePageSizeChange, setCurrentPage = _2.setCurrentPage, columnsList = _2.columnsList, handleColumnPreferences = _2.handleColumnPreferences;
102
104
  var _filteredData = (0, react_1.useMemo)(function () {
103
105
  return (0, table_1.searchAndSortData)(filteredData, columnsSearch);
104
106
  }, [columnsSearch, filteredData]);
@@ -110,9 +112,28 @@ function Table(_a) {
110
112
  var tablePaginationText = "".concat(startRow + 1, " - ").concat(endRow > tableData.length ? tableData.length : endRow, " of ").concat(isServerPagination ? totalRecords : tableData.length);
111
113
  var controlsHeight = 45;
112
114
  var estimatedRowHeight = 45;
113
- var visibleRowsCount = isServerPagination ? (noOfRowsPerPage !== null && noOfRowsPerPage !== void 0 ? noOfRowsPerPage : 0) : _filteredData.length;
114
- var dynamicMaxH = Math.min(500, (visibleRowsCount * estimatedRowHeight) + estimatedRowHeight);
115
- var tableMaxH = typeof tableMaxHeight === "number" ? tableMaxHeight : dynamicMaxH;
115
+ var actualRows = _filteredData.length;
116
+ var minRows = typeof minVisibleRows === "number" ? Math.max(0, minVisibleRows) : 5;
117
+ var maxRows = typeof maxVisibleRows === "number" ? Math.max(minRows, maxVisibleRows) : 10;
118
+ var visibleRowsCount = Math.max(minRows, Math.min(actualRows, maxRows));
119
+ (0, react_1.useEffect)(function () {
120
+ if (!autoFitViewport)
121
+ return;
122
+ var compute = function () {
123
+ if (tableContainerRef.current) {
124
+ var rect = tableContainerRef.current.getBoundingClientRect();
125
+ var available = Math.max(200, window.innerHeight - rect.top - 16);
126
+ setViewportAvailableH(available);
127
+ }
128
+ };
129
+ compute();
130
+ window.addEventListener("resize", compute);
131
+ return function () { return window.removeEventListener("resize", compute); };
132
+ }, [autoFitViewport]);
133
+ var rowsHeight = (visibleRowsCount * estimatedRowHeight) + estimatedRowHeight;
134
+ var dynamicMaxH = Math.min(500, rowsHeight);
135
+ var fittedMaxH = autoFitViewport ? Math.min(dynamicMaxH, viewportAvailableH) : dynamicMaxH;
136
+ var tableMaxH = typeof tableMaxHeight === "number" ? tableMaxHeight : fittedMaxH;
116
137
  return (react_1.default.createElement(react_2.Box, { bg: (_c = (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.background) === null || _c === void 0 ? void 0 : _c[50], border: "0.063rem solid ".concat((_d = theme.colors.border) === null || _d === void 0 ? void 0 : _d[500]), borderRadius: 3 },
117
138
  react_1.default.createElement(react_2.Flex, { align: "start" },
118
139
  react_1.default.createElement(MotionBox, { initial: { width: 0 }, animate: { width: (filterSidebar === null || filterSidebar === void 0 ? void 0 : filterSidebar.isFilterSidebar) ? 180 : 0 }, transition: { type: "tween", duration: 0.25 }, overflow: "hidden", flexShrink: 0, borderRight: "1px solid", borderColor: (_e = theme.colors.border) === null || _e === void 0 ? void 0 : _e[500], style: { height: controlsHeight + tableMaxH } },
@@ -132,7 +153,7 @@ function Table(_a) {
132
153
  react_1.default.createElement(ActiveFilters_1.default, { columns: columnsList, columnsSearch: columnsSearch, setColumnsSearch: setColumnsSearch }),
133
154
  (isPagination || isServerPagination) && (react_1.default.createElement(react_2.Box, { ml: "auto", minW: 310 },
134
155
  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, pageSizeOptions: paginationSelectOptions, isVisiblity: true })))),
135
- react_1.default.createElement(react_2.TableContainer, { position: "relative", maxH: tableMaxH, overflowY: "auto", overflowX: "auto", sx: {
156
+ react_1.default.createElement(react_2.TableContainer, { ref: tableContainerRef, position: "relative", maxH: tableMaxH, overflowY: "auto", overflowX: "auto", sx: {
136
157
  '&::-webkit-scrollbar': {
137
158
  width: '6px',
138
159
  height: '6px',
@@ -27,6 +27,9 @@ export type TableProps = {
27
27
  onNoOfRowsPerPageChange?: (noOfRows: number) => void;
28
28
  paginationSelectOptions?: (number | string)[];
29
29
  tableMaxHeight?: number;
30
+ minVisibleRows?: number;
31
+ maxVisibleRows?: number;
32
+ autoFitViewport?: boolean;
30
33
  headerActions?: HeaderActionsProps;
31
34
  onGlobalSearch?: (searchVal: string) => void;
32
35
  onColumnFilter?: (filters: Record<string, any>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "2.2.108",
3
+ "version": "2.2.110",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",