Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
updatePosition(targetEl) {
if (!targetEl) return;
const { position, padding } = this.props;
const popoverRect = this.popoverRef.current.getBoundingClientRect();
const targetRect = targetEl.getBoundingClientRect();
const viewportHeight = document.documentElement.clientHeight;
const viewportWidth = document.documentElement.clientWidth;
const { rect, position: finalPosition, transformOrigin } = getPosition({
position,
targetRect,
targetOffset: padding,
dimensions: { width: popoverRect.width, height: popoverRect.height },
viewport: { width: viewportWidth, height: viewportHeight },
viewportOffset: padding
});
this.setState({
finalPosition,
transformOrigin,
transform: `translate(${rect.left}px, ${rect.top}px)`
});
}