ant-design/components/progress/index.jsx

126 lines
3.1 KiB
React
Raw Normal View History

2015-06-14 12:55:44 +08:00
'use strict';
var Progressline = require('rc-progress').Line;
var Progresscircle = require('rc-progress').Circle;
var React = require('react');
var Line = React.createClass({
2015-06-14 19:50:23 +08:00
getDefaultProps: function () {
2015-06-14 12:55:44 +08:00
return {
percent: 0,
2015-06-14 19:50:23 +08:00
strokeWidth: 2,
status: "normal" // exception
2015-06-14 12:55:44 +08:00
}
},
render() {
2015-06-14 19:50:23 +08:00
var statusColorMap = {
"normal": "#3FC7FA",
"exception": "#FE8C6A",
"success": "#85D262"
};
if (parseInt(this.props.percent) === 100) {
this.props.status = 'success'
}
2015-06-14 12:55:44 +08:00
var style = {
"width": this.props.width
}
2015-06-14 19:50:23 +08:00
var wrapStyle = {
"font-size": this.props.width / 100 * this.props.strokeWidth
}
var textStyle = {
"color": statusColorMap[this.props.status]
}
2015-06-14 12:55:44 +08:00
var progressInfo
2015-06-14 19:50:23 +08:00
if (this.props.status === 'exception') {
2015-06-14 12:55:44 +08:00
progressInfo = (
2015-06-14 19:50:23 +08:00
<span style={textStyle} className="ant-progress-line-text">
<i className="anticon anticon-exclamation-round"></i>
</span>
)
} else if(this.props.status === 'success'){
progressInfo = (
<span style={textStyle} className="ant-progress-line-text">
<i className="anticon anticon-check-round"></i>
</span>
2015-06-14 12:55:44 +08:00
)
}else {
progressInfo = (
2015-06-14 19:50:23 +08:00
<span className="ant-progress-line-text">{this.props.percent}%</span>
2015-06-14 12:55:44 +08:00
)
}
return (
2015-06-14 19:50:23 +08:00
<div className="ant-progress-line-wrap" style={wrapStyle}>
<div className="ant-progress-line-inner" style={style}>
<Progressline percent={this.props.percent} strokeWidth={this.props.strokeWidth}
strokeColor={statusColorMap[this.props.status]}/>
</div>
2015-06-14 12:55:44 +08:00
{progressInfo}
</div>
);
}
});
var Circle = React.createClass({
2015-06-14 19:50:23 +08:00
getDefaultProps: function () {
2015-06-14 12:55:44 +08:00
return {
percent: 0,
2015-06-14 20:07:21 +08:00
strokeWidth: 2,
status: "normal" // exception
2015-06-14 12:55:44 +08:00
}
},
render() {
2015-06-14 20:07:21 +08:00
var statusColorMap = {
"normal": "#3FC7FA",
"exception": "#FE8C6A",
"success": "#85D262"
};
if (parseInt(this.props.percent) === 100) {
this.props.status = 'success'
}
2015-06-14 12:55:44 +08:00
var style = {
"width": this.props.width,
"height": this.props.width
}
2015-06-14 20:07:21 +08:00
var wrapStyle = {
2015-06-14 23:04:43 +08:00
"font-size": this.props.width * 0.3
2015-06-14 20:07:21 +08:00
}
var textStyle = {
"color": statusColorMap[this.props.status]
}
2015-06-14 12:55:44 +08:00
var progressInfo
2015-06-14 20:07:21 +08:00
if (this.props.status === 'exception') {
2015-06-14 12:55:44 +08:00
progressInfo = (
2015-06-14 20:07:21 +08:00
<span style={textStyle} className="ant-progress-circle-text">
<i className="anticon anticon-exclamation"></i>
</span>
2015-06-14 12:55:44 +08:00
)
2015-06-14 20:07:21 +08:00
}else {
2015-06-14 12:55:44 +08:00
progressInfo = (
2015-06-14 20:07:21 +08:00
<span className="ant-progress-circle-text">{this.props.percent}%</span>
2015-06-14 12:55:44 +08:00
)
}
return (
2015-06-14 20:07:21 +08:00
<div className="ant-progress-circle-wrap" style={wrapStyle}>
<div className="ant-progress-circle-inner" style={style}>
<Progresscircle percent={this.props.percent} strokeWidth={this.props.strokeWidth}
2015-06-14 19:50:23 +08:00
strokeColor={statusColorMap[this.props.status]}/>
2015-06-14 20:07:21 +08:00
{progressInfo}
</div>
2015-06-14 12:55:44 +08:00
</div>
);
}
});
module.exports = {
Line: Line,
Circle: Circle
};