pixelize-design-library 1.1.55 → 1.1.57

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.
@@ -29,4 +29,5 @@ export type ButtonGroupIconProps = {
29
29
  menulistStyle?: React.CSSProperties;
30
30
  menuItemStyle?: React.CSSProperties;
31
31
  isLoading?: boolean;
32
+ divider?: boolean;
32
33
  };
@@ -2,4 +2,4 @@ import React from "react";
2
2
  import { ButtonGroupIconProps } from "./ButtonGoupIconProps";
3
3
  export default function ButtonGroupIcon({ leftIcon, rightIcon, onLeftIconClick, onRightIconClick, buttonText, onButtonClick, onButtongroupClick, size, variant, color, buttonGroupStyle, buttonGroupLeftIconStyle, buttonGroupRightIconStyle, buttonStyle, onBlurLeftIcon, onBlurRightIcon, dropdownOptions, // New prop for dropdown options
4
4
  onDropdownOptionClick, // New prop to handle option clicks
5
- rightIconDropdown, menulistStyle, menuItemStyle, isLoading, }: ButtonGroupIconProps): React.JSX.Element;
5
+ rightIconDropdown, menulistStyle, menuItemStyle, isLoading, divider, }: ButtonGroupIconProps): React.JSX.Element;
@@ -27,11 +27,12 @@ var react_1 = __importStar(require("react"));
27
27
  var react_2 = require("@chakra-ui/react");
28
28
  var useCustomTheme_1 = require("../../Theme/useCustomTheme");
