@gpa-gemstone/react-table 1.2.59 → 1.2.61

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.
@@ -17,6 +17,10 @@ interface ITableProps<T> extends ReactTableProps.ITable<T> {
17
17
  * The key used to store columns in local storage
18
18
  */
19
19
  LocalStorageKey?: string;
20
+ /**
21
+ * Optional flag to show helper alert for configuring table columns
22
+ */
23
+ ShowColumnHelper?: boolean;
20
24
  }
21
25
  /**
22
26
  * Table with modal to show and hide columns
@@ -35,6 +35,7 @@ const ConfigurableColumn_1 = require("./ConfigurableColumn");
35
35
  * Table with modal to show and hide columns
36
36
  */
37
37
  function ConfigurableTable(props) {
38
+ var _a;
38
39
  const getKeyMappings = () => {
39
40
  const u = new Map();
40
41
  React.Children.forEach(props.children, (element) => {
@@ -59,6 +60,7 @@ function ConfigurableTable(props) {
59
60
  const [hover, setHover] = React.useState(false);
60
61
  const [guid] = React.useState((0, helper_functions_1.CreateGuid)());
61
62
  const [widthDisabledAdd, setWidthDisabledAdd] = React.useState(false);
63
+ const [showHelperAlert, setShowHelperAlert] = React.useState(true);
62
64
  const handleReduceWidthCallback = React.useCallback((hiddenKeys) => {
63
65
  if (hiddenKeys.length !== 0) {
64
66
  setWidthDisabledAdd(true);
@@ -125,6 +127,7 @@ function ConfigurableTable(props) {
125
127
  return ((_a = c === null || c === void 0 ? void 0 : c.Default) !== null && _a !== void 0 ? _a : false) || isSort || isLocal;
126
128
  }
127
129
  return (React.createElement(React.Fragment, null,
130
+ ((_a = props.ShowColumnHelper) !== null && _a !== void 0 ? _a : false) ? React.createElement(react_interactive_1.Alert, { AlertColor: "alert-info", Show: showHelperAlert, SetShow: setShowHelperAlert }, "Use the gear at the far right of the header row to choose columns to show or hide.") : null,
128
131
  React.createElement(Table_1.Table, Object.assign({}, props, { LastColumn: React.createElement("div", { style: { marginLeft: -5, marginBottom: 12 }, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), id: guid + '-tooltip', onClick: () => setShowSettings(true) },
129
132
  React.createElement(gpa_symbols_1.ReactIcons.Settings, null)), ReduceWidthCallback: handleReduceWidthCallback }), React.Children.map(props.children, (element) => {
130
133
  var _a, _b;
@@ -76,6 +76,8 @@ const IsColumnAdjustable = (props) => {
76
76
  return propValue;
77
77
  return false;
78
78
  };
79
+ const scrollBarWidth = getScrollbarWidth();
80
+ const lastColumnWidth = 17;
79
81
  function Table(props) {
80
82
  const bodyRef = React.useRef(null);
81
83
  const colWidthsRef = React.useRef(new Map());
@@ -119,7 +121,7 @@ function Table(props) {
119
121
  if (React.isValidElement(element) && IsColumnProps(element.props)) {
120
122
  if (newMap.get(element.props.Key) != null)
121
123
  console.error("Multiple of the same key detected in table, this will cause issues.");
122
- newMap.set(element.props.Key, { minWidth: 10, maxWidth: 1000, width: 100 });
124
+ newMap.set(element.props.Key, { minWidth: 10, maxWidth: undefined, width: 100 });
123
125
  }
124
126
  });
125
127
  // If width is the same and keys are identical, we can skip the operation
@@ -162,11 +164,12 @@ function Table(props) {
162
164
  let autoSpace = currentTableWidth;
163
165
  measureKeys.forEach(key => {
164
166
  const element = document.getElementById(key + "_measurement");
165
- if (element != null) {
167
+ const elementWidth = element === null || element === void 0 ? void 0 : element.getBoundingClientRect().width;
168
+ if (elementWidth != null) {
166
169
  const widthObj = newMap.get(key);
167
170
  if (widthObj != null) {
168
- autoSpace -= element.clientWidth;
169
- widthObj[type] = element.clientWidth;
171
+ autoSpace -= elementWidth;
172
+ widthObj[type] = elementWidth;
170
173
  }
171
174
  else
172
175
  console.error("Could not find width object for Key: " + key);
@@ -177,7 +180,7 @@ function Table(props) {
177
180
  document.body.removeChild(widthsContainer);
178
181
  // Handle Autos (width type only)
179
182
  if (type === 'width' && autoKeys.length > 0) {
180
- const spacePerElement = Math.floor(autoSpace / autoKeys.length);
183
+ const spacePerElement = autoSpace / autoKeys.length;
181
184
  autoKeys.forEach(key => {
182
185
  const widthObj = newMap.get(key);
183
186
  if (widthObj != null)
@@ -194,9 +197,9 @@ function Table(props) {
194
197
  // This follows behavior consistent with MDN documentation on how these width types should behave
195
198
  if (widthObj.minWidth > widthObj.width)
196
199
  widthObj.width = widthObj.minWidth;
197
- if (widthObj.minWidth > widthObj.maxWidth)
200
+ if (widthObj.maxWidth != null && widthObj.minWidth > widthObj.maxWidth)
198
201
  widthObj.maxWidth = widthObj.minWidth;
199
- if (widthObj.width > widthObj.maxWidth)
202
+ if (widthObj.maxWidth != null && widthObj.width > widthObj.maxWidth)
200
203
  widthObj.width = widthObj.maxWidth;
201
204
  // Constrain Width to remainingSpace
202
205
  if (widthObj.width > remainingSpace)
@@ -223,12 +226,17 @@ function Table(props) {
223
226
  return;
224
227
  // Note: certain body classes may break this check if they set overflow to scroll
225
228
  let newScroll = false;
226
- if (((_a = props.TbodyStyle) === null || _a === void 0 ? void 0 : _a.overflowY) === 'scroll' || ((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflow) === 'scroll')
229
+ const dims = (_a = bodyRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); //use getBoundClientRect() to get un rounded values
230
+ if (((_b = props.TbodyStyle) === null || _b === void 0 ? void 0 : _b.overflowY) === 'scroll' || ((_c = props.TbodyStyle) === null || _c === void 0 ? void 0 : _c.overflow) === 'scroll')
227
231
  newScroll = true;
228
232
  else
229
- newScroll = bodyRef.current.clientHeight < bodyRef.current.scrollHeight;
233
+ newScroll = (dims === null || dims === void 0 ? void 0 : dims.height) < bodyRef.current.scrollHeight;
230
234
  setScrolled(newScroll);
231
- setCurrentTableWidth(((_d = (_c = bodyRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth) !== null && _d !== void 0 ? _d : 17) - (newScroll ? 0 : 17));
235
+ // Pick whichever is larger so we dont double subtract
236
+ const scrollbar = newScroll ? scrollBarWidth : 0;
237
+ const last = props.LastColumn !== undefined ? lastColumnWidth : 0;
238
+ const spacer = Math.max(scrollbar, last);
239
+ setCurrentTableWidth(((_d = dims.width) !== null && _d !== void 0 ? _d : 17) - spacer);
232
240
  }, 100), []);
233
241
  React.useEffect(() => {
234
242
  let resizeObserver;
@@ -258,7 +266,7 @@ function Table(props) {
258
266
  React.createElement("tr", { style: props.RowStyle !== undefined ? Object.assign({}, props.RowStyle) : {} }, props.LastRow))) : null));
259
267
  }
260
268
  function Rows(props) {
261
- const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { paddingRight: (props.BodyScrolled ? 0 : 17), display: "block" })), [props.BodyStyle, props.BodyScrolled]);
269
+ const bodyStyle = React.useMemo(() => (Object.assign(Object.assign({}, props.BodyStyle), { display: "block" })), [props.BodyStyle]);
262
270
  const onClick = React.useCallback((e, item, index) => {
263
271
  if (props.OnClick !== undefined)
264
272
  props.OnClick({
@@ -368,9 +376,9 @@ function Header(props) {
368
376
  if (widthObjLeft == null || widthObjRight == null)
369
377
  return ({ min: -Infinity, max: Infinity });
370
378
  const limitByShrinkLeft = widthObjLeft.width - widthObjLeft.minWidth;
371
- const limitByGrowthLeft = widthObjLeft.maxWidth - widthObjLeft.width;
379
+ const limitByGrowthLeft = widthObjLeft.maxWidth == null ? Number.MAX_SAFE_INTEGER : (widthObjLeft.maxWidth - widthObjLeft.width);
372
380
  const limitByShrinkRight = widthObjRight.width - widthObjRight.minWidth;
373
- const limitByGrowthRight = widthObjRight.maxWidth - widthObjRight.width;
381
+ const limitByGrowthRight = widthObjRight.maxWidth == null ? Number.MAX_SAFE_INTEGER : (widthObjRight.maxWidth - widthObjRight.width);
374
382
  // Recall that a left movement is a negative deltaW
375
383
  const minDeltaW = -(limitByShrinkLeft < limitByGrowthRight ? limitByShrinkLeft : limitByGrowthRight);
376
384
  const maxDeltaW = limitByShrinkRight < limitByGrowthLeft ? limitByShrinkRight : limitByGrowthLeft;
@@ -494,5 +502,22 @@ function Header(props) {
494
502
  ((_r = element.props.children) !== null && _r !== void 0 ? _r : element.props.Key),
495
503
  ' '));
496
504
  }),
497
- React.createElement("th", { style: { width: 17, padding: 0, maxWidth: 17 } }, props.LastColumn))));
505
+ props.LastColumn !== undefined ?
506
+ React.createElement("th", { style: { width: lastColumnWidth, padding: 0, maxWidth: lastColumnWidth } }, props.LastColumn)
507
+ : null)));
508
+ }
509
+ function getScrollbarWidth() {
510
+ // Creating invisible container
511
+ const outer = document.createElement('div');
512
+ outer.style.visibility = 'hidden';
513
+ outer.style.overflow = 'scroll'; // forcing scrollbar to appear
514
+ document.body.appendChild(outer);
515
+ // Creating inner element and placing it in the container
516
+ const inner = document.createElement('div');
517
+ outer.appendChild(inner);
518
+ // Calculating difference between container's full width and the child width
519
+ const scrollbarWidth = (outer.offsetWidth - inner.offsetWidth);
520
+ // Removing temporary elements from the DOM
521
+ outer.parentNode.removeChild(outer);
522
+ return scrollbarWidth;
498
523
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-table",
3
- "version": "1.2.59",
3
+ "version": "1.2.61",
4
4
  "description": "Table for GPA web applications",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "dependencies": {
46
46
  "@gpa-gemstone/gpa-symbols": "0.0.46",
47
47
  "@gpa-gemstone/helper-functions": "0.0.37",
48
- "@gpa-gemstone/react-interactive": "1.0.138",
48
+ "@gpa-gemstone/react-interactive": "1.0.139",
49
49
  "@types/lodash": "^4.14.171",
50
50
  "@types/react": "^17.0.14",
51
51
  "lodash": "^4.17.21",