ProgressBar.jsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { withTranslation } from 'react-i18next';
  4. class ProgressBar extends React.Component {
  5. render() {
  6. const {
  7. header, currentCount, totalCount, isInProgress,
  8. } = this.props;
  9. const percentage = currentCount / totalCount * 100;
  10. const isActive = (isInProgress != null)
  11. ? isInProgress // apply props.isInProgress if set
  12. : (currentCount !== totalCount); // otherwise, set true when currentCount does not equal totalCount
  13. return (
  14. <>
  15. <h6 className="my-1">
  16. {header}
  17. <div className="float-right">{currentCount} / {totalCount}</div>
  18. </h6>
  19. <div className="progress">
  20. <div
  21. className={`progress-bar ${isActive ? 'bg-info progress-bar-striped active' : 'bg-success'}`}
  22. style={{ width: `${percentage}%` }}
  23. >
  24. <span className="sr-only">{percentage.toFixed(0)}% Complete</span>
  25. </div>
  26. </div>
  27. </>
  28. );
  29. }
  30. }
  31. ProgressBar.propTypes = {
  32. header: PropTypes.string.isRequired,
  33. currentCount: PropTypes.number.isRequired,
  34. totalCount: PropTypes.number.isRequired,
  35. isInProgress: PropTypes.bool,
  36. };
  37. export default withTranslation()(ProgressBar);