29
29
  function ButtonGroupIcon(_a) {
30
+ var _b, _c;
30
31
  var leftIcon = _a.leftIcon, rightIcon = _a.rightIcon, onLeftIconClick = _a.onLeftIconClick, onRightIconClick = _a.onRightIconClick, buttonText = _a.buttonText, onButtonClick = _a.onButtonClick, onButtongroupClick = _a.onButtongroupClick, size = _a.size, variant = _a.variant, color = _a.color, buttonGroupStyle = _a.buttonGroupStyle, buttonGroupLeftIconStyle = _a.buttonGroupLeftIconStyle, buttonGroupRightIconStyle = _a.buttonGroupRightIconStyle, buttonStyle = _a.buttonStyle, onBlurLeftIcon = _a.onBlurLeftIcon, onBlurRightIcon = _a.onBlurRightIcon, dropdownOptions = _a.dropdownOptions, // New prop for dropdown options
31
32
  onDropdownOptionClick = _a.onDropdownOptionClick, // New prop to handle option clicks
32
- rightIconDropdown = _a.rightIconDropdown, menulistStyle = _a.menulistStyle, menuItemStyle = _a.menuItemStyle, isLoading = _a.isLoading;
33
+ rightIconDropdown = _a.rightIconDropdown, menulistStyle = _a.menulistStyle, menuItemStyle = _a.menuItemStyle, isLoading = _a.isLoading, _d = _a.divider, divider = _d === void 0 ? true : _d;
33
34
  var theme = (0, useCustomTheme_1.useCustomTheme)();
34
- var _b = (0, react_1.useState)(false), isDropdownOpen = _b[0], setIsDropdownOpen = _b[1];
35
+ var _e = (0, react_1.useState)(false), isDropdownOpen = _e[0], setIsDropdownOpen = _e[1];
35
36
  var handleRightIconClick = function () {
36
37
  setIsDropdownOpen(!isDropdownOpen);
37
38
  if (onRightIconClick) {
@@ -57,7 +58,7 @@ function ButtonGroupIcon(_a) {
57
58
  "&:hover": {
58
59
  backgroundColor: theme.colors.primary[400],
59
60
  },
60
- } }, buttonText),
61
+ }, borderLeft: "1px solid ".concat((_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[300]), borderRight: "1px solid ".concat((_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[300]) }, buttonText),
61
62
  rightIcon && rightIconDropdown ? (react_1.default.createElement(react_2.Menu, { isOpen: isDropdownOpen, onClose: function () { return setIsDropdownOpen(false); } },
62
63
  react_1.default.createElement(react_2.MenuButton, { as: react_2.IconButton, "aria-label": "Right icon button", icon: rightIcon, onClick: handleRightIconClick, onBlur: onBlurRightIcon, style: buttonGroupRightIconStyle, sx: {
63
64
  backgroundColor: theme.colors.primary[500],
@@ -66,9 +67,16 @@ function ButtonGroupIcon(_a) {
66
67
  },
67
68
  } }),
68
69
  react_1.default.createElement(react_2.Box, { sx: { zIndex: 99 } },
69
- react_1.default.createElement(react_2.MenuList, { style: menulistStyle }, dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map(function (option, index) { return (react_1.default.createElement(react_2.MenuItem, { key: index, onClick: function (event) { return handleMenuClick(event, option); }, style: menuItemStyle }, option === null || option === void 0 ? void 0 :
70
- option.image,
71
- option.label)); }))))) : (rightIcon && (react_1.default.createElement(react_2.IconButton, { "aria-label": "Right icon button", icon: rightIcon, onClick: onRightIconClick, onBlur: onBlurRightIcon, style: buttonGroupRightIconStyle, sx: {
70
+ react_1.default.createElement(react_2.MenuList, { style: menulistStyle }, dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.map(function (option, index) {
71
+ var _a;
72
+ return (react_1.default.createElement(react_2.MenuItem, { key: index, onClick: function (event) { return handleMenuClick(event, option); }, style: menuItemStyle, borderBottom: divider ? "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]) : undefined, sx: {
73
+ "&:last-child": {
74
+ borderBottom: "none",
75
+ },
76
+ } }, option === null || option === void 0 ? void 0 :
77
+ option.image,
78
+ option.label));
79
+ }))))) : (rightIcon && (react_1.default.createElement(react_2.IconButton, { "aria-label": "Right icon button", icon: rightIcon, onClick: onRightIconClick, onBlur: onBlurRightIcon, style: buttonGroupRightIconStyle, sx: {
72
80
  backgroundColor: theme.colors.primary[500],
73
81
  "&:hover": {
74
82
  backgroundColor: theme.colors.primary[400],
@@ -10,6 +10,7 @@ type PaginationProps = Pick<TableProps, "isVisiblity" | "columns"> & {
10
10
  handleColumnVisibilityChange: (header: string | number) => void;
11
11
  setCurrentPage: React.Dispatch<React.SetStateAction<number>>;
12
12
  dataLength: number;
13
+ isServerPagination: boolean;
13
14
  };
14
- declare const Pagination: ({ isVisiblity, columns, visibleColumns, paginationText, handlePageSizeChange, rowsPerPage, currentPage, pages, handleColumnVisibilityChange, setCurrentPage, dataLength, }: PaginationProps) => React.JSX.Element;
15
+ declare const Pagination: ({ isVisiblity, columns, visibleColumns, paginationText, handlePageSizeChange, rowsPerPage, currentPage, pages, handleColumnVisibilityChange, setCurrentPage, dataLength, isServerPagination, }: PaginationProps) => React.JSX.Element;
15
16
  export default Pagination;
@@ -8,7 +8,7 @@ var icons_1 = require("@chakra-ui/icons");
8
8
  var react_2 = require("@chakra-ui/react");
9
9
  var fa_1 = require("react-icons/fa");
10
10
  var Pagination = function (_a) {
11
- var isVisiblity = _a.isVisiblity, columns = _a.columns, visibleColumns = _a.visibleColumns, paginationText = _a.paginationText, handlePageSizeChange = _a.handlePageSizeChange, rowsPerPage = _a.rowsPerPage, currentPage = _a.currentPage, pages = _a.pages, handleColumnVisibilityChange = _a.handleColumnVisibilityChange, setCurrentPage = _a.setCurrentPage, dataLength = _a.dataLength;
11
+ var isVisiblity = _a.isVisiblity, columns = _a.columns, visibleColumns = _a.visibleColumns, paginationText = _a.paginationText, handlePageSizeChange = _a.handlePageSizeChange, rowsPerPage = _a.rowsPerPage, currentPage = _a.currentPage, pages = _a.pages, handleColumnVisibilityChange = _a.handleColumnVisibilityChange, setCurrentPage = _a.setCurrentPage, dataLength = _a.dataLength, isServerPagination = _a.isServerPagination;
12
12
  var pageSizeOptions = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50, 75, 100].filter(function (size) { return size <= dataLength; });
13
13
  var isLeftDisabled = currentPage === 0;
14
14
  var isRightDisabled = currentPage >= pages - 1;
@@ -19,9 +19,9 @@ var Pagination = function (_a) {
19
19
  react_1.default.createElement(react_2.MenuList, { overflow: "scroll", zIndex: "2" }, columns.map(function (header, index) { return (react_1.default.createElement(react_2.MenuItem, { key: index },
20
20
  react_1.default.createElement(react_2.Checkbox, { isChecked: visibleColumns[header.label], size: "sm", onChange: function () { return handleColumnVisibilityChange(header.label); } }, header.label))); }))))),
21
21
  react_1.default.createElement(react_2.Text, { mr: 4, fontSize: 12 }, paginationText),
22
- react_1.default.createElement(react_2.Select, { onChange: handlePageSizeChange, value: rowsPerPage, mr: 4, size: "xs", width: 20 },
22
+ !isServerPagination && (react_1.default.createElement(react_2.Select, { onChange: handlePageSizeChange, value: rowsPerPage, mr: 4, size: "xs", width: 20 },
23
23
  react_1.default.createElement("option", { value: 0 }),
24
- pageSizeOptions.map(function (size, index) { return (react_1.default.createElement("option", { key: index, value: size }, size)); })),
24
+ pageSizeOptions.map(function (size, index) { return (react_1.default.createElement("option", { key: index, value: size }, size)); }))),
25
25
  react_1.default.createElement(react_2.Flex, null,
26
26
  react_1.default.createElement(react_2.IconButton, { mx: 1, "aria-label": "left-icon", color: isLeftDisabled ? "gray" : "black", rounded: "full", variant: isLeftDisabled ? "plain" : "ghost", onClick: function () { return setCurrentPage(0); } },
27
27
  react_1.default.createElement(fa_1.FaAngleDoubleLeft, null)),
@@ -77,7 +77,9 @@ var TableBody = function (_a) {
77
77
  }, [freezedBgColor, freezedTextColor, noBorders, theme.colors, isActionFreeze]);
78
78
  if (isLoading) {
79
79
  var totalVisibleColumns = Object.values(visibleColumns).filter(Boolean).length +
80
- (isCheckbox ? 1 : 0);
80
+ (isCheckbox ? 1 : 0) +
81
+ (isContent ? 1 : 0) +
82
+ (isLink ? 1 : 0);
81
83
  return (react_2.default.createElement(TableLoading_1.TableBodyLoading, { noOfColumns: totalVisibleColumns, borderColor: theme.colors.gray[300] }));
82
84
  }
83
85
  if (data.length === 0) {
@@ -90,7 +92,7 @@ var TableBody = function (_a) {
90
92
  react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14 },
91
93
  react_2.default.createElement("p", null, "No data found")))));
92
94
  }
93
- return (react_2.default.createElement(react_2.default.Fragment, null, data.slice(startRow, endRow).map(function (row, index) {
95
+ return (react_2.default.createElement(react_2.default.Fragment, null, data.map(function (row, index) {
94
96
  var rowIndex = startRow + index;
95
97
  var isExpanded = expandedRows.has(rowIndex);
96
98
  var isChecked = selections.includes(row.id);
@@ -27,12 +27,12 @@ var react_1 = __importStar(require("react"));
27
27
  var icons_1 = require("@chakra-ui/icons");
28
28
  var react_2 = require("@chakra-ui/react");
29
29
  var fa_1 = require("react-icons/fa");
30
- var functions_1 = require("../Utils/functions");
30
+ var table_1 = require("../../../Utils/table");
31
31
  var TableFilters = (0, react_1.memo)(function (_a) {
32
32
  var header = _a.header, setColumnsSearch = _a.setColumnsSearch, columnsSearch = _a.columnsSearch, onClose = _a.onClose;
33
33
  var searchRef = (0, react_1.useRef)(null);
34
34
  var _b = (0, react_1.useState)(false), refreshDataOnOpen = _b[0], setRefreshDataOnOpen = _b[1];
35
- var debounceRef = (0, functions_1.debounce)(function (value) {
35
+ var debounceRef = (0, table_1.debounce)(function (value) {
36
36
  setColumnsSearch(value);
37
37
  }, 700);
38
38
  (0, react_1.useEffect)(function () {
@@ -71,7 +71,7 @@ var TableHeader = function (_a) {
71
71
  var RenderView = (0, react_2.useCallback)(function () {
72
72
  var _a;
73
73
  var BgColor = isActionFreeze ? freezedBgColor : headerBgColor;
74
- return (react_2.default.createElement(react_1.Th, { w: 2, p: 0, backgroundColor: BgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: isActionFreeze ? "sticky" : "relative", className: "columns sticky-columns", right: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
74
+ return (react_2.default.createElement(react_1.Th, { w: 2, p: 0, minW: "2.065rem", backgroundColor: BgColor, border: noBorders ? "none" : "1px solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.gray[300]), position: isActionFreeze ? "sticky" : "relative", className: "columns sticky-columns", right: "0px", zIndex: 1, boxShadow: "2px 0 5px rgba(0, 0, 0, 0.1)" },
75
75
  react_2.default.createElement(react_1.Box, { display: "flex", justifyContent: "center" },
76
76
  react_2.default.createElement(lu_1.LuFileSymlink, { fontSize: 16 }))));
77
77
  }, [
@@ -7,8 +7,11 @@ type UseTableProps = {
7
7
  selections?: (string | number)[];
8
8
  columns: TableHeaderProps[];
9
9
  onSelection?: (selected: (string | number)[]) => void;
10
+ tablePreferences?: Record<string, any>;
11
+ savePreferences?: (data: Record<string, any>) => void;
12
+ noOfRowsPerPage?: number;
10
13
  };
11
- declare const useTable: ({ tableBorderColor, data, isPagination, selections, columns, onSelection, }: UseTableProps) => {
14
+ declare const useTable: ({ tableBorderColor, data, isPagination, selections, columns, onSelection, tablePreferences, savePreferences, noOfRowsPerPage, }: UseTableProps) => {
12
15
  tableData: DataObject[];
13
16
  tableContainerStyles: {
14
17
  borderRadius: string;
@@ -23,25 +23,32 @@ 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 = 5;
26
+ var defaultPageSize = 50;
27
27
  var useTable = function (_a) {
28
- var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, columns = _a.columns, onSelection = _a.onSelection;
28
+ var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, columns = _a.columns, onSelection = _a.onSelection, tablePreferences = _a.tablePreferences, savePreferences = _a.savePreferences, noOfRowsPerPage = _a.noOfRowsPerPage;
29
29
  var theme = (0, useCustomTheme_1.useCustomTheme)();
30
30
  var headerRefs = (0, react_1.useRef)([]);
31
31
  var _b = (0, react_1.useState)([]), columnWidths = _b[0], setColumnWidths = _b[1];
32
32
  var _c = (0, react_1.useState)(selections !== null && selections !== void 0 ? selections : []), selection = _c[0], setSelection = _c[1];
33
33
  var _d = (0, react_1.useState)([]), columnsSort = _d[0], setColumnsSort = _d[1];
34
34
  var _e = (0, react_1.useState)(0), currentPage = _e[0], setCurrentPage = _e[1];
35
- var _f = (0, react_1.useState)(defaultPageSize), rowsPerPage = _f[0], setRowsPerPage = _f[1];
36
- var _g = (0, react_1.useState)(columns.reduce(function (acc, curr) {
37
- var _a;
38
- return (__assign(__assign({}, acc), (_a = {}, _a[curr.label] = true, _a)));
39
- }, {})), visibleColumns = _g[0], setVisibleColumns = _g[1];
35
+ var _f = (0, react_1.useState)(noOfRowsPerPage !== null && noOfRowsPerPage !== void 0 ? noOfRowsPerPage : defaultPageSize), rowsPerPage = _f[0], setRowsPerPage = _f[1];
36
+ var _g = (0, react_1.useState)({}), visibleColumns = _g[0], setVisibleColumns = _g[1];
40
37
  var tableData = (0, react_1.useMemo)(function () { return data; }, [data]);
41
38
  var _h = (0, react_1.useState)(tableData), filteredData = _h[0], setFilteredData = _h[1];
42
39
  (0, react_1.useEffect)(function () {
43
40
  setFilteredData(tableData);
44
41
  }, [tableData]);
42
+ (0, react_1.useEffect)(function () {
43
+ var _a;
44
+ var nonVisibility = (_a = tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.nonVisibility) !== null && _a !== void 0 ? _a : [];
45
+ var column = columns.reduce(function (acc, curr) {
46
+ var _a;
47
+ var _b;
48
+ return (__assign(__assign({}, acc), (_a = {}, _a[curr.label] = !nonVisibility.includes((_b = curr.id) === null || _b === void 0 ? void 0 : _b.toString().toLowerCase()), _a)));
49
+ }, {});
50
+ setVisibleColumns(column);
51
+ }, [columns, tablePreferences === null || tablePreferences === void 0 ? void 0 : tablePreferences.nonVisibility]);
45
52
  var tableContainerStyles = (0, react_1.useMemo)(function () {
46
53
  var _a;
47
54
  return ({
@@ -112,10 +119,13 @@ var useTable = function (_a) {
112
119
  onSelection && onSelection(selectedItems);
113
120
  }, [onSelection, selection, tableData]);
114
121
  var handleColumnVisibilityChange = function (header) {
115
- setVisibleColumns(function (prev) {
116
- var _a;
117
- return (__assign(__assign({}, prev), (_a = {}, _a[header] = !prev[header], _a)));
118
- });
122
+ var _a;
123
+ var visibility = __assign(__assign({}, visibleColumns), (_a = {}, _a[header] = !visibleColumns[header], _a));
124
+ setVisibleColumns(visibility);
125
+ savePreferences &&
126
+ savePreferences(__assign(__assign({}, tablePreferences), { nonVisibility: Object.keys(visibility)
127
+ .filter(function (key) { return !visibility[key]; })
128
+ .map(function (item) { return item.toLowerCase(); }) }));
119
129
  };
120
130
  return {
121
131
  tableData: tableData,
@@ -1,4 +1,4 @@
1
1
  import React from "react";
2
2
  import { TableProps } from "./TableProps";
3
3
  import "./Table.css";
4
- export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, }: TableProps): React.JSX.Element;
4
+ export default function Table({ data, columns, onSelection, isLoading, isCheckbox, headerBgColor, freezedBgColor, headerTextColor, freezedTextColor, tableBorderColor, noBorders, isPagination, onRowClick, selections, isActionFreeze, preferencesUrl, preferencesKey, preferencesName, preferencesPage, authToken, paginationMode, noOfRowsPerPage, totalPages, onPagination, }: TableProps): React.JSX.Element;
@@ -35,53 +35,66 @@ var TableBody_1 = __importDefault(require("./Components/TableBody"));
35
35
  var useCustomTheme_1 = require("../../Theme/useCustomTheme");
36
36
  var useTable_1 = __importDefault(require("./Components/useTable"));
37
37
  require("./Table.css");
38
- var functions_1 = require("./Utils/functions");
38
+ var table_1 = require("../../Utils/table");
39
+ var usePreferences_1 = require("../../Hooks/usePreferences");
39
40
  function Table(_a) {
40
41
  var _b, _c, _d;
41
- var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _e = _a.isCheckbox, isCheckbox = _e === void 0 ? false : _e, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _f = _a.noBorders, noBorders = _f === void 0 ? false : _f, _g = _a.isPagination, isPagination = _g === void 0 ? true : _g, onRowClick = _a.onRowClick, selections = _a.selections, _h = _a.isActionFreeze, isActionFreeze = _h === void 0 ? true : _h;
42
+ var data = _a.data, columns = _a.columns, onSelection = _a.onSelection, isLoading = _a.isLoading, _e = _a.isCheckbox, isCheckbox = _e === void 0 ? false : _e, headerBgColor = _a.headerBgColor, freezedBgColor = _a.freezedBgColor, headerTextColor = _a.headerTextColor, freezedTextColor = _a.freezedTextColor, tableBorderColor = _a.tableBorderColor, _f = _a.noBorders, noBorders = _f === void 0 ? false : _f, _g = _a.isPagination, isPagination = _g === void 0 ? true : _g, onRowClick = _a.onRowClick, selections = _a.selections, _h = _a.isActionFreeze, isActionFreeze = _h === void 0 ? true : _h, _j = _a.preferencesUrl, preferencesUrl = _j === void 0 ? "https://pixelize.memron.net:5001/api/UserPreference" : _j, _k = _a.preferencesKey, preferencesKey = _k === void 0 ? "" : _k, _l = _a.preferencesName, preferencesName = _l === void 0 ? "" : _l, _m = _a.preferencesPage, preferencesPage = _m === void 0 ? "" : _m, _o = _a.authToken, authToken = _o === void 0 ? "" : _o, _p = _a.paginationMode, paginationMode = _p === void 0 ? "client" : _p, _q = _a.noOfRowsPerPage, noOfRowsPerPage = _q === void 0 ? 50 : _q, _r = _a.totalPages, totalPages = _r === void 0 ? 0 : _r, onPagination = _a.onPagination;
42
43
  var theme = (0, useCustomTheme_1.useCustomTheme)();
43
- var _j = (0, react_1.useState)({}), columnsSearch = _j[0], setColumnsSearch = _j[1];
44
- var _k = (0, useTable_1.default)({
44
+ var _s = (0, react_1.useState)({}), columnsSearch = _s[0], setColumnsSearch = _s[1];
45
+ var _t = (0, usePreferences_1.useGetPreferences)({
46
+ baseUrl: preferencesUrl,
47
+ page: preferencesPage,
48
+ key: preferencesKey,
49
+ name: preferencesName,
50
+ authToken: authToken,
51
+ }), preferences = _t.preferences, loading = _t.loading;
52
+ var savePreferences = (0, usePreferences_1.useSavePreferences)({
53
+ baseUrl: preferencesUrl,
54
+ page: preferencesPage,
55
+ key: preferencesKey,
56
+ name: preferencesName,
57
+ authToken: authToken,
58
+ }).savePreferences;
59
+ var isTableLoading = (0, react_1.useMemo)(function () {
60
+ return loading || isLoading;
61
+ }, [loading, isLoading]);
62
+ var tablePreferences = (0, react_1.useMemo)(function () {
63
+ if (preferences.length) {
64
+ return preferences[0].json;
65
+ }
66
+ return {};
67
+ }, [preferences]);
68
+ var _u = (0, useTable_1.default)({
45
69
  tableBorderColor: tableBorderColor,
46
70
  data: data,
47
71
  isPagination: isPagination,
48
72
  selections: selections,
49
73
  columns: columns,
50
74
  onSelection: onSelection,
51
- }), tableData = _k.tableData, tableContainerStyles = _k.tableContainerStyles, isContent = _k.isContent, isLink = _k.isLink, headerRefs = _k.headerRefs, columnWidths = _k.columnWidths, visibleColumns = _k.visibleColumns, handleSort = _k.handleSort, handleCheckbox = _k.handleCheckbox, filteredData = _k.filteredData, startRow = _k.startRow, endRow = _k.endRow, selection = _k.selection, columnsSort = _k.columnsSort, currentPage = _k.currentPage, pages = _k.pages, rowsPerPage = _k.rowsPerPage, handleColumnVisibilityChange = _k.handleColumnVisibilityChange, handlePageSizeChange = _k.handlePageSizeChange, setCurrentPage = _k.setCurrentPage;
75
+ tablePreferences: tablePreferences,
76
+ savePreferences: savePreferences,
77
+ noOfRowsPerPage: noOfRowsPerPage,
78
+ }), tableData = _u.tableData, tableContainerStyles = _u.tableContainerStyles, isContent = _u.isContent, isLink = _u.isLink, headerRefs = _u.headerRefs, columnWidths = _u.columnWidths, visibleColumns = _u.visibleColumns, handleSort = _u.handleSort, handleCheckbox = _u.handleCheckbox, filteredData = _u.filteredData, startRow = _u.startRow, endRow = _u.endRow, selection = _u.selection, columnsSort = _u.columnsSort, currentPage = _u.currentPage, pages = _u.pages, rowsPerPage = _u.rowsPerPage, handleColumnVisibilityChange = _u.handleColumnVisibilityChange, handlePageSizeChange = _u.handlePageSizeChange, setCurrentPage = _u.setCurrentPage;
52
79
  var _filteredData = (0, react_1.useMemo)(function () {
53
- return (0, functions_1.searchAndSortData)(filteredData, columnsSearch);
80
+ return (0, table_1.searchAndSortData)(filteredData, columnsSearch);
54
81
  }, [columnsSearch, filteredData]);
55
- var RenderPagination = (0, react_1.useCallback)(function () {
56
- if (!isPagination || !filteredData.length)
57
- return null;
58
- return (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(tableData.length), handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }));
59
- }, [
60
- columns,
61
- currentPage,
62
- endRow,
63
- filteredData.length,
64
- handleColumnVisibilityChange,
65
- handlePageSizeChange,
66
- isPagination,
67
- pages,
68
- rowsPerPage,
69
- setCurrentPage,
70
- startRow,
71
- tableData.length,
72
- visibleColumns,
73
- ]);
82
+ (0, react_1.useEffect)(function () {
83
+ if (onPagination) {
84
+ onPagination(currentPage + 1, noOfRowsPerPage);
85
+ }
86
+ }, [currentPage, onPagination, noOfRowsPerPage]);
74
87
  return (react_1.default.createElement(react_1.default.Fragment, null,
75
88
  react_1.default.createElement(react_2.TableContainer, { sx: tableContainerStyles },
76
89
  react_1.default.createElement(react_3.Table, { variant: "simple", size: "sm", overflowX: "scroll", minW: "100%", className: "table_wrapper" },
77
90
  react_1.default.createElement(react_3.Thead, { position: "sticky", top: 0, zIndex: 2 },
78
- react_1.default.createElement(TableHeader_1.default, { columns: columns, isCheckbox: isCheckbox, headerBgColor: headerBgColor !== null && headerBgColor !== void 0 ? headerBgColor : theme.colors.backgroundColor.muted, headerTextColor: headerTextColor !== null && headerTextColor !== void 0 ? headerTextColor : (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[600], freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], visibleColumns: visibleColumns, handleSort: handleSort, headerRefs: headerRefs, columnWidths: columnWidths, columnsSort: columnsSort, noBorders: noBorders, handleCheckbox: handleCheckbox, isLoading: isLoading, checked: tableData.length !== 0 && selection.length === tableData.length
91
+ react_1.default.createElement(TableHeader_1.default, { columns: columns, isCheckbox: isCheckbox, headerBgColor: headerBgColor !== null && headerBgColor !== void 0 ? headerBgColor : theme.colors.backgroundColor.muted, headerTextColor: headerTextColor !== null && headerTextColor !== void 0 ? headerTextColor : (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.gray[600], freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[600], visibleColumns: visibleColumns, handleSort: handleSort, headerRefs: headerRefs, columnWidths: columnWidths, columnsSort: columnsSort, noBorders: noBorders, handleCheckbox: handleCheckbox, isLoading: isTableLoading, checked: tableData.length !== 0 && selection.length === tableData.length
79
92
  ? true
80
93
  : selection.length === 0
81
94
  ? false
82
95
  : "indeterminate", isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze, setColumnsSearch: setColumnsSearch, columnsSearch: columnsSearch })),
83
96
  react_1.default.createElement(react_3.Tbody, null,
84
- react_1.default.createElement(TableBody_1.default, { data: _filteredData, columns: columns, startRow: startRow, endRow: endRow, visibleColumns: visibleColumns, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isLoading, onRowClick: onRowClick, isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze })))),
85
- react_1.default.createElement(RenderPagination, null)));
97
+ react_1.default.createElement(TableBody_1.default, { data: _filteredData, columns: columns, startRow: startRow, endRow: endRow, visibleColumns: visibleColumns, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isTableLoading, onRowClick: onRowClick, isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze })))),
98
+ isPagination && (react_1.default.createElement(Pagination_1.default, { columns: columns, currentPage: currentPage, setCurrentPage: setCurrentPage, rowsPerPage: rowsPerPage, pages: totalPages !== null && totalPages !== void 0 ? totalPages : pages, paginationText: "".concat(startRow + 1, " to ").concat(endRow, " of ").concat(tableData.length), handlePageSizeChange: handlePageSizeChange, dataLength: tableData.length, isServerPagination: paginationMode === "server", visibleColumns: visibleColumns, handleColumnVisibilityChange: handleColumnVisibilityChange, isVisiblity: true }))));
86
99
  }
87
100
  exports.default = Table;
@@ -19,6 +19,15 @@ export type TableProps = {
19
19
  selections?: (string | number)[];
20
20
  onRowClick?: (row: DataObject, header: Record<string | number, string | number>) => void;
21
21
  isActionFreeze?: boolean;
22
+ preferencesUrl?: string;
23
+ preferencesKey?: string;
24
+ preferencesName?: string;
25
+ preferencesPage?: string;
26
+ authToken?: string;
27
+ paginationMode?: "client" | "server";
28
+ noOfRowsPerPage?: number;
29
+ totalPages?: number;
30
+ onPagination?: (page: number, noOfRecords: number) => void;
22
31
  };
23
32
  export type DataObject = {
24
33
  [key: string]: string | number | any;
@@ -0,0 +1,24 @@
1
+ type PreferencesProps = {
2
+ baseUrl: string;
3
+ key?: string;
4
+ page?: string;
5
+ name?: string;
6
+ authToken?: string;
7
+ };
8
+ type PreferencesResponseProps = {
9
+ json: Record<string, any>;
10
+ key: string;
11
+ name: string;
12
+ page: string;
13
+ preference_id: string;
14
+ };
15
+ declare const useGetPreferences: ({ baseUrl, key, page, name, authToken, }: PreferencesProps) => {
16
+ preferences: PreferencesResponseProps[];
17
+ loading: boolean;
18
+ };
19
+ declare const useSavePreferences: ({ baseUrl, key, page, name, authToken, }: PreferencesProps) => {
20
+ savePreferences: (data?: Record<string, any>) => void;
21
+ loading: boolean;
22
+ error: null;
23
+ };
24
+ export { useGetPreferences, useSavePreferences };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSavePreferences = exports.useGetPreferences = void 0;
4
+ var react_1 = require("react");
5
+ var constructUrl = function (_a) {
6
+ var baseUrl = _a.baseUrl, key = _a.key, page = _a.page, name = _a.name;
7
+ var params = new URLSearchParams();
8
+ if (page) {
9
+ params.append("page", page);
10
+ }
11
+ if (key) {
12
+ params.append("key", key);
13
+ }
14
+ if (name) {
15
+ params.append("name", name);
16
+ }
17
+ var queryString = params.toString();
18
+ return "".concat(baseUrl).concat(queryString ? "?".concat(queryString) : "");
19
+ };
20
+ var useGetPreferences = function (_a) {
21
+ var _b = _a.baseUrl, baseUrl = _b === void 0 ? "" : _b, _c = _a.key, key = _c === void 0 ? "" : _c, _d = _a.page, page = _d === void 0 ? "" : _d, _e = _a.name, name = _e === void 0 ? "" : _e, _f = _a.authToken, authToken = _f === void 0 ? "" : _f;
22
+ var _g = (0, react_1.useState)([]), preferences = _g[0], setPreferences = _g[1];
23
+ var _h = (0, react_1.useState)(false), loading = _h[0], setLoading = _h[1];
24
+ (0, react_1.useEffect)(function () {
25
+ if (!baseUrl) {
26
+ return;
27
+ }
28
+ setLoading(true);
29
+ var url = constructUrl({ baseUrl: baseUrl, key: key, page: page, name: name });
30
+ fetch(url, {
31
+ headers: {
32
+ Authorization: authToken,
33
+ },
34
+ })
35
+ .then(function (response) { return response.json(); })
36
+ .then(function (data) { return setPreferences(data); })
37
+ .catch(function (error) { return console.error(error); })
38
+ .finally(function () { return setLoading(false); });
39
+ }, [baseUrl]);
40
+ return { preferences: preferences, loading: loading };
41
+ };
42
+ exports.useGetPreferences = useGetPreferences;
43
+ var useSavePreferences = function (_a) {
44
+ var _b = _a.baseUrl, baseUrl = _b === void 0 ? "" : _b, _c = _a.key, key = _c === void 0 ? "" : _c, _d = _a.page, page = _d === void 0 ? "" : _d, _e = _a.name, name = _e === void 0 ? "" : _e, _f = _a.authToken, authToken = _f === void 0 ? "" : _f;
45
+ var _g = (0, react_1.useState)(false), loading = _g[0], setLoading = _g[1];
46
+ var _h = (0, react_1.useState)(null), error = _h[0], setError = _h[1];
47
+ var savePreferences = function (data) {
48
+ if (data === void 0) { data = {}; }
49
+ setLoading(true);
50
+ fetch(baseUrl, {
51
+ method: "POST",
52
+ headers: {
53
+ Authorization: authToken,
54
+ "Content-Type": "application/json",
55
+ },
56
+ body: JSON.stringify({
57
+ key: key,
58
+ page: page,
59
+ name: name,
60
+ json: data,
61
+ }),
62
+ })
63
+ .then(function (response) { return response.json(); })
64
+ .then(function (data) { return console.log(data); })
65
+ .catch(function (error) { return setError(error); })
66
+ .finally(function () { return setLoading(false); });
67
+ };
68
+ return { savePreferences: savePreferences, loading: loading, error: error };
69
+ };
70
+ exports.useSavePreferences = useSavePreferences;
@@ -7,3 +7,5 @@ export declare function SortMultiColumnData(data: Record<string, string | number
7
7
  export declare const getPreviousColumnWidth: (columns: KaTableProps["columns"], key: string) => any;
8
8
  export declare const getFieldType: (header: string, data: DataObject[]) => "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function";
9
9
  export declare const calculateLeftOffset: (columns: number[], index: number) => number;
10
+ export declare const searchAndSortData: (data: DataObject[], searchValues: Record<string, string>) => DataObject[];
11
+ export declare function debounce<T extends (...args: any[]) => void>(func: T, delay: number): (...args: Parameters<T>) => void;
@@ -9,7 +9,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
9
9
  return to.concat(ar || Array.prototype.slice.call(from));
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.calculateLeftOffset = exports.getFieldType = exports.getPreviousColumnWidth = exports.SortMultiColumnData = void 0;
12
+ exports.debounce = exports.searchAndSortData = exports.calculateLeftOffset = exports.getFieldType = exports.getPreviousColumnWidth = exports.SortMultiColumnData = void 0;
13
13
  function SortMultiColumnData(data, sortConfig) {
14
14
  if (!sortConfig.length)
15
15
  return data;
@@ -39,15 +39,6 @@ var getPreviousColumnWidth = function (columns, key) {
39
39
  return 0;
40
40
  };
41
41
  exports.getPreviousColumnWidth = getPreviousColumnWidth;
42
- // export function calculateLeftOffset(columns: any, currentIndex: number) {
43
- // let offset = 0;
44
- // for (let i = 0; i < currentIndex; i++) {
45
- // if (columns[i].isFreeze) {
46
- // offset += columns[i].width || 100;
47
- // }
48
- // }
49
- // return offset;
50
- // }
51
42
  var getFieldType = function (header, data) {
52
43
  for (var _i = 0, data_1 = data; _i < data_1.length; _i++) {
53
44
  var row = data_1[_i];
@@ -62,3 +53,46 @@ var calculateLeftOffset = function (columns, index) {
62
53
  return columns.slice(0, index).reduce(function (sum, width) { return sum + width; }, 0);
63
54
  };
64
55
  exports.calculateLeftOffset = calculateLeftOffset;
56
+ var searchAndSortData = function (data, searchValues) {
57
+ var filteredData = data.filter(function (item) {
58
+ return Object.keys(searchValues).every(function (key) {
59
+ var searchValue = searchValues[key].toLowerCase();
60
+ return item[key].toString().toLowerCase().includes(searchValue);
61
+ });
62
+ });
63
+ return filteredData.sort(function (a, b) {
64
+ var aMatchCount = 0;
65
+ var bMatchCount = 0;
66
+ Object.keys(searchValues).forEach(function (key) {
67
+ var searchValue = searchValues[key].toLowerCase();
68
+ if (a[key] && a[key].toString().toLowerCase() === searchValue) {
69
+ aMatchCount++;
70
+ }
71
+ if (b[key] && b[key].toString().toLowerCase() === searchValue) {
72
+ bMatchCount++;
73
+ }
74
+ if (a[key] && a[key].toString().toLowerCase().includes(searchValue)) {
75
+ aMatchCount += 0.5;
76
+ }
77
+ if (b[key] && b[key].toString().toLowerCase().includes(searchValue)) {
78
+ bMatchCount += 0.5;
79
+ }
80
+ });
81
+ return bMatchCount - aMatchCount;
82
+ });
83
+ };
84
+ exports.searchAndSortData = searchAndSortData;
85
+ function debounce(func, delay) {
86
+ var timer;
87
+ return function () {
88
+ var args = [];
89
+ for (var _i = 0; _i < arguments.length; _i++) {
90
+ args[_i] = arguments[_i];
91
+ }
92
+ clearTimeout(timer);
93
+ timer = setTimeout(function () {
94
+ func.apply(void 0, args);
95
+ }, delay);
96
+ };
97
+ }
98
+ exports.debounce = debounce;
package/dist/index.d.ts CHANGED
@@ -39,5 +39,6 @@ import VerifyEmailOtp from "./Components/EmailCards/VerifyEmailOtp/VerifyEmailOt
39
39
  import withTheme from "./withTheme";
40
40
  import { useCustomTheme } from "./Theme/useCustomTheme";
41
41
  import { ThemesList } from "./Theme";
42
- export { Accordian, AlertDialog, ApexBarChart, ApexPieChart, Breadcrumbs, Button, ButtonGroupIcon, Card, Checkbox, DatePicker, Drawer, DrawerHeader, DrawerBody, DrawerFooter, Dropdown, Editor, InputTextArea, KaTable, TableActionCreator, TableEnums, TableProps, TableModel, TableUtils, TableFun, Loading, Modal, ModalHeader, ModalBody, ModalFooter, NavigationBar, NoteTextArea, MultiSelect, NumberInput, PinInput, ProfileCard, ProfileCardHeader, ProfileCardBody, ProfileCardFooter, ProfilePhotoViewer, ProgressBar, RadioButton, RadioButtonGroup, Search, Select, SelectSearch, SideBar, Skeletons, Switch, Table, TextInput, Timeline, Toaster, ToolTip, useToaster, VerifyEmailOtp, useCustomTheme, ThemesList, };
42
+ import { debounce } from "./Utils/table";
43
+ export { Accordian, AlertDialog, ApexBarChart, ApexPieChart, Breadcrumbs, Button, ButtonGroupIcon, Card, Checkbox, DatePicker, Drawer, DrawerHeader, DrawerBody, DrawerFooter, Dropdown, Editor, InputTextArea, KaTable, TableActionCreator, TableEnums, TableProps, TableModel, TableUtils, TableFun, Loading, Modal, ModalHeader, ModalBody, ModalFooter, NavigationBar, NoteTextArea, MultiSelect, NumberInput, PinInput, ProfileCard, ProfileCardHeader, ProfileCardBody, ProfileCardFooter, ProfilePhotoViewer, ProgressBar, RadioButton, RadioButtonGroup, Search, Select, SelectSearch, SideBar, Skeletons, Switch, Table, TextInput, Timeline, Toaster, ToolTip, useToaster, VerifyEmailOtp, useCustomTheme, ThemesList, debounce, };
43
44
  export default withTheme;
package/dist/index.js CHANGED
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
30
  exports.TextInput = exports.Table = exports.Switch = exports.Skeletons = exports.SideBar = exports.SelectSearch = exports.Select = exports.Search = exports.RadioButtonGroup = exports.RadioButton = exports.ProgressBar = exports.ProfilePhotoViewer = exports.ProfileCardFooter = exports.ProfileCardBody = exports.ProfileCardHeader = exports.ProfileCard = exports.PinInput = exports.NumberInput = exports.MultiSelect = exports.NoteTextArea = exports.NavigationBar = exports.ModalFooter = exports.ModalBody = exports.ModalHeader = exports.Modal = exports.Loading = exports.TableFun = exports.TableUtils = exports.TableModel = exports.TableProps = exports.TableEnums = exports.TableActionCreator = exports.KaTable = exports.InputTextArea = exports.Editor = exports.Dropdown = exports.DrawerFooter = exports.DrawerBody = exports.DrawerHeader = exports.Drawer = exports.DatePicker = exports.Checkbox = exports.Card = exports.ButtonGroupIcon = exports.Button = exports.Breadcrumbs = exports.ApexPieChart = exports.ApexBarChart = exports.AlertDialog = exports.Accordian = void 0;
31
- exports.ThemesList = exports.useCustomTheme = exports.VerifyEmailOtp = exports.useToaster = exports.ToolTip = exports.Toaster = exports.Timeline = void 0;
31
+ exports.debounce = exports.ThemesList = exports.useCustomTheme = exports.VerifyEmailOtp = exports.useToaster = exports.ToolTip = exports.Toaster = exports.Timeline = void 0;
32
32
  var Accordion_1 = __importDefault(require("./Components/Accordion/Accordion"));
33
33
  exports.Accordian = Accordion_1.default;
34
34
  var AlertDialog_1 = __importDefault(require("./Components/AlertDialog/AlertDialog"));
@@ -127,4 +127,6 @@ var useCustomTheme_1 = require("./Theme/useCustomTheme");
127
127
  Object.defineProperty(exports, "useCustomTheme", { enumerable: true, get: function () { return useCustomTheme_1.useCustomTheme; } });
128
128
  var Theme_1 = require("./Theme");
129
129
  Object.defineProperty(exports, "ThemesList", { enumerable: true, get: function () { return Theme_1.ThemesList; } });
130
+ var table_1 = require("./Utils/table");
131
+ Object.defineProperty(exports, "debounce", { enumerable: true, get: function () { return table_1.debounce; } });
130
132
  exports.default = withTheme_1.default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "1.1.55",
3
+ "version": "1.1.57",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",