elseware-ui 2.15.1 → 2.15.2

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.
@@ -9,6 +9,9 @@ export interface AdvancedTableProps<T> {
9
9
  isSuccess?: boolean;
10
10
  isError?: boolean;
11
11
  error?: unknown;
12
+ onPageChange?: (page: number) => void;
13
+ onLimitChange?: (limit: number | "All") => void;
14
+ totalRecords?: number;
12
15
  }
13
- declare function AdvancedTable<T extends Record<string, any>>({ title, columns, data, defaultPageSize, pageSizeOptions, isLoading, isSuccess, isError, error, }: AdvancedTableProps<T>): import("react/jsx-runtime").JSX.Element;
16
+ declare function AdvancedTable<T extends Record<string, any>>({ title, columns, data, defaultPageSize, pageSizeOptions, isLoading, isSuccess, isError, error, totalRecords, onPageChange, onLimitChange, }: AdvancedTableProps<T>): import("react/jsx-runtime").JSX.Element;
14
17
  export default AdvancedTable;
@@ -11,6 +11,9 @@ type AdvancedTableContentProps<T> = {
11
11
  data: T[];
12
12
  defaultPageSize?: number;
13
13
  pageSizeOptions?: (number | "All")[];
14
+ totalRecords?: number;
15
+ onPageChange?: (page: number) => void;
16
+ onLimitChange?: (limit: number | "All") => void;
14
17
  };
15
- export declare function AdvancedTableContent<T extends Record<string, any>>({ title, columns, data, defaultPageSize, pageSizeOptions, }: AdvancedTableContentProps<T>): import("react/jsx-runtime").JSX.Element;
18
+ export declare function AdvancedTableContent<T extends Record<string, any>>({ title, columns, data, defaultPageSize, pageSizeOptions, totalRecords, onPageChange, onLimitChange, }: AdvancedTableContentProps<T>): import("react/jsx-runtime").JSX.Element;
16
19
  export {};
package/build/index.es.js CHANGED
@@ -7853,7 +7853,7 @@ function AsyncComponentWrapper(_a) {
7853
7853
  }
7854
7854
 
7855
7855
  function AdvancedTableContent(_a) {
7856
- var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c;
7856
+ var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, totalRecords = _a.totalRecords, onPageChange = _a.onPageChange, onLimitChange = _a.onLimitChange;
7857
7857
  var _d = useState(""), searchQuery = _d[0], setSearchQuery = _d[1];
7858
7858
  var _e = useState(null), sortKey = _e[0], setSortKey = _e[1];
7859
7859
  var _f = useState("asc"), sortOrder = _f[0], setSortOrder = _f[1];
@@ -7883,18 +7883,23 @@ function AdvancedTableContent(_a) {
7883
7883
  return 0;
7884
7884
  });
7885
7885
  }, [filteredData, sortKey, sortOrder]);
7886
- // Pagination
7887
- var totalPages = rowsPerPage === "All" ? 1 : Math.ceil(sortedData.length / rowsPerPage);
7888
- var paginatedData = rowsPerPage === "All"
7886
+ // BACKEND OR FRONTEND PAGINATION
7887
+ var totalItems = totalRecords !== null && totalRecords !== void 0 ? totalRecords : sortedData.length;
7888
+ var totalPages = rowsPerPage === "All" ? 1 : Math.ceil(totalItems / rowsPerPage);
7889
+ var localPaginatedData = rowsPerPage === "All"
7889
7890
  ? sortedData
7890
7891
  : sortedData.slice(currentPage * rowsPerPage, currentPage * rowsPerPage + rowsPerPage);
7892
+ var finalData = totalRecords ? data : localPaginatedData;
7893
+ // EVENTS
7891
7894
  var handlePageChange = function (page) {
7892
7895
  setCurrentPage(page);
7896
+ onPageChange && onPageChange(page);
7893
7897
  };
7894
7898
  var handlePageSizeChange = function (e) {
7895
7899
  var value = e.target.value === "All" ? "All" : parseInt(e.target.value);
7896
7900
  setRowsPerPage(value);
7897
7901
  setCurrentPage(0);
7902
+ onLimitChange && onLimitChange(value);
7898
7903
  };
