# All files / src/CommandButton CommandButton.tsx

100% Statements 13/13
100% Branches 4/4
100% Functions 1/1
100% Lines 12/12

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
    2417x
    17x
    17x

    17x
    22x
    22x
    22x
    22x
    22x
    22x

    17x

    17x
     import * as React from 'react'
    import { CommandContext } from '../Command/Command'
    import { CommandButtonStyled, CommandButtonTextStyled } from './CommandButton.styled'
    import { CommandButtonProps } from './CommandButton.type'

    const CommandButton = React.forwardRef<HTMLButtonElement, CommandButtonProps>(
      ({ onClick, children, ...rest }: CommandButtonProps, ref): React.ReactElement => {
        const reveal = React.useContext(CommandContext)
        const theChildren = React.Children.toArray(children)
        const icon = theChildren[0]
        const text = React.Children.count(children) > 1 ? theChildren[1] : null
        return (
          <CommandButtonStyled onClick={onClick} ref={ref} reveal={reveal} {...rest}>
            {icon}
            {text && <CommandButtonTextStyled hasIcon={!!icon}>{text}</CommandButtonTextStyled>}
          </CommandButtonStyled>
        )
      }
    )

    CommandButton.displayName = 'FCommandButton'

    export default CommandButton