UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

38 lines (33 loc) 1.09 kB
/** * Copyright IBM Corp. 2020, 2025 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; var layout = require('@carbon/layout'); const getSpreadsheetWidth = _ref => { let { type, headerGroup, scrollBarSizeValue, totalVisibleColumns, defaultColumn, totalColumnsWidth, visibleColumns } = _ref; const additionalWidth = scrollBarSizeValue + defaultColumn.rowHeaderWidth; if (!totalVisibleColumns) { if (type === 'header') { return layout.px(parseInt(headerGroup.getHeaderGroupProps().style.width) + additionalWidth); } if (type !== 'header') { return totalColumnsWidth + additionalWidth; } } if (totalVisibleColumns) { const totalVisibleColumnWidth = visibleColumns.map((item, index) => index <= totalVisibleColumns - 1 && (item?.width || defaultColumn?.width)).reduce((prev, curr) => prev + curr, 0); return totalVisibleColumnWidth + additionalWidth; } }; exports.getSpreadsheetWidth = getSpreadsheetWidth;