All files / components/utilities progress-bar.jsx

100% Statements 13/13
77.27% Branches 17/22
100% Functions 1/1
100% Lines 13/13
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          2x 2x 2x 1x   1x   2x 2x 2x 2x   2x                         2x                           1x                                   1x                    
import React from 'react';
import PropTypes from 'prop-types';
 
class ProgressBar extends React.Component {
  render() {
    const percentage = (typeof this.props.percent === 'string' && this.props.percent.includes('%')) ? this.props.percent : `${this.props.percent}%`;
    const style = {};
    if (this.props.vertical) {
      style.height = percentage;
    } else {
      style.width = percentage;
    }
    const verticalness = this.props.vertical ? ' vertical' : '';
    const activeness = this.props.active ? ' active' : '';
    const stripedness = this.props.striped ? ' progress-bar-striped' : '';
    const size = this.props.size ? ` ${this.props.vertical ? 'progress-' : ''}${this.props.size}` : '';
    const theBar = (
      <div className={`progress${verticalness}${activeness}${size}`}>
        <div
          className={`progress-bar ${this.props.theme}${stripedness}`}
          role="progressbar"
          aria-valuenow={percentage.replace('%', '')}
          aria-valuemin="0"
          aria-valuemax="100"
          style={style}
        >
          <span className="sr-only">{`${percentage} Complete`}</span>
        </div>
      </div>
    );
    return this.props.vertical ? theBar : (
      <div className="progress-group">
        {this.props.description ? (
          <div className="progress-text">{this.props.description}</div>
        ) : ''}
        {this.props.details ? (
          <div className="progress-number">{this.props.details}</div>
        ) : ''}
        {theBar}
      </div>
    );
  }
}
 
ProgressBar.propTypes = {
  percent: PropTypes.oneOfType([
    PropTypes.number,
    PropTypes.string
  ]),
  description: PropTypes.string,
  details: PropTypes.oneOfType([
    PropTypes.string,
    PropTypes.number,
    PropTypes.element
  ]),
  theme: PropTypes.string,
  size: PropTypes.string,
  striped: PropTypes.bool,
  vertical: PropTypes.bool,
  active: PropTypes.bool
};
 
ProgressBar.defaultProps = {
  theme: 'progress-bar-yellow',
  percent: 0,
  size: '',
  striped: false,
  vertical: false,
  active: false
};
 
export default ProgressBar;