All files / packages/design-system/ui/components/button-icons index.jsx

58.82% Statements 10/17
94.44% Branches 17/18
0% Functions 0/1
58.82% Lines 10/17

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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151                59x                                                 1121x           40x           3x           6x                   4x                 3x           1x       1121x                                                                                                                       59x                    
// Copyright (c) 2015-present, salesforce.com, inc. All rights reserved
// Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license
 
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import SvgIcon from '../../shared/svg-icon';
import classNames from 'classnames';
 
export const HintParent = props => (
  <div className="slds-hint-parent">{props.children}</div>
);
 
class ButtonIcon extends Component {
  render() {
    let {
      id,
      className,
      iconClassName,
      assistiveText,
      hasDropdown,
      size,
      variant,
      theme,
      feedback,
      selected,
      symbol,
      isFirst,
      isMiddle,
      isLast,
      isOpen,
      useCurrentColor,
      innerRef,
      ...rest
    } = this.props;
 
    /**
     * Neutral - Bordered with Filled Container
     */
    if (theme === 'neutral') {
      variant = 'slds-button_icon-border-filled';
 
      if (size === 'medium') {
        size = null;
      }
      if (hasDropdown) {
        variant = null;
      }
      /**
       * Inverse - Bare/Bordered on Inverse Background
       */
    } else if (theme === 'inverse') {
      variant = 'slds-button_icon-inverse';
 
      if (size === 'medium') {
        variant = 'slds-button_icon-border-inverse';
        size = null;
      }
      /**
       * Brand
       */
    } else if (theme === 'brand') {
      variant = 'slds-button_icon-brand';
 
      if (size === 'medium') {
        size = null;
      }
      /**
       * Transparent - Bordered with Transparent Container
       */
    } else if (theme === 'transparent') {
      variant = 'slds-button_icon-border';
 
      if (size === 'medium') {
        size = null;
      }
      if (hasDropdown) {
        variant = null;
      }
    }
 
    return (
      <button
        onClick={e => {
          // Temporary fix to stop Action Menus from triggering Accordion Section toggling
          e.stopPropagation();
        }}
        id={id}
        className={classNames(
          'slds-button slds-button_icon',
          selected && 'slds-is-selected',
          {
            'slds-button_icon-more': hasDropdown && theme === 'neutral',
            'slds-button_icon-container-more':
              hasDropdown && theme === 'transparent',
            'slds-button_icon-current-color': useCurrentColor
          },
          {
            'slds-button_icon-container': size === 'medium',
            'slds-button_icon-large': size === 'large',
            'slds-button_icon-small': size === 'small',
            'slds-button_icon-x-small': size === 'x-small',
            'slds-button_icon-xx-small': size === 'xx-small'
          },
          {
            'slds-button_icon-error': feedback === 'error',
            'slds-button_icon-warning': feedback === 'warning'
          },
          {
            'slds-button_first': isFirst,
            'slds-button_middle': isMiddle,
            'slds-button_last': isLast
          },
          variant,
          className
        )}
        aria-haspopup={hasDropdown ? 'true' : this.props['aria-haspopup']}
        {...hasDropdown && { [`aria-expanded`]: isOpen ? 'true' : 'false' }}
        ref={innerRef}
        {...rest}
      >
        <SvgIcon
          className={classNames('slds-button__icon', iconClassName)}
          sprite="utility"
          symbol={symbol || 'settings'}
        />
        {hasDropdown && (
          <SvgIcon
            className="slds-button__icon slds-button__icon_x-small"
            sprite="utility"
            symbol="down"
          />
        )}
        <span className="slds-assistive-text">
          {assistiveText || 'Provide description of action'}
        </span>
      </button>
    );
  }
}
 
ButtonIcon.propTypes = {
  id: PropTypes.string,
  symbol: PropTypes.string,
  theme: PropTypes.string,
  assistiveText: PropTypes.string,
  useCurrentColor: PropTypes.bool,
  title: PropTypes.string
};
 
export default ButtonIcon;