# All files / src/Overlay OverlayArrow.tsx

100% Statements 9/9
90% Branches 18/20
100% Functions 1/1
100% Lines 8/8

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
    59x
    59x

    59x
    17x
    17x

    17x
    17x

    17x

     import { MiddlewareData } from '@floating-ui/react-dom'
    import React from 'react'
    import { arrowSize, StyledArrow } from './OverlayArrow.styles'
    import { OverlayPlacement } from './useOverlay'

    interface ArrowProps {
      placement: OverlayPlacement
      x?: number
      y?: number
      arrow: MiddlewareData['arrow']
    }

    export const Arrow = React.forwardRef<HTMLDivElement, ArrowProps>(
      function Arrow({ placement, arrow }, ref) {
        const staticSide = {
          top: 'bottom',
          right: 'left',
          bottom: 'top',
          left: 'right',
        }[placement.split('-')[0]]

        const arrowX = arrow?.x ?? null
        const arrowY = arrow?.y ?? null

        return (
          <StyledArrow
            ref={ref}
            style={{
              position: 'absolute',
              left: arrowX !== null ? `${arrowX}px` : undefined,
              top: arrowY !== null ? `${arrowY}px` : undefined,
              right: '',
              bottom: '',
              [staticSide as string]: `-${arrowSize / 2}px`,
            }}
            data-overlay-arrow
          />
        )
      }
    )