23 lines
669 B
JavaScript
23 lines
669 B
JavaScript
import * as React from 'react';
|
|
/**
|
|
* 重置数组中所有 cell 的相对 left 的距离。
|
|
* @param cells
|
|
* @param extraWidth 额外为最后一个元素添加的的宽度,当存在纵向滚动条的时候设置。
|
|
*/
|
|
|
|
export default function resetLeftForCells(cells, extraWidth) {
|
|
var left = 0;
|
|
var nextCells = [];
|
|
|
|
for (var i = 0; i < cells.length; i++) {
|
|
var cell = cells[i];
|
|
var nextCell = /*#__PURE__*/React.cloneElement(cell, {
|
|
left: left,
|
|
width: i === cells.length - 1 && extraWidth ? cell.props.width + extraWidth : cell.props.width
|
|
});
|
|
left += cell.props.width;
|
|
nextCells.push(nextCell);
|
|
}
|
|
|
|
return nextCells;
|
|
} |