UNPKG

react-bootstrap

Version:

Bootstrap 3 components build with React

136 lines (114 loc) 3.5 kB
define(function (require, exports, module) {var React = require('react'); var joinClasses = require('./utils/joinClasses'); var Interpolate = require('./Interpolate'); var BootstrapMixin = require('./BootstrapMixin'); var classSet = require('./utils/classSet'); var cloneWithProps = require('./utils/cloneWithProps'); var ValidComponentChildren = require('./utils/ValidComponentChildren'); var ProgressBar = React.createClass({displayName: "ProgressBar", propTypes: { min: React.PropTypes.number, now: React.PropTypes.number, max: React.PropTypes.number, label: React.PropTypes.node, srOnly: React.PropTypes.bool, striped: React.PropTypes.bool, active: React.PropTypes.bool }, mixins: [BootstrapMixin], getDefaultProps: function () { return { bsClass: 'progress-bar', min: 0, max: 100 }; }, getPercentage: function (now, min, max) { return Math.ceil((now - min) / (max - min) * 100); }, render: function () { var classes = { progress: true }; if (this.props.active) { classes['progress-striped'] = true; classes['active'] = true; } else if (this.props.striped) { classes['progress-striped'] = true; } if (!ValidComponentChildren.hasValidComponent(this.props.children)) { if (!this.props.isChild) { return ( React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}), this.renderProgressBar() ) ); } else { return ( this.renderProgressBar() ); } } else { return ( React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}), ValidComponentChildren.map(this.props.children, this.renderChildBar) ) ); } }, renderChildBar: function (child, index) { return cloneWithProps(child, { isChild: true, key: child.key ? child.key : index, ref: child.ref }); }, renderProgressBar: function () { var percentage = this.getPercentage( this.props.now, this.props.min, this.props.max ); var label; if (typeof this.props.label === "string") { label = this.renderLabel(percentage); } else if (this.props.label) { label = this.props.label; } if (this.props.srOnly) { label = this.renderScreenReaderOnlyLabel(label); } var classes = this.getBsClassSet(); return ( React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes)), role: "progressbar", style: {width: percentage + '%'}, "aria-valuenow": this.props.now, "aria-valuemin": this.props.min, "aria-valuemax": this.props.max}), label ) ); }, renderLabel: function (percentage) { var InterpolateClass = this.props.interpolateClass || Interpolate; return ( React.createElement(InterpolateClass, { now: this.props.now, min: this.props.min, max: this.props.max, percent: percentage, bsStyle: this.props.bsStyle}, this.props.label ) ); }, renderScreenReaderOnlyLabel: function (label) { return ( React.createElement("span", {className: "sr-only"}, label ) ); } }); module.exports = ProgressBar; });