@cashub/ui 0.38.1 → 0.38.3
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/package.json +1 -1
- package/table/InfiniteGridTable.js +11 -6
package/package.json
CHANGED
|
@@ -44,6 +44,7 @@ const InfiniteGridTable = _ref => {
|
|
|
44
44
|
const [tableColumns, setTableColumns] = (0, _react.useState)(columns);
|
|
45
45
|
const [tableWidth, setTableWidth] = (0, _react.useState)(0);
|
|
46
46
|
const [restWidth, setRestWidth] = (0, _react.useState)(0);
|
|
47
|
+
const [theadHeight, setTheadHeight] = (0, _react.useState)(0);
|
|
47
48
|
const texts = (0, _react.useMemo)(() => {
|
|
48
49
|
const defaultTexts = {
|
|
49
50
|
info: 'Showing _START_ to _END_ of _TOTAL_ entries',
|
|
@@ -52,17 +53,15 @@ const InfiniteGridTable = _ref => {
|
|
|
52
53
|
return _objectSpread(_objectSpread({}, defaultTexts), translation);
|
|
53
54
|
}, [translation]);
|
|
54
55
|
const tableHeight = (0, _react.useMemo)(() => {
|
|
55
|
-
var _tableHeadRef$current;
|
|
56
|
-
const theadHeight = ((_tableHeadRef$current = tableHeadRef.current) === null || _tableHeadRef$current === void 0 ? void 0 : _tableHeadRef$current.offsetHeight) || 0;
|
|
57
56
|
// when data is empty, table will generate a row to show a message
|
|
58
57
|
const rowCounts = data.length || 1;
|
|
59
58
|
return theadHeight + rowCounts * ROW_HEIGHT;
|
|
60
|
-
}, [data.length]);
|
|
59
|
+
}, [theadHeight, data.length]);
|
|
61
60
|
const visibleRowCounts = (0, _react.useMemo)(() => {
|
|
62
61
|
return Math.ceil(containerHeight / ROW_HEIGHT);
|
|
63
62
|
}, [containerHeight]);
|
|
64
63
|
const startIndex = (0, _react.useMemo)(() => {
|
|
65
|
-
const top =
|
|
64
|
+
const top = Math.max(0, scrollTop - wrapperTop);
|
|
66
65
|
return Math.max(0, Math.floor(top / ROW_HEIGHT) - OVER_SCAN_COUNT);
|
|
67
66
|
}, [wrapperTop, scrollTop]);
|
|
68
67
|
const endIndex = (0, _react.useMemo)(() => {
|
|
@@ -218,7 +217,7 @@ const InfiniteGridTable = _ref => {
|
|
|
218
217
|
backgroundReverse: backgroundReverse
|
|
219
218
|
}, 'rest'));
|
|
220
219
|
const index = rowIndex + startIndex;
|
|
221
|
-
const top = index * ROW_HEIGHT +
|
|
220
|
+
const top = index * ROW_HEIGHT + theadHeight;
|
|
222
221
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
223
222
|
"data-index": index,
|
|
224
223
|
style: {
|
|
@@ -229,7 +228,7 @@ const InfiniteGridTable = _ref => {
|
|
|
229
228
|
children: tds
|
|
230
229
|
}, index);
|
|
231
230
|
});
|
|
232
|
-
}, [backgroundReverse, tableColumns, visibleData, showFullValue, restWidth, startIndex]);
|
|
231
|
+
}, [backgroundReverse, tableColumns, visibleData, showFullValue, restWidth, startIndex, theadHeight]);
|
|
233
232
|
const generateEmptyMessage = (0, _react.useCallback)(() => {
|
|
234
233
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("tr", {
|
|
235
234
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(TD, {
|
|
@@ -257,6 +256,12 @@ const InfiniteGridTable = _ref => {
|
|
|
257
256
|
setTableWidth(tableRef.current.offsetWidth);
|
|
258
257
|
}
|
|
259
258
|
}, [columns]);
|
|
259
|
+
(0, _react.useLayoutEffect)(() => {
|
|
260
|
+
if (tableHeadRef.current) {
|
|
261
|
+
const theadHeight = tableHeadRef.current.offsetHeight;
|
|
262
|
+
setTheadHeight(theadHeight);
|
|
263
|
+
}
|
|
264
|
+
}, []);
|
|
260
265
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
261
266
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(TableWrapper, {
|
|
262
267
|
style: {
|