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

100% Statements 13/13
100% Branches 2/2
100% Functions 3/3
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 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          14x 22x                         14x           14x   14x       14x 8x     14x         12x 10x                               14x             14x      
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { UtilityIcon } from '../icons/base/example';
 
export const Badge = props => (
  <span
    className={classNames('slds-badge', {
      'slds-badge_inverse': props.isInverse,
      'slds-badge_lightest': props.isLightest,
      'slds-theme_success': props.isSuccess,
      'slds-theme_warning': props.isWarning,
      'slds-theme_error': props.isError
    })}
  >
    {props.children}
  </span>
);
 
Badge.propTypes = {
  isInverse: PropTypes.bool,
  isLightest: PropTypes.bool,
  children: PropTypes.node.isRequired
};
 
export const InverseBadge = props => <Badge isInverse>{props.children}</Badge>;
 
InverseBadge.propTypes = {
  children: PropTypes.node.isRequired
};
 
export const LightestBadge = props => (
  <Badge isLightest>{props.children}</Badge>
);
 
LightestBadge.propTypes = {
  children: PropTypes.node.isRequired
};
 
export const BadgeIcon = props => {
  const { assistiveText, align, isInverse, symbol } = props;
  return (
    <span
      className={classNames('slds-badge__icon', `slds-badge__icon_${align}`, {
        'slds-badge__icon_inverse': isInverse
      })}
    >
      <UtilityIcon
        className="slds-icon_xx-small"
        useCurrentColor
        assistiveText={assistiveText || false}
        symbol={symbol}
      />
    </span>
  );
};
 
BadgeIcon.propTypes = {
  symbol: PropTypes.string,
  align: PropTypes.oneOf(['left', 'right']),
  isInverse: PropTypes.bool,
  assistiveText: PropTypes.oneOfType([PropTypes.string, PropTypes.bool])
};
 
BadgeIcon.defaultProps = {
  align: 'left'
};