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.

142 lines
3.7 KiB

import {Circle as Progresscircle} from 'rc-progress';
import React from 'react';
import assign from 'object-assign';
9 years ago
import Icon from '../icon';
10 years ago
const prefixCls = 'ant-progress';
const statusColorMap = {
9 years ago
'normal': '#2db7f5',
'exception': '#ff6600',
'success': '#87d068'
};
let Line = React.createClass({
propTypes: {
status: React.PropTypes.oneOf(['normal', 'exception', 'active', 'success']),
showInfo: React.PropTypes.bool,
percent: React.PropTypes.number,
strokeWidth: React.PropTypes.number,
},
10 years ago
getDefaultProps() {
10 years ago
return {
percent: 0,
strokeWidth: 10,
status: 'normal', // exception active
format: '${percent}%',
showInfo: true,
10 years ago
};
10 years ago
},
render() {
let props = assign({}, this.props);
10 years ago
if (parseInt(props.percent, 10) === 100) {
10 years ago
props.status = 'success';
}
let progressInfo;
let fullCls = '';
const text = (typeof props.format === 'string') ?
props.format.replace('${percent}', props.percent) : props.format;
if(props.showInfo === true){
if (props.status === 'exception') {
progressInfo = (
<span className={prefixCls + '-line-text'}>{text}</span>
);
} else if (props.status === 'success') {
progressInfo = (
<span className={prefixCls + '-line-text'}>
<Icon type="check" />
</span>
);
} else {
progressInfo = (
<span className={prefixCls + '-line-text'}>{text}</span>
);
}
9 years ago
} else {
fullCls = ' ' + prefixCls + '-line-wrap-full';
10 years ago
}
let percentStyle = {
width: props.percent + '%',
height: props.strokeWidth
};
10 years ago
return (
<div className={prefixCls + '-line-wrap clearfix status-' + props.status + fullCls}>
10 years ago
{progressInfo}
<div className={prefixCls + '-line-outer'}>
<div className={prefixCls + '-line-inner'}>
<div className={prefixCls + '-line-bg'} style={percentStyle}></div>
</div>
</div>
10 years ago
</div>
);
}
});
let Circle = React.createClass({
propTypes: {
status: React.PropTypes.oneOf(['normal', 'exception', 'success']),
percent: React.PropTypes.number,
strokeWidth: React.PropTypes.number,
width: React.PropTypes.number,
},
getDefaultProps: function () {
10 years ago
return {
width: 132,
10 years ago
percent: 0,
strokeWidth: 6,
format: '${percent}%',
status: 'normal', // exception
10 years ago
};
10 years ago
},
render() {
let props = assign({}, this.props);
10 years ago
if (parseInt(props.percent, 10) === 100) {
10 years ago
props.status = 'success';
}
let style = {
10 years ago
'width': props.width,
'height': props.width,
10 years ago
'fontSize': props.width * 0.16 + 6
10 years ago
};
let progressInfo;
const text = (typeof props.format === 'string') ?
props.format.replace('${percent}', props.percent) : props.format;
10 years ago
if (props.status === 'exception') {
10 years ago
progressInfo = (
<span className={prefixCls + '-circle-text'}>{text}</span>
10 years ago
);
10 years ago
} else if (props.status === 'success') {
10 years ago
progressInfo = (
<span className={prefixCls + '-circle-text'}>
<Icon type="check" />
10 years ago
</span>
);
10 years ago
} else {
10 years ago
progressInfo = (
<span className={prefixCls + '-circle-text'}>{text}</span>
10 years ago
);
10 years ago
}
return (
<div className={prefixCls + '-circle-wrap status-' + props.status} >
<div className={prefixCls + '-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
};