# All files / src/ToolHeader ActionIcon.tsx

30% Statements 6/20
0% Branches 0/4
0% Functions 0/3
40% Lines 6/15

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
    702x
    2x
    2x

    2x

    2x

    2x

     import React from 'react'
    import { StyledAnchor, StyledUnstyledButton } from '../Semantic/Semantic.styles'
    import { Tooltip } from '../Tooltip/Tooltip'
    import {
      ActionIconPolyType,
      ActionIconProps,
      ActionIconRef,
    } from './ActionIcon.types'

    const ActionIconLink = React.forwardRef(function (
      { 'aria-label': label, href, children, ...props }: ActionIconProps<'link'>,
      ref: ActionIconRef<'link'>
    ) {
      return (
        <Tooltip overlay={label} trigger={['hover', 'focus']}>
          <StyledAnchor aria-label={label} href={href} {...props} ref={ref}>
            {children}
          </StyledAnchor>
        </Tooltip>
      )
    })

    const ActionIconButton = React.forwardRef(function (
      { 'aria-label': label, children, ...props }: ActionIconProps<'button'>,
      ref: ActionIconRef<'button'>
    ) {
      return (
        <Tooltip overlay={label} trigger={['hover', 'focus']}>
          <StyledUnstyledButton aria-label={label} {...props} ref={ref}>
            {children}
          </StyledUnstyledButton>
        </Tooltip>
      )
    })

    function ActionIconInner<T extends ActionIconPolyType>(
      props: ActionIconProps<T>,
      ref: ActionIconRef<T>
    ) {
      Iif (props.role === 'link' || (props as any as ActionIconProps<'link'>).href) {
        return (
          <ActionIconLink
            {...(props as any as ActionIconProps<'link'>)}
            ref={ref as ActionIconRef<'link'>}
          />
        )
      }

      Iif (props.role === 'button') {
        return (
          <ActionIconButton
            {...(props as ActionIconProps<'button'>)}
            ref={ref as ActionIconRef<'button'>}
          />
        )
      }
      return (
        <ActionIconButton
          {...(props as ActionIconProps<'button'>)}
          ref={ref as ActionIconRef<'button'>}
        />
      )
    }

    export const ActionIcon = React.forwardRef(ActionIconInner) as <
      Role extends ActionIconPolyType
    >(
      props: ActionIconProps<Role>
    ) => ReturnType<typeof ActionIconInner>