@schema-render/search-react
Version:
Conditional search component based on FormRender.
28 lines (27 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "calcCollapsedNumber", {
enumerable: true,
get: function() {
return calcCollapsedNumber;
}
});
function calcCollapsedNumber(container, collapsedRows, customAlgo) {
var _container_firstElementChild_getBoundingClientRect, _container_firstElementChild;
// 采用自定义算法
if (customAlgo) {
return customAlgo(container);
}
// 容器不存在,返回兜底默认值
if (!container) {
return 5;
}
// 容器宽度
var containerWidth = container.clientWidth;
// 子节点宽度,取最大值,即 Bounding 宽度
var childWidth = ((_container_firstElementChild = container.firstElementChild) === null || _container_firstElementChild === void 0 ? void 0 : (_container_firstElementChild_getBoundingClientRect = _container_firstElementChild.getBoundingClientRect()) === null || _container_firstElementChild_getBoundingClientRect === void 0 ? void 0 : _container_firstElementChild_getBoundingClientRect.width) || 320;
// 计算折叠个数算法,以第一个子节点宽度作为计算基数
return Math.floor(containerWidth / childWidth) * collapsedRows - 1;
}