@carbon/ibm-products
Version:
Carbon for IBM Products
33 lines (28 loc) • 1.24 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.
*/
;
var deepCloneObject = require('../../../global/js/utils/deepCloneObject.js');
// Determines if a row or column header cell should receive a highlight/active background color
// Check each object in selectionAreas and see if the headerIndex is between
// point1.row and point2.row, inclusive
const checkActiveHeaderCell = (headerIndex, selectionAreas, headerType) => {
const areasCloned = deepCloneObject.deepCloneObject(selectionAreas);
const activeRowIndexes = [];
areasCloned.forEach(area => {
const greatestRowIndex = Math.max(area.point1?.[headerType], area.point2?.[headerType]);
const lowestRowIndex = Math.min(area.point1?.[headerType], area.point2?.[headerType]);
for (let i = lowestRowIndex; i <= greatestRowIndex; i++) {
activeRowIndexes.push(i);
}
});
const activeRowIndexesNoDuplicates = [...new Set(activeRowIndexes)];
if (areasCloned?.length && activeRowIndexesNoDuplicates.includes(headerIndex)) {
return true;
}
return false;
};
exports.checkActiveHeaderCell = checkActiveHeaderCell;