Skip to content

Commit

Permalink
Strip out some technical debt.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Jun 6, 2015
1 parent 2f8c454 commit 42ffa0e
Showing 1 changed file with 36 additions and 46 deletions.
82 changes: 36 additions & 46 deletions src/ProgressBar.js
Expand Up @@ -28,41 +28,34 @@ const ProgressBar = React.createClass({
},

getPercentage(now, min, max) {
let roundPrecision = 1000;
const roundPrecision = 1000;
return Math.round(((now - min) / (max - min) * 100) * roundPrecision) / roundPrecision;
},

render() {
let classes = {
progress: true
};

if (this.props.active) {
classes['progress-striped'] = true;
classes.active = true;
} else if (this.props.striped) {
classes['progress-striped'] = true;
if (this.props.isChild) {
return this.renderProgressBar();
}

if (!ValidComponentChildren.hasValidComponent(this.props.children)) {
if (!this.props.isChild) {
return (
<div {...this.props} className={classNames(this.props.className, classes)}>
{this.renderProgressBar()}
</div>
);
} else {
return (
this.renderProgressBar()
);
}
const classes = {
active: this.props.active,
progress: true,
'progress-striped': this.props.active || this.props.striped
};

let content;

if (this.props.children) {
content = ValidComponentChildren.map(this.props.children, this.renderChildBar);
} else {
return (
<div {...this.props} className={classNames(this.props.className, classes)}>
{ValidComponentChildren.map(this.props.children, this.renderChildBar)}
</div>
);
content = this.renderProgressBar();
}

return (
<div {...this.props} className={classNames(this.props.className, classes)}>
{content}
</div>
);
},

renderChildBar(child, index) {
Expand All @@ -73,28 +66,33 @@ const ProgressBar = React.createClass({
},

renderProgressBar() {
let percentage = this.getPercentage(
this.props.now,
this.props.min,
this.props.max
);
const percentage = this.getPercentage(
this.props.now,
this.props.min,
this.props.max
);

let label;

if (typeof this.props.label === 'string') {
label = this.renderLabel(percentage);
} else if (this.props.label) {
} else {
label = this.props.label;
}

if (this.props.srOnly) {
label = this.renderScreenReaderOnlyLabel(label);
label = (
<span className="sr-only">
{label}
</span>
);
}

let classes = this.getBsClassSet();

return (
<div {...this.props} className={classNames(this.props.className, classes)} role="progressbar"
<div
{...this.props}
className={classNames(this.props.className, this.getBsClassSet())}
role="progressbar"
style={{width: percentage + '%'}}
aria-valuenow={this.props.now}
aria-valuemin={this.props.min}
Expand All @@ -105,7 +103,7 @@ const ProgressBar = React.createClass({
},

renderLabel(percentage) {
let InterpolateClass = this.props.interpolateClass || Interpolate;
const InterpolateClass = this.props.interpolateClass || Interpolate;

return (
<InterpolateClass
Expand All @@ -117,14 +115,6 @@ const ProgressBar = React.createClass({
{this.props.label}
</InterpolateClass>
);
},

renderScreenReaderOnlyLabel(label) {
return (
<span className="sr-only">
{label}
</span>
);
}
});

Expand Down

0 comments on commit 42ffa0e

Please sign in to comment.