forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressBar.js
More file actions
135 lines (114 loc) · 3.42 KB
/
ProgressBar.js
File metadata and controls
135 lines (114 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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;
});