# All files / src/Overlay Overlay.tsx

17.39% Statements 4/23
0% Branches 0/11
0% Functions 0/2
21.05% Lines 4/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    701x
    1x
    1x

    1x

     import React from 'react'
    import { Portal } from '../Portal/Portal'
    import { Anchor, AnchorProps } from '../_hooks/Anchor'

    export interface OverlayProps extends AnchorProps {
      /**
       * @since 10.19.0
       */
      shrinkOverlay?: boolean
      /**
       * @since 10.19.0
       */
      container?: HTMLElement

      arrow?: boolean
    }

    /**
     * @deprecatedSince 11
     * @deprecated Intended for internal library development.
     */
    export const Overlay = React.forwardRef<HTMLElement, OverlayProps>(
      function Overlay(
        {
          canFlip = true,
          children,
          padding = 2,
          placement = 'bottom',
          shrinkOverlay = false,
          targetRef,
          container,
          isFlyout,
        },
        overlayRef
      ) {
        const ref =
          // eslint-disable-next-line react-hooks/rules-of-hooks
          (overlayRef as React.RefObject<HTMLElement>) || React.useRef(null)

        return (
          <Portal container={container}>
            <Anchor
              {...{
                canFlip,
                dependencies: [children],
                onLayout: (anchor) => {
                  Iif (!ref.current) {
                    return
                  }

                  const left = Math.floor(anchor.left)
                  const top = Math.floor(anchor.top)

                  ref.current.style.transform = `translateZ(0) translate(${left}px, ${top}px)`
                },
                overlayRef: ref,
                padding,
                placement,
                targetRef,
                shrinkOverlay,
                isFlyout,
              }}
            >
              {children}
            </Anchor>
          </Portal>
        )
      }
    )