Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
calcOverlayPosition(placement, overlayNode, target, container, padding) {
const childOffset = utils.getPosition(target, container);
const { height: overlayHeight, width: overlayWidth } = getOffset(overlayNode);
let positionLeft, positionTop, arrowOffsetLeft, arrowOffsetTop;
if (placement === 'left' || placement === 'right') {
positionTop = childOffset.top + (childOffset.height - overlayHeight) / 2;
if (placement === 'left') {
positionLeft = childOffset.left - overlayWidth;
} else {
positionLeft = childOffset.left + childOffset.width;
}
const topDelta = getTopDelta(positionTop, overlayHeight, container, padding);
positionTop += topDelta;
arrowOffsetTop = 50 * (1 - 2 * topDelta / overlayHeight) + '%';
updatePosition(event: React.MouseEvent) {
const { vertical, min, locale } = this.props;
const barOffset = getOffset(this.barRef.current);
const offset = vertical ? event.pageY - barOffset.top : event.pageX - barOffset.left;
const value = locale.rtl && !vertical ? barOffset.width - offset : offset;
this.setValue(this.calculateValue(value) + min);
}
setTimeout(() => {
this.bar &&
this.setState({
barOffset: getOffset(this.bar)
});
}, 1);
}
getValueByPosition = (event: React.MouseEvent) => {
const { vertical, min, locale } = this.props;
const barOffset = getOffset(this.barRef.current);
const offset = vertical ? event.pageY - barOffset.top : event.pageX - barOffset.left;
const value = locale.rtl && !vertical ? barOffset.width - offset : offset;
return this.getValueByOffset(value) + min;
};
this.setState(() => {
return { affixHeaderOffset: getOffset(this.headerWrapper) };
});
}
getContainerDimensions(containerNode) {
let width, height, scroll;
if (containerNode.tagName === 'BODY') {
width = window.innerWidth;
height = window.innerHeight;
scroll = scrollTop(ownerDocument(containerNode).documentElement) || scrollTop(containerNode);
} else {
({ width, height } = getOffset(containerNode));
scroll = scrollTop(containerNode);
}
return { width, height, scroll };
},
this.setState(() => {
return { offset: getOffset(this.containerRef.current) };
});
};
getPosition = (event: React.MouseEvent) => {
const offset = getOffset(this.triggerRef.current);
const offsetX = (event.pageX || 0) - offset.left;
const offsetY = (event.pageY || 0) - offset.top;
const radiusX = Math.max(offset.width - offsetX, offsetX);
const radiusY = Math.max(offset.height - offsetY, offsetY);
const radius = Math.sqrt(Math.pow(radiusX, 2) + Math.pow(radiusY, 2));
return {
width: radius * 2,
height: radius * 2,
left: offsetX - radius,
top: offsetY - radius
};
};