7899
7904
  var toggleSort = function (key) {
7900
7905
  if (sortKey === key) {
@@ -7909,12 +7914,12 @@ function AdvancedTableContent(_a) {
7909
7914
  "px-4 py-3 font-semibold text-gray-700 dark:text-gray-300": true,
7910
7915
  "cursor-pointer select-none hover:bg-gray-200 dark:hover:bg-gray-700": col.sortable,
7911
7916
  "bg-gray-300 dark:bg-gray-600": sortKey === col.key,
7912
- }) }, { children: jsxs("div", __assign$1({ className: "flex items-center gap-1" }, { children: [col.header, col.sortable && sortKey === col.key && (jsx("span", __assign$1({ className: "text-xs" }, { children: sortOrder === "asc" ? "▲" : "▼" })))] })) }), i)); }) }) })), jsxs("tbody", __assign$1({ className: "divide-y divide-gray-200 dark:divide-gray-700" }, { children: [paginatedData.map(function (row, rowIndex) { return (jsx("tr", __assign$1({ className: "hover:bg-gray-50 dark:hover:bg-gray-900 odd:eui-bg-sm even:eui-bg-md" }, { children: columns.map(function (col, colIndex) { return (jsx("td", __assign$1({ className: "px-4 py-1 text-gray-800 dark:text-gray-400" }, { children: col.render(row[col.key], row) }), colIndex)); }) }), rowIndex)); }), paginatedData.length === 0 && (jsx("tr", { children: jsx("td", __assign$1({ colSpan: columns.length, className: "px-4 py-4 text-center text-gray-500" }, { children: "No matching data found." })) }))] }))] })) })), jsxs("div", __assign$1({ className: "flex items-center justify-between mt-4" }, { children: [jsx("select", __assign$1({ value: rowsPerPage, onChange: handlePageSizeChange, className: "px-3 py-2 text-sm border border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-400 dark:border-gray-600" }, { children: pageSizeOptions.map(function (opt, idx) { return (jsxs("option", __assign$1({ value: opt }, { children: ["Show ", opt] }), idx)); }) })), rowsPerPage !== "All" && totalPages > 1 && (jsxs("div", __assign$1({ className: "flex justify-between items-center" }, { children: [jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === 0, onClick: function () { return handlePageChange(currentPage - 1); } }, { children: "<" })), jsxs("span", __assign$1({ className: "px-5 text-sm text-gray-700 dark:text-gray-400" }, { children: ["Page ", currentPage + 1, " of ", totalPages] })), jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === totalPages - 1, onClick: function () { return handlePageChange(currentPage + 1); } }, { children: ">" }))] })))] }))] })));
7917
+ }) }, { children: jsxs("div", __assign$1({ className: "flex items-center gap-1" }, { children: [col.header, col.sortable && sortKey === col.key && (jsx("span", __assign$1({ className: "text-xs" }, { children: sortOrder === "asc" ? "▲" : "▼" })))] })) }), i)); }) }) })), jsxs("tbody", __assign$1({ className: "divide-y divide-gray-200 dark:divide-gray-700" }, { children: [finalData.map(function (row, rowIndex) { return (jsx("tr", __assign$1({ className: "hover:bg-gray-50 dark:hover:bg-gray-900 odd:eui-bg-sm even:eui-bg-md" }, { children: columns.map(function (col, colIndex) { return (jsx("td", __assign$1({ className: "px-4 py-1 text-gray-800 dark:text-gray-400" }, { children: col.render(row[col.key], row) }), colIndex)); }) }), rowIndex)); }), finalData.length === 0 && (jsx("tr", { children: jsx("td", __assign$1({ colSpan: columns.length, className: "px-4 py-4 text-center text-gray-500" }, { children: "No matching data found." })) }))] }))] })) })), jsxs("div", __assign$1({ className: "flex items-center justify-between mt-4" }, { children: [jsx("select", __assign$1({ value: rowsPerPage, onChange: handlePageSizeChange, className: "px-3 py-2 text-sm border border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-400 dark:border-gray-600" }, { children: pageSizeOptions.map(function (opt, idx) { return (jsxs("option", __assign$1({ value: opt }, { children: ["Show ", opt] }), idx)); }) })), rowsPerPage !== "All" && totalPages > 1 && (jsxs("div", __assign$1({ className: "flex justify-between items-center" }, { children: [jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === 0, onClick: function () { return handlePageChange(currentPage - 1); } }, { children: "<" })), jsxs("span", __assign$1({ className: "px-5 text-sm text-gray-700 dark:text-gray-400" }, { children: ["Page ", currentPage + 1, " of ", totalPages] })), jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === totalPages - 1, onClick: function () { return handlePageChange(currentPage + 1); } }, { children: ">" }))] })))] }))] })));
7913
7918
  }
