@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.
@@ -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, { Color: 'alert-primary', Style: { marginBottom: 0, marginTop: '0.5em' } }, "Additional columns disabled due to table size.")
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
@@ -3,4 +3,5 @@ export interface IProps {
3
3
  Total: number;
4
4
  SetPage: (p: number) => void;
5
5
  }
6
- export default function (props: IProps): JSX.Element;
6
+ declare const Paging: (props: IProps) => JSX.Element;
7
+ export default Paging;
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
- function default_1(props) {
28
- const [pages, setPages] = React.useState([]);
29
- const nPages = 7;
30
- const minPg = React.useMemo(() => {
31
- const min = Math.min(...pages);
32
- if (isFinite(min) && !isNaN(min))
33
- return min;
34
- return 0;
35
- }, [pages]);
36
- const maxPg = React.useMemo(() => {
37
- const max = Math.max(...pages);
38
- if (isFinite(max) && !isNaN(max))
39
- return max;
40
- return 0;
41
- }, [pages]);
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 display = [];
44
- let p = Math.max(props.Current - Math.floor(nPages / 2), 1);
45
- if (props.Total - p < nPages)
46
- p = Math.max(props.Total - nPages + 1, 1);
47
- while (p <= props.Total && display.length < nPages) {
48
- display.push(p);
49
- p = p + 1;
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
- setPages(display);
52
- }, [props.Total, props.Current]);
53
- return React.createElement("ul", { className: "pagination justify-content-center" },
54
- React.createElement("li", { className: "page-item" + (minPg <= 1 ? ' disabled' : ""), key: "previous" },
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 (minPg > 1)
57
- props.SetPage(Math.max(props.Current - nPages, 1));
58
- } }, "Previous")),
59
- minPg > 2 ? React.createElement(React.Fragment, null,
60
- React.createElement("li", { className: "page-item", key: "1" },
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
- pages.map((p) => React.createElement("li", { className: "page-item" + (p == props.Current ? " active" : ""), key: p },
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
- maxPg + 2 <= props.Total ? React.createElement(React.Fragment, null,
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" + (maxPg == props.Total ? ' disabled' : ""), key: 'next' },
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 (maxPg < props.Total)
74
- props.SetPage(Math.min(props.Current + nPages, props.Total));
75
- } }, "Next")));
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;
@@ -189,32 +189,32 @@ function Table(props) {
189
189
  console.error("Could not find width object for Key: " + key);
190
190
  });
191
191
  }
192
- let remainingSpace = currentTableWidth;
193
- [...newMap.keys()].forEach(key => {
194
- const widthObj = newMap.get(key);
195
- if (widthObj != null) {
196
- if (widthObj.minWidth <= remainingSpace) {
197
- // This follows behavior consistent with MDN documentation on how these width types should behave
198
- if (widthObj.minWidth > widthObj.width)
199
- widthObj.width = widthObj.minWidth;
200
- if (widthObj.maxWidth != null && widthObj.minWidth > widthObj.maxWidth)
201
- widthObj.maxWidth = widthObj.minWidth;
202
- if (widthObj.maxWidth != null && widthObj.width > widthObj.maxWidth)
203
- widthObj.width = widthObj.maxWidth;
204
- // Constrain Width to remainingSpace
205
- if (widthObj.width > remainingSpace)
206
- widthObj.width = remainingSpace;
207
- remainingSpace -= widthObj.width;
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
- console.error("Could not find width object for Key: " + key);
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.66",
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.48",
47
- "@gpa-gemstone/helper-functions": "0.0.37",
48
- "@gpa-gemstone/react-interactive": "1.0.144",
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",