@gpa-gemstone/react-table 1.2.66 → 1.2.67
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/lib/ConfigurableTable/ConfigurableTable.js +1 -1
- package/lib/Paging.d.ts +2 -1
- package/lib/Paging.js +82 -40
- package/lib/Table/Table.js +25 -25
- package/package.json +4 -4
|
@@ -186,6 +186,6 @@ function ColumnSelection(props) {
|
|
|
186
186
|
? 'The Table is currently sorted by this column so it cannot be hidden.'
|
|
187
187
|
: undefined })) : null))),
|
|
188
188
|
props.disableAdd ?
|
|
189
|
-
React.createElement(react_interactive_1.Alert, {
|
|
189
|
+
React.createElement(react_interactive_1.Alert, { Class: 'alert-primary', Style: { marginBottom: 0, marginTop: '0.5em' } }, "Additional columns disabled due to table size.")
|
|
190
190
|
: null));
|
|
191
191
|
}
|
package/lib/Paging.d.ts
CHANGED
package/lib/Paging.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.default = default_1;
|
|
4
3
|
// ******************************************************************************************************
|
|
5
4
|
// Paging.tsx - Gbtc
|
|
6
5
|
//
|
|
@@ -23,54 +22,97 @@ exports.default = default_1;
|
|
|
23
22
|
// Generated original version of source code.
|
|
24
23
|
//
|
|
25
24
|
// ******************************************************************************************************
|
|
25
|
+
const gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
26
|
+
const helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
26
27
|
const React = require("react");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
const defaultMaxPagesToShow = 7;
|
|
29
|
+
const Paging = (props) => {
|
|
30
|
+
const containerRef = React.useRef(null);
|
|
31
|
+
const { scrollWidth, width } = (0, helper_functions_1.useGetContainerPosition)(containerRef);
|
|
32
|
+
const [pagesToShow, setPagesToShow] = React.useState([]);
|
|
33
|
+
const [maxPagesToShow, setMaxPagesToShow] = React.useState(defaultMaxPagesToShow);
|
|
34
|
+
const minPageToShow = React.useMemo(() => {
|
|
35
|
+
const min = Math.min(...pagesToShow);
|
|
36
|
+
if (!isFinite(min) || isNaN(min))
|
|
37
|
+
return 0;
|
|
38
|
+
return min;
|
|
39
|
+
}, [pagesToShow]);
|
|
40
|
+
const maxPageToShow = React.useMemo(() => {
|
|
41
|
+
const max = Math.max(...pagesToShow);
|
|
42
|
+
if (!isFinite(max) || isNaN(max))
|
|
43
|
+
return 0;
|
|
44
|
+
return max;
|
|
45
|
+
}, [pagesToShow]);
|
|
42
46
|
React.useEffect(() => {
|
|
43
|
-
const
|
|
44
|
-
let
|
|
45
|
-
if (props.Total -
|
|
46
|
-
|
|
47
|
-
while (
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
const newPagesToShow = [];
|
|
48
|
+
let startPage = Math.max(props.Current - Math.floor(maxPagesToShow / 2), 1);
|
|
49
|
+
if (props.Total - startPage < maxPagesToShow)
|
|
50
|
+
startPage = Math.max(props.Total - maxPagesToShow + 1, 1);
|
|
51
|
+
while (startPage <= props.Total && newPagesToShow.length < maxPagesToShow) {
|
|
52
|
+
newPagesToShow.push(startPage);
|
|
53
|
+
startPage = startPage + 1;
|
|
50
54
|
}
|
|
51
|
-
|
|
52
|
-
}, [props.Total, props.Current]);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
setPagesToShow(newPagesToShow);
|
|
56
|
+
}, [props.Total, props.Current, width, scrollWidth, maxPagesToShow]);
|
|
57
|
+
//Effect to decrement maxPagesToShow if we are overflowing
|
|
58
|
+
React.useLayoutEffect(() => {
|
|
59
|
+
if (scrollWidth > width)
|
|
60
|
+
setMaxPagesToShow(prev => Math.max(prev - 1, 1));
|
|
61
|
+
}, [width, scrollWidth]);
|
|
62
|
+
//Effect to increment maxPagesToShow if we have enough space
|
|
63
|
+
React.useLayoutEffect(() => {
|
|
64
|
+
if (maxPagesToShow >= defaultMaxPagesToShow || containerRef.current == null)
|
|
65
|
+
return;
|
|
66
|
+
const childArray = Array.from(containerRef.current.children);
|
|
67
|
+
// Sum widths of all <li> elements
|
|
68
|
+
const trueWidth = childArray.reduce((sum, child) => sum + child.offsetWidth, 0);
|
|
69
|
+
const availableWidth = width - trueWidth;
|
|
70
|
+
const estimatedButtonWidthWithTolerance = 50;
|
|
71
|
+
if (availableWidth >= estimatedButtonWidthWithTolerance)
|
|
72
|
+
setMaxPagesToShow(prev => Math.min(defaultMaxPagesToShow, prev + 1));
|
|
73
|
+
}, [width, maxPagesToShow]);
|
|
74
|
+
const showLeftBlock = maxPagesToShow < defaultMaxPagesToShow
|
|
75
|
+
? minPageToShow !== 1
|
|
76
|
+
: minPageToShow > 2;
|
|
77
|
+
const showRightBlock = maxPagesToShow < defaultMaxPagesToShow
|
|
78
|
+
? maxPageToShow !== props.Total
|
|
79
|
+
: maxPageToShow + 2 <= props.Total;
|
|
80
|
+
return (React.createElement("ul", { className: "pagination justify-content-center", ref: containerRef },
|
|
81
|
+
React.createElement("li", { className: "page-item" + (minPageToShow <= 1 ? ' disabled' : ""), key: "previous", style: { cursor: 'pointer' } },
|
|
55
82
|
React.createElement("a", { className: "page-link", onClick: () => {
|
|
56
|
-
if (
|
|
57
|
-
props.SetPage(Math.max(props.Current -
|
|
58
|
-
} },
|
|
59
|
-
|
|
60
|
-
|
|
83
|
+
if (minPageToShow > 1)
|
|
84
|
+
props.SetPage(Math.max(props.Current - defaultMaxPagesToShow, 1));
|
|
85
|
+
} },
|
|
86
|
+
React.createElement(gpa_symbols_1.ReactIcons.DoubleChevronLeft, { Size: 15 }))),
|
|
87
|
+
React.createElement("li", { className: "page-item" + (props.Current <= 1 ? ' disabled' : ""), key: "step-previous", style: { cursor: 'pointer' } },
|
|
88
|
+
React.createElement("a", { className: "page-link", onClick: () => {
|
|
89
|
+
if (props.Current > 1)
|
|
90
|
+
props.SetPage(props.Current - 1);
|
|
91
|
+
} },
|
|
92
|
+
React.createElement(gpa_symbols_1.ReactIcons.ChevronLeft, { Size: 15 }))),
|
|
93
|
+
showLeftBlock ? React.createElement(React.Fragment, null,
|
|
94
|
+
React.createElement("li", { className: "page-item", key: "1", style: { cursor: 'pointer' } },
|
|
61
95
|
React.createElement("a", { className: "page-link", onClick: () => props.SetPage(1) }, "1")),
|
|
62
96
|
React.createElement("li", { className: "page-item disabled", key: "skip-1" },
|
|
63
97
|
React.createElement("a", { className: "page-link" }, "..."))) : null,
|
|
64
|
-
|
|
98
|
+
pagesToShow.map((p) => React.createElement("li", { className: "page-item" + (p == props.Current ? " active" : ""), key: p, style: { cursor: 'pointer' } },
|
|
65
99
|
React.createElement("a", { className: "page-link", onClick: () => props.SetPage(p) }, p))),
|
|
66
|
-
|
|
100
|
+
showRightBlock ? React.createElement(React.Fragment, null,
|
|
67
101
|
React.createElement("li", { className: "page-item disabled", key: "skip-2" },
|
|
68
102
|
React.createElement("a", { className: "page-link" }, "...")),
|
|
69
|
-
React.createElement("li", { className: "page-item", key: props.Total },
|
|
103
|
+
React.createElement("li", { className: "page-item", key: props.Total, style: { cursor: 'pointer' } },
|
|
70
104
|
React.createElement("a", { className: "page-link", onClick: () => props.SetPage(props.Total) }, props.Total))) : null,
|
|
71
|
-
React.createElement("li", { className: "page-item" + (
|
|
105
|
+
React.createElement("li", { className: "page-item" + (props.Current >= props.Total ? ' disabled' : ""), key: "step-next", style: { cursor: 'pointer' } },
|
|
106
|
+
React.createElement("a", { className: "page-link", onClick: () => {
|
|
107
|
+
if (props.Current < props.Total)
|
|
108
|
+
props.SetPage(props.Current + 1);
|
|
109
|
+
} },
|
|
110
|
+
React.createElement(gpa_symbols_1.ReactIcons.ChevronRight, { Size: 15 }))),
|
|
111
|
+
React.createElement("li", { className: "page-item" + (maxPageToShow == props.Total ? ' disabled' : ""), key: 'next', style: { cursor: 'pointer' } },
|
|
72
112
|
React.createElement("a", { className: "page-link", onClick: () => {
|
|
73
|
-
if (
|
|
74
|
-
props.SetPage(Math.min(props.Current +
|
|
75
|
-
} },
|
|
76
|
-
}
|
|
113
|
+
if (maxPageToShow < props.Total)
|
|
114
|
+
props.SetPage(Math.min(props.Current + defaultMaxPagesToShow, props.Total));
|
|
115
|
+
} },
|
|
116
|
+
React.createElement(gpa_symbols_1.ReactIcons.DoubleChevronRight, { Size: 15 })))));
|
|
117
|
+
};
|
|
118
|
+
exports.default = Paging;
|
package/lib/Table/Table.js
CHANGED
|
@@ -189,32 +189,32 @@ function Table(props) {
|
|
|
189
189
|
console.error("Could not find width object for Key: " + key);
|
|
190
190
|
});
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
else {
|
|
210
|
-
widthObj.minWidth = 0;
|
|
211
|
-
widthObj.width = 0;
|
|
212
|
-
widthObj.maxWidth = 0;
|
|
213
|
-
}
|
|
192
|
+
});
|
|
193
|
+
let remainingSpace = currentTableWidth;
|
|
194
|
+
[...newMap.keys()].forEach(key => {
|
|
195
|
+
const widthObj = newMap.get(key);
|
|
196
|
+
if (widthObj != null) {
|
|
197
|
+
if (widthObj.minWidth <= remainingSpace) {
|
|
198
|
+
// This follows behavior consistent with MDN documentation on how these width types should behave
|
|
199
|
+
if (widthObj.minWidth > widthObj.width)
|
|
200
|
+
widthObj.width = widthObj.minWidth;
|
|
201
|
+
if (widthObj.maxWidth != null && widthObj.minWidth > widthObj.maxWidth)
|
|
202
|
+
widthObj.maxWidth = widthObj.minWidth;
|
|
203
|
+
if (widthObj.maxWidth != null && widthObj.width > widthObj.maxWidth)
|
|
204
|
+
widthObj.width = widthObj.maxWidth;
|
|
205
|
+
// Constrain Width to remainingSpace
|
|
206
|
+
if (widthObj.width > remainingSpace)
|
|
207
|
+
widthObj.width = remainingSpace;
|
|
208
|
+
remainingSpace -= widthObj.width;
|
|
214
209
|
}
|
|
215
|
-
else
|
|
216
|
-
|
|
217
|
-
|
|
210
|
+
else {
|
|
211
|
+
widthObj.minWidth = 0;
|
|
212
|
+
widthObj.width = 0;
|
|
213
|
+
widthObj.maxWidth = 0;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else
|
|
217
|
+
console.error("Could not find width object for Key: " + key);
|
|
218
218
|
});
|
|
219
219
|
colWidthsRef.current = newMap;
|
|
220
220
|
oldWidthRef.current = currentTableWidth;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gpa-gemstone/react-table",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.67",
|
|
4
4
|
"description": "Table for GPA web applications",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"typescript": "5.5.3"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@gpa-gemstone/gpa-symbols": "0.0.
|
|
47
|
-
"@gpa-gemstone/helper-functions": "0.0.
|
|
48
|
-
"@gpa-gemstone/react-interactive": "1.0.
|
|
46
|
+
"@gpa-gemstone/gpa-symbols": "0.0.49",
|
|
47
|
+
"@gpa-gemstone/helper-functions": "0.0.38",
|
|
48
|
+
"@gpa-gemstone/react-interactive": "1.0.145",
|
|
49
49
|
"@types/lodash": "^4.14.171",
|
|
50
50
|
"@types/react": "^17.0.14",
|
|
51
51
|
"lodash": "^4.17.21",
|