7914
7919
 
7915
7920
  function AdvancedTable(_a) {
7916
- var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, isLoading = _a.isLoading, _d = _a.isSuccess, isSuccess = _d === void 0 ? true : _d, isError = _a.isError, error = _a.error;
7917
- return (jsx("div", { children: jsx(AsyncComponentWrapper, __assign$1({ isLoading: isLoading, isSuccess: isSuccess, isError: isError, error: error }, { children: jsx(AdvancedTableContent, { title: title, columns: columns, data: data, defaultPageSize: defaultPageSize, pageSizeOptions: pageSizeOptions }) })) }));
7921
+ var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, isLoading = _a.isLoading, _d = _a.isSuccess, isSuccess = _d === void 0 ? true : _d, isError = _a.isError, error = _a.error, totalRecords = _a.totalRecords, onPageChange = _a.onPageChange, onLimitChange = _a.onLimitChange;
7922
+ return (jsx("div", { children: jsx(AsyncComponentWrapper, __assign$1({ isLoading: isLoading, isSuccess: isSuccess, isError: isError, error: error }, { children: jsx(AdvancedTableContent, { title: title, columns: columns, data: data, defaultPageSize: defaultPageSize, pageSizeOptions: pageSizeOptions, totalRecords: totalRecords, onPageChange: onPageChange, onLimitChange: onLimitChange }) })) }));
7918
7923
  }
7919
7924
 
7920
7925
  var shapes$3 = {
package/build/index.js CHANGED
@@ -7880,7 +7880,7 @@ function AsyncComponentWrapper(_a) {
7880
7880
  }
7881
7881
 
7882
7882
  function AdvancedTableContent(_a) {
7883
- var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c;
7883
+ var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, totalRecords = _a.totalRecords, onPageChange = _a.onPageChange, onLimitChange = _a.onLimitChange;
7884
7884
  var _d = React.useState(""), searchQuery = _d[0], setSearchQuery = _d[1];
7885
7885
  var _e = React.useState(null), sortKey = _e[0], setSortKey = _e[1];
7886
7886
  var _f = React.useState("asc"), sortOrder = _f[0], setSortOrder = _f[1];
@@ -7910,18 +7910,23 @@ function AdvancedTableContent(_a) {
7910
7910
  return 0;
7911
7911
  });
7912
7912
  }, [filteredData, sortKey, sortOrder]);
7913
- // Pagination
7914
- var totalPages = rowsPerPage === "All" ? 1 : Math.ceil(sortedData.length / rowsPerPage);
7915
- var paginatedData = rowsPerPage === "All"
7913
+ // BACKEND OR FRONTEND PAGINATION
7914
+ var totalItems = totalRecords !== null && totalRecords !== void 0 ? totalRecords : sortedData.length;
7915
+ var totalPages = rowsPerPage === "All" ? 1 : Math.ceil(totalItems / rowsPerPage);
7916
+ var localPaginatedData = rowsPerPage === "All"
7916
7917
  ? sortedData
7917
7918
  : sortedData.slice(currentPage * rowsPerPage, currentPage * rowsPerPage + rowsPerPage);
