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;
|