@awsui/components-react
Version:
AWS UI is a collection of [React](https://reactjs.org/) components that help create intuitive, responsive, and accessible user experiences for web applications. It is developed by Amazon Web Services (AWS). This work is available under the terms of the [A
45 lines (44 loc) • 1.52 kB
JavaScript
export var getOverflowParents = function (element) {
var parents = [];
var node = element;
while ((node = node.parentElement)) {
getComputedStyle(node).overflow !== 'visible' && parents.push(node);
}
return parents;
};
export var getOverflowParentDimensions = function (element, excludeClosestParent) {
if (excludeClosestParent === void 0) { excludeClosestParent = false; }
var parents = getOverflowParents(element).map(function (el) {
var _a = el.getBoundingClientRect(), height = _a.height, width = _a.width, top = _a.top, left = _a.left;
return {
height: height,
width: width,
top: top,
left: left
};
});
parents.push({
height: window.innerHeight,
width: window.innerWidth,
top: 0,
left: 0
});
if (excludeClosestParent) {
parents.shift();
}
return parents;
};
export function browserScrollbarSize() {
var scrollDiv = document.createElement('div');
scrollDiv.style.overflow = 'scroll';
scrollDiv.style.height = '100px';
scrollDiv.style.width = '100px';
scrollDiv.style.position = 'absolute';
scrollDiv.style.top = '-9999px';
scrollDiv.style.left = '-9999px';
document.body.appendChild(scrollDiv);
var width = scrollDiv.offsetWidth - scrollDiv.clientWidth;
var height = scrollDiv.offsetHeight - scrollDiv.clientHeight;
document.body.removeChild(scrollDiv);
return { width: width, height: height };
}