From 42ffa0e87a943effc717a05ce7c69fddad2fd501 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Fri, 5 Jun 2015 21:13:17 +0300 Subject: [PATCH] Strip out some technical debt. --- src/ProgressBar.js | 82 ++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/src/ProgressBar.js b/src/ProgressBar.js index b91f0db408..c8de41f12d 100644 --- a/src/ProgressBar.js +++ b/src/ProgressBar.js @@ -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 ( -
- {this.renderProgressBar()} -
- ); - } 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 ( -
- {ValidComponentChildren.map(this.props.children, this.renderChildBar)} -
- ); + content = this.renderProgressBar(); } + + return ( +
+ {content} +
+ ); }, renderChildBar(child, index) { @@ -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 = ( + + {label} + + ); } - let classes = this.getBsClassSet(); - return ( -
); - }, - - renderScreenReaderOnlyLabel(label) { - return ( - - {label} - - ); } });