All files / atom/button/src Button.js

80% Statements 8/10
72.72% Branches 8/11
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65        1x                         24x 24x   24x 24x   24x   24x             1x                                                                
import PropTypes from 'prop-types'
 
import ButtonLink from './ButtonLink.js'
 
const Button = ({
  children,
  href,
  target,
  disabled,
  isSubmit, // eslint-disable-line react/prop-types
  isButton, // eslint-disable-line react/prop-types
  link,
  linkFactory: Link = ButtonLink,
  forwardingRef, // eslint-disable-line react/prop-types
  className,
  ...attrs
}) => {
  Iif (isSubmit) attrs.type = 'submit'
  Iif (isButton) attrs.type = 'button'
 
  const defaultRel = target === '_blank' ? 'noopener' : undefined
  const rel = attrs.rel || defaultRel
 
  const [Component, props] = link ? [Link, {href, target, rel}] : ['button', {disabled}]
 
  return (
    <Component className={className} ref={forwardingRef} {...props} {...attrs}>
      {children}
    </Component>
  )
}
 
Button.propTypes = {
  /**
   * Content to be included in the button
   */
  children: PropTypes.node,
  /**
   * CSS class to be added to the button
   */
  className: PropTypes.string,
  /**
   * HTML element: if true, render a link. Otherwise render a button
   */
  link: PropTypes.bool,
  /**
   * URL to be added on the HTML link
   */
  href: PropTypes.string,
  /**
   * Target to be added on the HTML link
   */
  target: PropTypes.string,
  /**
   * Disable: faded with no interaction.
   */
  disabled: PropTypes.bool,
  /**
   * Factory used to create navigation links
   */
  linkFactory: PropTypes.func
}
 
export default Button