How to use the evergreen-ui/esm/positioner/src/getPosition function in evergreen-ui

To help you get started, we’ve selected a few evergreen-ui examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / Spoke / src / ui / onboarding / OnboardingPopover.js View on Github external
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)`
    });
  }