UNPKG

1.07 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _react = require("react");
8/**
9 * Get sticky column offset width
10 */
11function useStickyOffsets(colWidths, flattenColumns, direction) {
12 var stickyOffsets = (0, _react.useMemo)(function () {
13 var columnCount = flattenColumns.length;
14 var getOffsets = function getOffsets(startIndex, endIndex, offset) {
15 var offsets = [];
16 var total = 0;
17 for (var i = startIndex; i !== endIndex; i += offset) {
18 offsets.push(total);
19 if (flattenColumns[i].fixed) {
20 total += colWidths[i] || 0;
21 }
22 }
23 return offsets;
24 };
25 var startOffsets = getOffsets(0, columnCount, 1);
26 var endOffsets = getOffsets(columnCount - 1, -1, -1).reverse();
27 return direction === 'rtl' ? {
28 left: endOffsets,
29 right: startOffsets
30 } : {
31 left: startOffsets,
32 right: endOffsets
33 };
34 }, [colWidths, flattenColumns, direction]);
35 return stickyOffsets;
36}
37var _default = exports.default = useStickyOffsets;
\No newline at end of file