7919
+ var finalData = totalRecords ? data : localPaginatedData;
7920
+ // EVENTS
7918
7921
  var handlePageChange = function (page) {
7919
7922
  setCurrentPage(page);
7923
+ onPageChange && onPageChange(page);
7920
7924
  };
7921
7925
  var handlePageSizeChange = function (e) {
7922
7926
  var value = e.target.value === "All" ? "All" : parseInt(e.target.value);
7923
7927
  setRowsPerPage(value);
7924
7928
  setCurrentPage(0);
7929
+ onLimitChange && onLimitChange(value);
7925
7930
  };
7926
7931
  var toggleSort = function (key) {
7927
7932
  if (sortKey === key) {
@@ -7936,12 +7941,12 @@ function AdvancedTableContent(_a) {
7936
7941
  "px-4 py-3 font-semibold text-gray-700 dark:text-gray-300": true,
7937
7942
  "cursor-pointer select-none hover:bg-gray-200 dark:hover:bg-gray-700": col.sortable,
7938
7943
  "bg-gray-300 dark:bg-gray-600": sortKey === col.key,
7939
- }) }, { children: jsxRuntime.jsxs("div", __assign$1({ className: "flex items-center gap-1" }, { children: [col.header, col.sortable && sortKey === col.key && (jsxRuntime.jsx("span", __assign$1({ className: "text-xs" }, { children: sortOrder === "asc" ? "▲" : "▼" })))] })) }), i)); }) }) })), jsxRuntime.jsxs("tbody", __assign$1({ className: "divide-y divide-gray-200 dark:divide-gray-700" }, { children: [paginatedData.map(function (row, rowIndex) { return (jsxRuntime.jsx("tr", __assign$1({ className: "hover:bg-gray-50 dark:hover:bg-gray-900 odd:eui-bg-sm even:eui-bg-md" }, { children: columns.map(function (col, colIndex) { return (jsxRuntime.jsx("td", __assign$1({ className: "px-4 py-1 text-gray-800 dark:text-gray-400" }, { children: col.render(row[col.key], row) }), colIndex)); }) }), rowIndex)); }), paginatedData.length === 0 && (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", __assign$1({ colSpan: columns.length, className: "px-4 py-4 text-center text-gray-500" }, { children: "No matching data found." })) }))] }))] })) })), jsxRuntime.jsxs("div", __assign$1({ className: "flex items-center justify-between mt-4" }, { children: [jsxRuntime.jsx("select", __assign$1({ value: rowsPerPage, onChange: handlePageSizeChange, className: "px-3 py-2 text-sm border border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-400 dark:border-gray-600" }, { children: pageSizeOptions.map(function (opt, idx) { return (jsxRuntime.jsxs("option", __assign$1({ value: opt }, { children: ["Show ", opt] }), idx)); }) })), rowsPerPage !== "All" && totalPages > 1 && (jsxRuntime.jsxs("div", __assign$1({ className: "flex justify-between items-center" }, { children: [jsxRuntime.jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === 0, onClick: function () { return handlePageChange(currentPage - 1); } }, { children: "<" })), jsxRuntime.jsxs("span", __assign$1({ className: "px-5 text-sm text-gray-700 dark:text-gray-400" }, { children: ["Page ", currentPage + 1, " of ", totalPages] })), jsxRuntime.jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === totalPages - 1, onClick: function () { return handlePageChange(currentPage + 1); } }, { children: ">" }))] })))] }))] })));
7944
+ }) }, { children: jsxRuntime.jsxs("div", __assign$1({ className: "flex items-center gap-1" }, { children: [col.header, col.sortable && sortKey === col.key && (jsxRuntime.jsx("span", __assign$1({ className: "text-xs" }, { children: sortOrder === "asc" ? "▲" : "▼" })))] })) }), i)); }) }) })), jsxRuntime.jsxs("tbody", __assign$1({ className: "divide-y divide-gray-200 dark:divide-gray-700" }, { children: [finalData.map(function (row, rowIndex) { return (jsxRuntime.jsx("tr", __assign$1({ className: "hover:bg-gray-50 dark:hover:bg-gray-900 odd:eui-bg-sm even:eui-bg-md" }, { children: columns.map(function (col, colIndex) { return (jsxRuntime.jsx("td", __assign$1({ className: "px-4 py-1 text-gray-800 dark:text-gray-400" }, { children: col.render(row[col.key], row) }), colIndex)); }) }), rowIndex)); }), finalData.length === 0 && (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", __assign$1({ colSpan: columns.length, className: "px-4 py-4 text-center text-gray-500" }, { children: "No matching data found." })) }))] }))] })) })), jsxRuntime.jsxs("div", __assign$1({ className: "flex items-center justify-between mt-4" }, { children: [jsxRuntime.jsx("select", __assign$1({ value: rowsPerPage, onChange: handlePageSizeChange, className: "px-3 py-2 text-sm border border-gray-300 rounded-md dark:bg-gray-900 dark:text-gray-400 dark:border-gray-600" }, { children: pageSizeOptions.map(function (opt, idx) { return (jsxRuntime.jsxs("option", __assign$1({ value: opt }, { children: ["Show ", opt] }), idx)); }) })), rowsPerPage !== "All" && totalPages > 1 && (jsxRuntime.jsxs("div", __assign$1({ className: "flex justify-between items-center" }, { children: [jsxRuntime.jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === 0, onClick: function () { return handlePageChange(currentPage - 1); } }, { children: "<" })), jsxRuntime.jsxs("span", __assign$1({ className: "px-5 text-sm text-gray-700 dark:text-gray-400" }, { children: ["Page ", currentPage + 1, " of ", totalPages] })), jsxRuntime.jsx("button", __assign$1({ className: "px-3 py-1 rounded-full text-sm bg-gray-200 dark:bg-gray-700 disabled:opacity-40", disabled: currentPage === totalPages - 1, onClick: function () { return handlePageChange(currentPage + 1); } }, { children: ">" }))] })))] }))] })));
7940
7945
  }
7941
7946
 
7942
7947
  function AdvancedTable(_a) {
7943
- var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, isLoading = _a.isLoading, _d = _a.isSuccess, isSuccess = _d === void 0 ? true : _d, isError = _a.isError, error = _a.error;
7944
- return (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(AsyncComponentWrapper, __assign$1({ isLoading: isLoading, isSuccess: isSuccess, isError: isError, error: error }, { children: jsxRuntime.jsx(AdvancedTableContent, { title: title, columns: columns, data: data, defaultPageSize: defaultPageSize, pageSizeOptions: pageSizeOptions }) })) }));
7948
+ var title = _a.title, columns = _a.columns, data = _a.data, _b = _a.defaultPageSize, defaultPageSize = _b === void 0 ? 5 : _b, _c = _a.pageSizeOptions, pageSizeOptions = _c === void 0 ? [5, 10, 100, "All"] : _c, isLoading = _a.isLoading, _d = _a.isSuccess, isSuccess = _d === void 0 ? true : _d, isError = _a.isError, error = _a.error, totalRecords = _a.totalRecords, onPageChange = _a.onPageChange, onLimitChange = _a.onLimitChange;
7949
+ return (jsxRuntime.jsx("div", { children: jsxRuntime.jsx(AsyncComponentWrapper, __assign$1({ isLoading: isLoading, isSuccess: isSuccess, isError: isError, error: error }, { children: jsxRuntime.jsx(AdvancedTableContent, { title: title, columns: columns, data: data, defaultPageSize: defaultPageSize, pageSizeOptions: pageSizeOptions, totalRecords: totalRecords, onPageChange: onPageChange, onLimitChange: onLimitChange }) })) }));
7945
7950
  }
7946
7951
 
7947
7952
  var shapes$3 = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elseware-ui",
3
- "version": "2.15.1",
3
+ "version": "2.15.2",
4
4
  "private": false,
5
5
  "description": "A modern and customizable React UI component library by elseware Technology.",
6
6
  "keywords": [