UNPKG

@kubit-ui-web/react-components

Version:

Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience

45 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getHeight = void 0; // Set list options height when not use the ActionbottomSheet const getHeight = (element, limit) => { const REM_MEASURE = 16; let numItemsPrinted = 0; let listIndex = 0; let isTitle = true; let top = null; let bottom = null; for (let i = 0; i < limit; i++) { // check if there are no more items in the current list to loop through the next one if (!element[listIndex]?.children[i - numItemsPrinted]) { numItemsPrinted += element[listIndex]?.childElementCount; listIndex++; isTitle = true; } // check if list exists if (!element[listIndex]) { break; } // check if it's a title or list item and add its height if (element[listIndex].previousSibling && isTitle) { isTitle = false; numItemsPrinted++; if (top === null) { top = element[listIndex].previousSibling?.getBoundingClientRect().top; } bottom = element[listIndex].previousSibling?.getBoundingClientRect().bottom; } else { if (top === null) { top = element[listIndex].children[i - numItemsPrinted]?.getBoundingClientRect().top; } bottom = element[listIndex].children[i - numItemsPrinted]?.getBoundingClientRect().bottom; } } if (bottom !== null && top !== null) { return `${(bottom - top) / REM_MEASURE}rem`; } return '0rem'; }; exports.getHeight = getHeight; //# sourceMappingURL=height.js.map