You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
3.4 KiB

import {Line as Progressline, Circle as Progresscircle} from 'rc-progress';
import React from 'react';
import assign from 'object-assign';
10 years ago
var Line = React.createClass({
10 years ago
getDefaultProps() {
10 years ago
return {
10 years ago
width: 300,
10 years ago
percent: 0,
10 years ago
strokeWidth: 3,
status: 'normal' // exception
10 years ago
};
10 years ago
},
render() {
var statusColorMap = {
'normal': '#3FC7FA',
'exception': '#FE8C6A',
'success': '#85D262'
};
10 years ago
var props = assign({}, this.props);
if (parseInt(props.percent) === 100) {
props.status = 'success';
}
10 years ago
var style = {
10 years ago
'width': props.width
10 years ago
};
10 years ago
var fontSize = (props.width / 100 * props.strokeWidth);
10 years ago
var iconStyle = {
10 years ago
'fontSize': (fontSize < 12) ? 12 : fontSize
10 years ago
};
var textStyle = {
10 years ago
'color': statusColorMap[props.status]
10 years ago
};
var progressInfo;
10 years ago
if (props.status === 'exception') {
10 years ago
progressInfo = (
<span style={textStyle} className='ant-progress-line-text'>
10 years ago
<i style={iconStyle} className="anticon anticon-exclamation-circle"></i>
</span>
10 years ago
);
10 years ago
} else if (props.status === 'success') {
progressInfo = (
<span style={textStyle} className='ant-progress-line-text'>
10 years ago
<i style={iconStyle} className="anticon anticon-check-circle"></i>
</span>
10 years ago
);
10 years ago
} else {
10 years ago
progressInfo = (
10 years ago
<span className='ant-progress-line-text'>{props.percent}%</span>
10 years ago
);
10 years ago
}
return (
10 years ago
<div className='ant-progress-line-wrap'>
<div className='ant-progress-line-inner' style={style}>
10 years ago
<Progressline percent={props.percent} strokeWidth={props.strokeWidth}
strokeColor={statusColorMap[props.status]} trailColor="#e9e9e9" />
</div>
10 years ago
{progressInfo}
</div>
);
}
});
var Circle = React.createClass({
getDefaultProps: function () {
10 years ago
return {
width: 132,
10 years ago
percent: 0,
strokeWidth: 6,
status: 'normal' // exception
10 years ago
};
10 years ago
},
render() {
var statusColorMap = {
'normal': '#3FC7FA',
'exception': '#FE8C6A',
'success': '#85D262'
};
10 years ago
var props = assign({}, this.props);
if (parseInt(props.percent) === 100) {
props.status = 'success';
}
10 years ago
var style = {
10 years ago
'width': props.width,
'height': props.width
10 years ago
};
var wrapStyle = {
10 years ago
'fontSize': props.width * 0.16 + 6
10 years ago
};
var textStyle = {
10 years ago
'color': statusColorMap[props.status]
10 years ago
};
var progressInfo;
10 years ago
if (props.status === 'exception') {
10 years ago
progressInfo = (
<span style={textStyle} className='ant-progress-circle-text'>
<i className='anticon anticon-exclamation'></i>
</span>
10 years ago
);
10 years ago
} else if (props.status === 'success') {
10 years ago
progressInfo = (
<span style={textStyle} className='ant-progress-circle-text'>
<i className="anticon anticon-check"></i>
</span>
);
10 years ago
} else {
10 years ago
progressInfo = (
10 years ago
<span className="ant-progress-circle-text">{props.percent}%</span>
10 years ago
);
10 years ago
}
return (
<div className="ant-progress-circle-wrap" style={wrapStyle}>
<div className="ant-progress-circle-inner" style={style}>
10 years ago
<Progresscircle percent={props.percent} strokeWidth={props.strokeWidth}
strokeColor={statusColorMap[props.status]} trailColor="#e9e9e9" />
{progressInfo}
</div>
10 years ago
</div>
);
}
});
export default {
10 years ago
Line: Line,
Circle: Circle
};