pixelize-design-library 2.2.184 → 2.2.187
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/Components/Table/Components/TableBody.js +41 -40
- package/dist/Components/Table/Components/TableHeader.d.ts +1 -1
- package/dist/Components/Table/Components/TableHeader.js +4 -4
- package/dist/Components/Table/Components/useTable.d.ts +3 -1
- package/dist/Components/Table/Components/useTable.js +35 -17
- package/dist/Components/Table/Table.d.ts +1 -1
- package/dist/Components/Table/Table.js +4 -5
- package/dist/Components/Table/TableProps.d.ts +2 -0
- package/package.json +1 -1
|
@@ -44,50 +44,37 @@ var TableLoading_1 = require("./TableLoading");
|
|
|
44
44
|
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
|
+
var EMPTY_SX = {};
|
|
48
|
+
var EMPTY_HOVER = {};
|
|
47
49
|
var TableRow = react_2.default.memo(function (_a) {
|
|
48
|
-
var _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
49
|
-
var row = _a.row, rowIndex = _a.rowIndex, index = _a.index, isChecked = _a.isChecked, isExpanded = _a.isExpanded, isContent = _a.isContent, isLink = _a.isLink, isCheckbox = _a.isCheckbox, isLoading = _a.isLoading, isActionFreeze = _a.isActionFreeze, columns = _a.columns,
|
|
50
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
51
|
+
var row = _a.row, rowIndex = _a.rowIndex, index = _a.index, isChecked = _a.isChecked, isExpanded = _a.isExpanded, isContent = _a.isContent, isLink = _a.isLink, isCheckbox = _a.isCheckbox, isLoading = _a.isLoading, isActionFreeze = _a.isActionFreeze, columns = _a.columns, leftOffsets = _a.leftOffsets, noBorders = _a.noBorders, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, theme = _a.theme, borderStyle = _a.borderStyle, hoverStyle = _a.hoverStyle, handleCheckbox = _a.handleCheckbox, onRowClick = _a.onRowClick, toggleRowExpansion = _a.toggleRowExpansion;
|
|
52
|
+
var checkedSx = (0, react_2.useMemo)(function () { return isChecked ? {
|
|
53
|
+
"& td": { backgroundColor: theme.colors.disabled[100] },
|
|
54
|
+
} : EMPTY_SX; }, [isChecked, theme.colors.disabled]);
|
|
55
|
+
var handleCellClick = (0, react_2.useCallback)(function (header) {
|
|
56
|
+
if (!header.node && onRowClick) {
|
|
57
|
+
onRowClick(row, { label: header.label, id: header.id });
|
|
58
|
+
}
|
|
59
|
+
}, [row, onRowClick]);
|
|
50
60
|
return (react_2.default.createElement(react_2.default.Fragment, null,
|
|
51
|
-
react_2.default.createElement(react_1.Tr, { opacity: isLoading ? 0.4 : 1, pointerEvents: isLoading ? "none" : "auto", transition: "opacity 0.2s", sx:
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
backgroundColor: theme.colors.disabled[100],
|
|
55
|
-
},
|
|
56
|
-
}
|
|
57
|
-
: {} },
|
|
58
|
-
isContent && (react_2.default.createElement(react_1.Td, { w: "6", p: 0, fontSize: 14, backgroundColor: (_c = (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.background) === null || _c === void 0 ? void 0 : _c[50], color: freezedTextColor, position: "sticky", borderBottom: noBorders ? "none" : "0.063rem solid ".concat((_d = theme.colors) === null || _d === void 0 ? void 0 : _d.border[500]), boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" }, !!(row === null || row === void 0 ? void 0 : row.content) && (react_2.default.createElement(react_1.IconButton, { "aria-label": isExpanded ? "Collapse row" : "Expand row", color: (_e = theme.colors) === null || _e === void 0 ? void 0 : _e.gray[600], icon: isExpanded ? (react_2.default.createElement(lucide_react_1.ChevronDown, { fontSize: 16 })) : (react_2.default.createElement(lucide_react_1.ChevronRight, { fontSize: 16 })), _hover: { transform: "scale(1.1)" }, size: "sm", onClick: function () { return toggleRowExpansion(rowIndex); }, variant: "ghost" })))),
|
|
59
|
-
isCheckbox && (react_2.default.createElement(react_1.Td, { w: "6", fontSize: 14, fontWeight: 600, color: (_g = (_f = theme.colors) === null || _f === void 0 ? void 0 : _f.background) === null || _g === void 0 ? void 0 : _g[50], textTransform: "capitalize", backgroundColor: (_j = (_h = theme.colors) === null || _h === void 0 ? void 0 : _h.background) === null || _j === void 0 ? void 0 : _j[50], position: "sticky", borderBottom: noBorders ? "none" : "0.063rem solid ".concat((_k = theme.colors) === null || _k === void 0 ? void 0 : _k.border[500]), boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" },
|
|
61
|
+
react_2.default.createElement(react_1.Tr, { opacity: isLoading ? 0.4 : 1, pointerEvents: isLoading ? "none" : "auto", transition: "opacity 0.2s", sx: checkedSx },
|
|
62
|
+
isContent && (react_2.default.createElement(react_1.Td, { w: "6", p: 0, fontSize: 14, backgroundColor: (_c = (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.background) === null || _c === void 0 ? void 0 : _c[50], color: freezedTextColor, position: "sticky", borderBottom: borderStyle, boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" }, !!(row === null || row === void 0 ? void 0 : row.content) && (react_2.default.createElement(react_1.IconButton, { "aria-label": isExpanded ? "Collapse row" : "Expand row", color: (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.gray[600], icon: isExpanded ? (react_2.default.createElement(lucide_react_1.ChevronDown, { fontSize: 16 })) : (react_2.default.createElement(lucide_react_1.ChevronRight, { fontSize: 16 })), _hover: { transform: "scale(1.1)" }, size: "sm", onClick: function () { return toggleRowExpansion(rowIndex); }, variant: "ghost" })))),
|
|
63
|
+
isCheckbox && (react_2.default.createElement(react_1.Td, { w: "6", fontSize: 14, fontWeight: 600, color: (_f = (_e = theme.colors) === null || _e === void 0 ? void 0 : _e.background) === null || _f === void 0 ? void 0 : _f[50], textTransform: "capitalize", backgroundColor: (_h = (_g = theme.colors) === null || _g === void 0 ? void 0 : _g.background) === null || _h === void 0 ? void 0 : _h[50], position: "sticky", borderBottom: borderStyle, boxSizing: "border-box", left: 0, zIndex: 1, className: "columns sticky-columns" },
|
|
60
64
|
react_2.default.createElement(Checkbox_1.default, { "aria-label": "Select all rows", onChange: function () { return handleCheckbox(row.id); }, isChecked: isChecked }))),
|
|
61
65
|
columns.map(function (header, headerIndex) {
|
|
62
|
-
var _a, _b, _c, _d, _e
|
|
66
|
+
var _a, _b, _c, _d, _e;
|
|
63
67
|
if (header.isHidden)
|
|
64
68
|
return null;
|
|
65
69
|
var isFrozen = header.isFreeze;
|
|
66
|
-
|
|
67
|
-
isFrozen: isFrozen,
|
|
68
|
-
columnWidths: columnWidths,
|
|
69
|
-
headerIndex: headerIndex,
|
|
70
|
-
isCheckbox: isCheckbox,
|
|
71
|
-
header: header,
|
|
72
|
-
row: row,
|
|
73
|
-
freezedBgColor: freezedBgColor,
|
|
74
|
-
index: index,
|
|
75
|
-
theme: theme,
|
|
76
|
-
}).leftOffset;
|
|
77
|
-
return (react_2.default.createElement(react_1.Td, { maxWidth: 500, minWidth: 120, height: 45, key: headerIndex + 1, onClick: function () {
|
|
78
|
-
return !header.node
|
|
79
|
-
? onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(row, { label: header.label, id: header.id })
|
|
80
|
-
: null;
|
|
81
|
-
}, 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
|
|
70
|
+
return (react_2.default.createElement(react_1.Td, { maxWidth: 500, minWidth: 120, height: 45, key: headerIndex + 1, onClick: function () { return handleCellClick(header); }, fontSize: 14, fontWeight: 400, position: isFrozen ? "sticky" : undefined, left: isFrozen ? leftOffsets[headerIndex] : undefined, zIndex: isFrozen ? 1 : 0, backgroundColor: (_a = theme.colors.background) === null || _a === void 0 ? void 0 : _a[50], textOverflow: "ellipsis", borderBottom: noBorders
|
|
82
71
|
? "none"
|
|
83
72
|
: "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
|
|
84
|
-
?
|
|
85
|
-
:
|
|
86
|
-
backgroundColor: (_g = (_f = theme.colors.secondary) === null || _f === void 0 ? void 0 : _f.opacity) === null || _g === void 0 ? void 0 : _g[4],
|
|
87
|
-
} },
|
|
73
|
+
? EMPTY_HOVER
|
|
74
|
+
: hoverStyle },
|
|
88
75
|
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]))));
|
|
89
76
|
}),
|
|
90
|
-
isLink && (react_2.default.createElement(react_1.Td, { w: 2, p: 0, fontSize: 14, backgroundColor: (
|
|
77
|
+
isLink && (react_2.default.createElement(react_1.Td, { w: 2, p: 0, fontSize: 14, backgroundColor: (_k = (_j = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _j === void 0 ? void 0 : _j.background) === null || _k === void 0 ? void 0 : _k[50], color: freezedTextColor, position: isActionFreeze ? "sticky" : "relative", borderBottom: borderStyle, boxSizing: "border-box", right: 0, zIndex: 1, className: "columns sticky-columns".concat(isActionFreeze ? "-right" : "") }, (row.onLink || row.onEdit || row.onDelete) && (react_2.default.createElement(TableActions_1.default, { row: row }))))),
|
|
91
78
|
row.content && isExpanded && (react_2.default.createElement(react_1.Tr, null,
|
|
92
79
|
react_2.default.createElement(react_1.Td, { colSpan: columns.length +
|
|
93
80
|
(isCheckbox ? 1 : 0) +
|
|
@@ -96,10 +83,11 @@ var TableRow = react_2.default.memo(function (_a) {
|
|
|
96
83
|
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)))))));
|
|
97
84
|
});
|
|
98
85
|
var TableBody = function (_a) {
|
|
99
|
-
var _b, _c, _d, _e, _f;
|
|
86
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
100
87
|
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;
|
|
101
88
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
102
|
-
var
|
|
89
|
+
var _j = (0, react_2.useState)(new Set()), expandedRows = _j[0], setExpandedRows = _j[1];
|
|
90
|
+
var selectionsSet = (0, react_2.useMemo)(function () { return new Set(selections); }, [selections]);
|
|
103
91
|
var toggleRowExpansion = (0, react_2.useCallback)(function (rowIndex) {
|
|
104
92
|
setExpandedRows(function (prev) {
|
|
105
93
|
var newSet = new Set(prev);
|
|
@@ -118,26 +106,39 @@ var TableBody = function (_a) {
|
|
|
118
106
|
(isContent ? 1 : 0) +
|
|
119
107
|
(isLink ? 1 : 0);
|
|
120
108
|
}, [columns, isCheckbox, isContent, isLink]);
|
|
109
|
+
var leftOffsets = (0, react_2.useMemo)(function () {
|
|
110
|
+
var checkboxOffset = isCheckbox ? 50 : 0;
|
|
111
|
+
return columnWidths.map(function (_, idx) {
|
|
112
|
+
return columnWidths.slice(0, idx).reduce(function (sum, w) { return sum + w; }, 0) + checkboxOffset;
|
|
113
|
+
});
|
|
114
|
+
}, [columnWidths, isCheckbox]);
|
|
115
|
+
var borderStyle = (0, react_2.useMemo)(function () { var _a; return noBorders ? "none" : "0.063rem solid ".concat((_a = theme.colors) === null || _a === void 0 ? void 0 : _a.border[500]); }, [noBorders, (_b = theme.colors) === null || _b === void 0 ? void 0 : _b.border]);
|
|
116
|
+
var hoverStyle = (0, react_2.useMemo)(function () {
|
|
117
|
+
var _a, _b;
|
|
118
|
+
return ({
|
|
119
|
+
backgroundColor: (_b = (_a = theme.colors.secondary) === null || _a === void 0 ? void 0 : _a.opacity) === null || _b === void 0 ? void 0 : _b[4],
|
|
120
|
+
});
|
|
121
|
+
}, [(_c = theme.colors.secondary) === null || _c === void 0 ? void 0 : _c.opacity]);
|
|
121
122
|
if (isLoading && data.length === 0) {
|
|
122
123
|
return (react_2.default.createElement(TableLoading_1.TableBodyLoading, { noOfColumns: totalVisibleColumns, borderColor: theme.colors.gray[300], rowsCount: typeof loadingSkeletonRows === "number" ? loadingSkeletonRows : 4 }));
|
|
123
124
|
}
|
|
124
125
|
if (!isLoading && data.length === 0) {
|
|
125
|
-
return (react_2.default.createElement(react_1.Tr, { backgroundColor: (
|
|
126
|
+
return (react_2.default.createElement(react_1.Tr, { backgroundColor: (_d = theme.colors.background) === null || _d === void 0 ? void 0 : _d[50] },
|
|
126
127
|
react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, textAlign: "center", py: 4 },
|
|
127
|
-
react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14, color: (
|
|
128
|
+
react_2.default.createElement(react_1.Box, { textAlign: "center", fontSize: 14, color: (_f = (_e = theme.colors) === null || _e === void 0 ? void 0 : _e.text) === null || _f === void 0 ? void 0 : _f[500] },
|
|
128
129
|
react_2.default.createElement("p", null, "No data found")))));
|
|
129
130
|
}
|
|
130
131
|
return (react_2.default.createElement(react_2.default.Fragment, null,
|
|
131
132
|
isLoading && data.length > 0 && (react_2.default.createElement(react_1.Tr, null,
|
|
132
133
|
react_2.default.createElement(react_1.Td, { colSpan: totalVisibleColumns, p: 0, border: "none", position: "relative", height: 0 },
|
|
133
134
|
react_2.default.createElement(react_1.Box, { position: "absolute", top: 4, left: "50%", transform: "translateX(-50%)", zIndex: 10 },
|
|
134
|
-
react_2.default.createElement(react_1.Spinner, { size: "sm", color: ((
|
|
135
|
+
react_2.default.createElement(react_1.Spinner, { size: "sm", color: ((_h = (_g = theme.colors) === null || _g === void 0 ? void 0 : _g.primary) === null || _h === void 0 ? void 0 : _h[500]) || "blue.500" }))))),
|
|
135
136
|
data.map(function (row, index) {
|
|
136
137
|
var _a;
|
|
137
138
|
var rowIndex = startRow + index;
|
|
138
139
|
var isExpanded = expandedRows.has(rowIndex);
|
|
139
|
-
var isChecked =
|
|
140
|
-
return (react_2.default.createElement(TableRow, { key: (_a = row.id) !== null && _a !== void 0 ? _a : rowIndex, row: row, rowIndex: rowIndex, index: index, isChecked: isChecked, isExpanded: isExpanded, isContent: isContent, isLink: isLink, isCheckbox: isCheckbox, isLoading: isLoading, isActionFreeze: isActionFreeze, columns: columns,
|
|
140
|
+
var isChecked = selectionsSet.has(row.id);
|
|
141
|
+
return (react_2.default.createElement(TableRow, { key: (_a = row.id) !== null && _a !== void 0 ? _a : rowIndex, row: row, rowIndex: rowIndex, index: index, isChecked: isChecked, isExpanded: isExpanded, isContent: isContent, isLink: isLink, isCheckbox: isCheckbox, isLoading: isLoading, isActionFreeze: isActionFreeze, columns: columns, leftOffsets: leftOffsets, noBorders: noBorders, freezedBgColor: freezedBgColor, freezedTextColor: freezedTextColor, theme: theme, borderStyle: borderStyle, hoverStyle: hoverStyle, handleCheckbox: handleCheckbox, onRowClick: onRowClick, toggleRowExpansion: toggleRowExpansion }));
|
|
141
142
|
})));
|
|
142
143
|
};
|
|
143
144
|
exports.default = TableBody;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TableHeaderPageProps } from "../TableProps";
|
|
3
|
-
declare const _default: React.MemoExoticComponent<({ columns, isCheckbox, handleSort, headerRefs, columnWidths, columnsSort, headerBgColor, headerTextColor, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, checked, isLoading, isContent, isLink, isActionFreeze, setColumnsSearch, columnsSearch, }: TableHeaderPageProps) => React.JSX.Element>;
|
|
3
|
+
declare const _default: React.MemoExoticComponent<({ columns, isCheckbox, handleSort, headerRefs, columnWidths, columnsSort, headerBgColor, headerTextColor, freezedBgColor, freezedTextColor, noBorders, handleCheckbox, checked, isLoading, isContent, isLink, isActionFreeze, setColumnsSearch, columnsSearch, isSelecting, }: TableHeaderPageProps) => React.JSX.Element>;
|
|
4
4
|
export default _default;
|
|
@@ -55,18 +55,18 @@ var TableFilters_1 = __importDefault(require("./TableFilters"));
|
|
|
55
55
|
var lucide_react_1 = require("lucide-react");
|
|
56
56
|
var Checkbox_1 = __importDefault(require("../../Checkbox/Checkbox"));
|
|
57
57
|
var TableHeader = function (_a) {
|
|
58
|
-
var columns = _a.columns, isCheckbox = _a.isCheckbox, handleSort = _a.handleSort, headerRefs = _a.headerRefs, columnWidths = _a.columnWidths, columnsSort = _a.columnsSort, headerBgColor = _a.headerBgColor, headerTextColor = _a.headerTextColor, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, checked = _a.checked, isLoading = _a.isLoading, isContent = _a.isContent, isLink = _a.isLink, isActionFreeze = _a.isActionFreeze, setColumnsSearch = _a.setColumnsSearch, columnsSearch = _a.columnsSearch;
|
|
58
|
+
var columns = _a.columns, isCheckbox = _a.isCheckbox, handleSort = _a.handleSort, headerRefs = _a.headerRefs, columnWidths = _a.columnWidths, columnsSort = _a.columnsSort, headerBgColor = _a.headerBgColor, headerTextColor = _a.headerTextColor, freezedBgColor = _a.freezedBgColor, freezedTextColor = _a.freezedTextColor, noBorders = _a.noBorders, handleCheckbox = _a.handleCheckbox, checked = _a.checked, isLoading = _a.isLoading, isContent = _a.isContent, isLink = _a.isLink, isActionFreeze = _a.isActionFreeze, setColumnsSearch = _a.setColumnsSearch, columnsSearch = _a.columnsSearch, isSelecting = _a.isSelecting;
|
|
59
59
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
60
60
|
var _b = (0, react_2.useState)(null), openFilterId = _b[0], setOpenFilterId = _b[1];
|
|
61
61
|
var RenderCheckbox = (0, react_2.useCallback)(function () {
|
|
62
|
-
var _a, _b, _c;
|
|
63
|
-
return (react_2.default.createElement(react_1.Th, { w: 6, fontSize: 14, fontWeight: 600, color: freezedTextColor, textTransform: "capitalize", backgroundColor: (_b = (_a = theme.colors) === null || _a === void 0 ? void 0 : _a.secondary) === null || _b === void 0 ? void 0 : _b[50], borderY: noBorders ? "none" : "0.063rem solid ".concat((_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 9, boxShadow: theme.shadows.md },
|
|
64
|
-
react_2.default.createElement(Checkbox_1.default, { "aria-label": "Select all rows", variant: "outline", onChange: function () { return handleCheckbox(0); }, isChecked: isLoading ? false : checked === true, isIndeterminate: checked === "indeterminate" })));
|
|
62
|
+
var _a, _b, _c, _d, _e;
|
|
63
|
+
return (react_2.default.createElement(react_1.Th, { w: 6, fontSize: 14, fontWeight: 600, color: freezedTextColor, textTransform: "capitalize", backgroundColor: (_b = (_a = theme.colors) === null || _a === void 0 ? void 0 : _a.secondary) === null || _b === void 0 ? void 0 : _b[50], borderY: noBorders ? "none" : "0.063rem solid ".concat((_c = theme.colors) === null || _c === void 0 ? void 0 : _c.gray[300]), position: "sticky", className: "columns sticky-columns", left: "0px", zIndex: 9, boxShadow: theme.shadows.md }, isSelecting ? (react_2.default.createElement(react_1.Spinner, { size: "sm", color: (_e = (_d = theme.colors) === null || _d === void 0 ? void 0 : _d.primary) === null || _e === void 0 ? void 0 : _e[500] })) : (react_2.default.createElement(Checkbox_1.default, { "aria-label": "Select all rows", variant: "outline", onChange: function () { return handleCheckbox(0); }, isChecked: isLoading ? false : checked === true, isIndeterminate: checked === "indeterminate" }))));
|
|
65
64
|
}, [
|
|
66
65
|
checked,
|
|
67
66
|
freezedTextColor,
|
|
68
67
|
handleCheckbox,
|
|
69
68
|
isLoading,
|
|
69
|
+
isSelecting,
|
|
70
70
|
noBorders,
|
|
71
71
|
theme.colors,
|
|
72
72
|
]);
|
|
@@ -12,8 +12,9 @@ type UseTableProps = {
|
|
|
12
12
|
isServerPagination: boolean;
|
|
13
13
|
totalRecords: number;
|
|
14
14
|
onNoOfRowsPerPageChange?: (noOfRows: number) => void;
|
|
15
|
+
defaultVisibleColumns?: number;
|
|
15
16
|
};
|
|
16
|
-
declare const useTable: ({ tableBorderColor, data, isPagination, selections, onSelection, tablePreferences, savePreferences, noOfRowsPerPage, isServerPagination, totalRecords, columns, onNoOfRowsPerPageChange, }: UseTableProps) => {
|
|
17
|
+
declare const useTable: ({ tableBorderColor, data, isPagination, selections, onSelection, tablePreferences, savePreferences, noOfRowsPerPage, isServerPagination, totalRecords, columns, onNoOfRowsPerPageChange, defaultVisibleColumns, }: UseTableProps) => {
|
|
17
18
|
tableData: DataObject[];
|
|
18
19
|
tableContainerStyles: {
|
|
19
20
|
borderRadius: string;
|
|
@@ -41,5 +42,6 @@ declare const useTable: ({ tableBorderColor, data, isPagination, selections, onS
|
|
|
41
42
|
setCurrentPage: import("react").Dispatch<import("react").SetStateAction<number>>;
|
|
42
43
|
columnsList: TableHeaderProps[];
|
|
43
44
|
handleColumnPreferences: (columns: any) => void;
|
|
45
|
+
isSelecting: boolean;
|
|
44
46
|
};
|
|
45
47
|
export default useTable;
|
|
@@ -38,7 +38,7 @@ var mergeColumnWithPreference = function (pref, originalCol) {
|
|
|
38
38
|
return next;
|
|
39
39
|
};
|
|
40
40
|
var useTable = function (_a) {
|
|
41
|
-
var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, onSelection = _a.onSelection, tablePreferences = _a.tablePreferences, savePreferences = _a.savePreferences, noOfRowsPerPage = _a.noOfRowsPerPage, isServerPagination = _a.isServerPagination, totalRecords = _a.totalRecords, columns = _a.columns, onNoOfRowsPerPageChange = _a.onNoOfRowsPerPageChange;
|
|
41
|
+
var tableBorderColor = _a.tableBorderColor, data = _a.data, isPagination = _a.isPagination, selections = _a.selections, onSelection = _a.onSelection, tablePreferences = _a.tablePreferences, savePreferences = _a.savePreferences, noOfRowsPerPage = _a.noOfRowsPerPage, isServerPagination = _a.isServerPagination, totalRecords = _a.totalRecords, columns = _a.columns, onNoOfRowsPerPageChange = _a.onNoOfRowsPerPageChange, defaultVisibleColumns = _a.defaultVisibleColumns;
|
|
42
42
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
43
43
|
var headerRefs = (0, react_1.useRef)([]);
|
|
44
44
|
var _b = (0, react_1.useState)([]), columnWidths = _b[0], setColumnWidths = _b[1];
|
|
@@ -55,7 +55,10 @@ var useTable = function (_a) {
|
|
|
55
55
|
}
|
|
56
56
|
var tableData = data;
|
|
57
57
|
var _g = (0, react_1.useState)(function () {
|
|
58
|
-
return columns.map(function (col
|
|
58
|
+
return columns.map(function (col, i) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (__assign(__assign({}, col), { isHidden: defaultVisibleColumns ? i >= defaultVisibleColumns : ((_a = col.isHidden) !== null && _a !== void 0 ? _a : false) }));
|
|
61
|
+
});
|
|
59
62
|
}), columnsList = _g[0], setColumnsList = _g[1];
|
|
60
63
|
(0, react_1.useEffect)(function () {
|
|
61
64
|
var _a;
|
|
@@ -70,9 +73,12 @@ var useTable = function (_a) {
|
|
|
70
73
|
setColumnsList(mergedColumns);
|
|
71
74
|
}
|
|
72
75
|
else {
|
|
73
|
-
setColumnsList(columns.map(function (col
|
|
76
|
+
setColumnsList(columns.map(function (col, i) {
|
|
77
|
+
var _a;
|
|
78
|
+
return (__assign(__assign({}, col), { isHidden: defaultVisibleColumns ? i >= defaultVisibleColumns : ((_a = col.isHidden) !== null && _a !== void 0 ? _a : false) }));
|
|
79
|
+
}));
|
|
74
80
|
}
|
|
75
|
-
}, [tablePreferences, columns]);
|
|
81
|
+
}, [tablePreferences, columns, defaultVisibleColumns]);
|
|
76
82
|
var tableContainerStyles = (0, react_1.useMemo)(function () {
|
|
77
83
|
var _a;
|
|
78
84
|
return ({
|
|
@@ -139,25 +145,36 @@ var useTable = function (_a) {
|
|
|
139
145
|
(0, react_1.useEffect)(function () {
|
|
140
146
|
setSelection(selections !== null && selections !== void 0 ? selections : []);
|
|
141
147
|
}, [selections]);
|
|
148
|
+
var _h = (0, react_1.useState)(false), isSelecting = _h[0], setIsSelecting = _h[1];
|
|
149
|
+
var selectionRef = (0, react_1.useRef)(selection);
|
|
150
|
+
selectionRef.current = selection;
|
|
151
|
+
var onSelectionRef = (0, react_1.useRef)(onSelection);
|
|
152
|
+
onSelectionRef.current = onSelection;
|
|
142
153
|
var handleCheckbox = (0, react_1.useCallback)(function (id) {
|
|
143
|
-
var
|
|
154
|
+
var _a;
|
|
155
|
+
var current = selectionRef.current;
|
|
144
156
|
if (id === 0) {
|
|
145
|
-
|
|
146
|
-
|
|
157
|
+
setIsSelecting(true);
|
|
158
|
+
setTimeout(function () {
|
|
159
|
+
var _a;
|
|
160
|
+
var selectedItems = current.length === tableData.length ? [] : tableData.map(function (item) { return item.id; });
|
|
161
|
+
setSelection(selectedItems);
|
|
162
|
+
(_a = onSelectionRef.current) === null || _a === void 0 ? void 0 : _a.call(onSelectionRef, selectedItems);
|
|
163
|
+
setIsSelecting(false);
|
|
164
|
+
}, 0);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
var selectedItems = void 0;
|
|
168
|
+
if (current.includes(id)) {
|
|
169
|
+
selectedItems = current.filter(function (item) { return item !== id; });
|
|
147
170
|
}
|
|
148
171
|
else {
|
|
149
|
-
selectedItems =
|
|
172
|
+
selectedItems = __spreadArray(__spreadArray([], current, true), [id], false);
|
|
150
173
|
}
|
|
174
|
+
setSelection(selectedItems);
|
|
175
|
+
(_a = onSelectionRef.current) === null || _a === void 0 ? void 0 : _a.call(onSelectionRef, selectedItems);
|
|
151
176
|
}
|
|
152
|
-
|
|
153
|
-
selectedItems = selection.filter(function (item) { return item !== id; });
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
selectedItems = __spreadArray(__spreadArray([], selection, true), [id], false);
|
|
157
|
-
}
|
|
158
|
-
setSelection(selectedItems);
|
|
159
|
-
onSelection && onSelection(selectedItems);
|
|
160
|
-
}, [onSelection, selection, tableData]);
|
|
177
|
+
}, [tableData]);
|
|
161
178
|
var handleColumnPreferences = function (columns) {
|
|
162
179
|
setColumnsList(columns);
|
|
163
180
|
savePreferences &&
|
|
@@ -184,6 +201,7 @@ var useTable = function (_a) {
|
|
|
184
201
|
setCurrentPage: setCurrentPage,
|
|
185
202
|
columnsList: columnsList,
|
|
186
203
|
handleColumnPreferences: handleColumnPreferences,
|
|
204
|
+
isSelecting: isSelecting,
|
|
187
205
|
};
|
|
188
206
|
};
|
|
189
207
|
exports.default = useTable;
|
|
@@ -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, minVisibleRows, maxVisibleRows, autoFitViewport, tableSettings, filterSidebar, loadingSkeletonRows }: 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, loadingSkeletonRows, defaultVisibleColumns, }: TableProps): React.JSX.Element;
|
|
@@ -65,9 +65,7 @@ function Table(_a) {
|
|
|
65
65
|
name: "",
|
|
66
66
|
page: "",
|
|
67
67
|
orgId: "",
|
|
68
|
-
} : _4, _5 = _a.paginationMode, paginationMode = _5 === void 0 ? "client" : _5, _6 = _a.noOfRowsPerPage, noOfRowsPerPage = _6 === void 0 ? 50 : _6, _7 = _a.totalRecords, totalRecords = _7 === void 0 ? 0 : _7, onPagination = _a.onPagination, _8 = _a.isTableSettings, isTableSettings = _8 === void 0 ? false : _8, 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, loadingSkeletonRows = _a.loadingSkeletonRows
|
|
69
|
-
// onColumnFilter
|
|
70
|
-
;
|
|
68
|
+
} : _4, _5 = _a.paginationMode, paginationMode = _5 === void 0 ? "client" : _5, _6 = _a.noOfRowsPerPage, noOfRowsPerPage = _6 === void 0 ? 50 : _6, _7 = _a.totalRecords, totalRecords = _7 === void 0 ? 0 : _7, onPagination = _a.onPagination, _8 = _a.isTableSettings, isTableSettings = _8 === void 0 ? false : _8, 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, loadingSkeletonRows = _a.loadingSkeletonRows, defaultVisibleColumns = _a.defaultVisibleColumns;
|
|
71
69
|
var theme = (0, useCustomTheme_1.useCustomTheme)();
|
|
72
70
|
var _9 = (0, react_1.useState)({}), columnsSearch = _9[0], setColumnsSearch = _9[1];
|
|
73
71
|
var tableContainerRef = (0, react_1.useRef)(null);
|
|
@@ -113,7 +111,8 @@ function Table(_a) {
|
|
|
113
111
|
totalRecords: totalRecords,
|
|
114
112
|
isServerPagination: isServerPagination,
|
|
115
113
|
onNoOfRowsPerPageChange: onNoOfRowsPerPageChange,
|
|
116
|
-
|
|
114
|
+
defaultVisibleColumns: defaultVisibleColumns,
|
|
115
|
+
}), tableData = _13.tableData, isContent = _13.isContent, isLink = _13.isLink, headerRefs = _13.headerRefs, columnWidths = _13.columnWidths, handleSort = _13.handleSort, handleCheckbox = _13.handleCheckbox, filteredData = _13.filteredData, startRow = _13.startRow, endRow = _13.endRow, selection = _13.selection, columnsSort = _13.columnsSort, currentPage = _13.currentPage, pages = _13.pages, rowsPerPage = _13.rowsPerPage, handlePageSizeChange = _13.handlePageSizeChange, setCurrentPage = _13.setCurrentPage, columnsList = _13.columnsList, handleColumnPreferences = _13.handleColumnPreferences, isSelecting = _13.isSelecting;
|
|
117
116
|
var _filteredData = (0, react_1.useMemo)(function () {
|
|
118
117
|
return (0, table_1.searchAndSortData)(filteredData, columnsSearch);
|
|
119
118
|
}, [columnsSearch, filteredData]);
|
|
@@ -275,7 +274,7 @@ function Table(_a) {
|
|
|
275
274
|
? true
|
|
276
275
|
: selection.length === 0
|
|
277
276
|
? false
|
|
278
|
-
: "indeterminate", isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze, setColumnsSearch: setColumnsSearch, columnsSearch: columnsSearch })),
|
|
277
|
+
: "indeterminate", isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze, setColumnsSearch: setColumnsSearch, columnsSearch: columnsSearch, isSelecting: isSelecting })),
|
|
279
278
|
react_1.default.createElement(react_3.Tbody, null,
|
|
280
279
|
react_1.default.createElement(TableBody_1.default, { data: _filteredData, columns: columnsList, startRow: startRow, endRow: endRow, isCheckbox: isCheckbox, columnWidths: columnWidths, noBorders: noBorders, freezedBgColor: freezedBgColor !== null && freezedBgColor !== void 0 ? freezedBgColor : theme.colors.backgroundColor.secondary, freezedTextColor: freezedTextColor !== null && freezedTextColor !== void 0 ? freezedTextColor : (_z = theme.colors) === null || _z === void 0 ? void 0 : _z.gray[600], handleCheckbox: handleCheckbox, selections: selection, isLoading: isTableLoading, loadingSkeletonRows: loadingSkeletonRows, onRowClick: onRowClick, isContent: isContent, isLink: isLink, isActionFreeze: isActionFreeze }))))))));
|
|
281
280
|
}
|
|
@@ -30,6 +30,7 @@ export type TableProps = {
|
|
|
30
30
|
minVisibleRows?: number;
|
|
31
31
|
maxVisibleRows?: number;
|
|
32
32
|
autoFitViewport?: boolean;
|
|
33
|
+
defaultVisibleColumns?: number;
|
|
33
34
|
loadingSkeletonRows?: number;
|
|
34
35
|
headerActions?: HeaderActionsProps;
|
|
35
36
|
onGlobalSearch?: (searchVal: string) => void;
|
|
@@ -107,6 +108,7 @@ export type TableHeaderPageProps = Pick<TableProps, "columns" | "isCheckbox" | "
|
|
|
107
108
|
isLink: boolean;
|
|
108
109
|
setColumnsSearch: React.Dispatch<React.SetStateAction<Record<string, string>>>;
|
|
109
110
|
columnsSearch: Record<string, string>;
|
|
111
|
+
isSelecting?: boolean;
|
|
110
112
|
};
|
|
111
113
|
export type TableBodyPageProps = Pick<TableProps, "columns" | "isCheckbox" | "data" | "freezedBgColor" | "freezedTextColor" | "noBorders" | "isLoading" | "loadingSkeletonRows" | "onRowClick" | "isActionFreeze"> & {
|
|
112
114
|
startRow: number;
|