Split packages into platform and extensions
This commit is contained in:
1 parent
f175d4b96b
commit
e8969fba11
992 files changed
+2
-1
No files matched your search
@@ -0,0 +1,46 @@
|
||||
export default function bounding(elementRef, currentPosition = {}) {
|
||||
if (!elementRef.current) {
|
||||
return;
|
||||
}
|
||||
|
||||
const currentElement = elementRef.current;
|
||||
const {
|
||||
offsetParent,
|
||||
offsetTop,
|
||||
offsetHeight,
|
||||
offsetLeft,
|
||||
offsetWidth,
|
||||
} = currentElement;
|
||||
let top = currentPosition.top || offsetTop;
|
||||
let left = currentPosition.left || offsetLeft;
|
||||
|
||||
if (!offsetParent) {
|
||||
return;
|
||||
}
|
||||
|
||||
let maxHeight = `${offsetParent.offsetHeight}px`;
|
||||
|
||||
if (offsetHeight + top > offsetParent.offsetHeight) {
|
||||
top = top - (offsetHeight + top - offsetParent.offsetHeight);
|
||||
if (top < 0) {
|
||||
top = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (left + offsetWidth > offsetParent.offsetWidth) {
|
||||
left = offsetParent.offsetWidth - offsetWidth;
|
||||
if (left < 0) {
|
||||
left = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxHeight && currentElement.style.maxHeight !== maxHeight) {
|
||||
currentElement.style.maxHeight = maxHeight;
|
||||
}
|
||||
if (currentElement.style.top !== `${top}px`) {
|
||||
currentElement.style.top = `${top}px`;
|
||||
}
|
||||
if (currentElement.style.left !== `${left}px`) {
|
||||
currentElement.style.left = `${left}px`;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user