@carbon/ibm-products
Version:
Carbon for IBM Products
36 lines (32 loc) • 1.04 kB
JavaScript
/**
* 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.
*/
import { px } from '@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 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;
}
};
export { getSpreadsheetWidth };