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.

150 lines
3.9 KiB

import { Circle as Progresscircle } from 'rc-progress';
import React from 'react';
9 years ago
import Icon from '../icon';
10 years ago
const prefixCls = 'ant-progress';
const statusColorMap = {
normal: '#2db7f5',
exception: '#ff5500',
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,
trailColor: React.PropTypes.string,
format: React.PropTypes.func,
},
10 years ago
getDefaultProps() {
10 years ago
return {
percent: 0,
strokeWidth: 10,
status: 'normal', // exception active
showInfo: true,
trailColor: '#f3f3f3'
10 years ago
};
10 years ago
},
render() {
let props = { ...this.props };
10 years ago
if (parseInt(props.percent, 10) === 100) {
10 years ago
props.status = 'success';
}
let progressInfo;
let fullCls = '';
const format = props.format || (percent => `${percent}%`);
if (props.showInfo) {
if (props.status === 'exception') {
progressInfo = (
<span className={`${prefixCls}-line-text`}>
{props.format ? format(props.percent) : <Icon type="cross-circle" />}
</span>
);
} else if (props.status === 'success') {
progressInfo = (
<span className={`${prefixCls}-line-text`}>
{props.format ? format(props.percent) : <Icon type="check-circle" />}
</span>
);
} else {
progressInfo = (
<span className={`${prefixCls}-line-text`}>{format(props.percent)}</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}`} style={props.style}>
<div className={`${prefixCls}-line-outer`}>
<div className={`${prefixCls}-line-inner`}>
<div className={`${prefixCls}-line-bg`} style={percentStyle}></div>
</div>
</div>
{progressInfo}
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,
trailColor: React.PropTypes.string,
format: React.PropTypes.func,
},
getDefaultProps() {
10 years ago
return {
width: 132,
10 years ago
percent: 0,
strokeWidth: 6,
status: 'normal', // exception
trailColor: '#f3f3f3',
10 years ago
};
10 years ago
},
render() {
let props = { ...this.props };
10 years ago
if (parseInt(props.percent, 10) === 100) {
10 years ago
props.status = 'success';
}
let style = {
width: props.width,
height: props.width,
fontSize: props.width * 0.16 + 6
10 years ago
};
let progressInfo;
const format = props.format || (percent => `${percent}%`);
10 years ago
if (props.status === 'exception') {
10 years ago
progressInfo = (
<span className={`${prefixCls}-circle-text`}>
{props.format ? format(props.percent) : <Icon type="exclamation" />}
</span>
10 years ago
);
10 years ago
} else if (props.status === 'success') {
10 years ago
progressInfo = (
<span className={`${prefixCls}-circle-text`}>
{props.format ? format(props.percent) : <Icon type="check" />}
10 years ago
</span>
);
10 years ago
} else {
10 years ago
progressInfo = (
<span className={`${prefixCls}-circle-text`}>{format(props.percent)}</span>
10 years ago
);
10 years ago
}
return (
<div className={`${prefixCls}-circle-wrap status-${props.status}`} style={props.style}>
<div className={`${prefixCls}-circle-inner`} style={style}>
10 years ago
<Progresscircle percent={props.percent} strokeWidth={props.strokeWidth}
strokeColor={statusColorMap[props.status]} trailColor={props.trailColor} />
{progressInfo}
</div>
10 years ago
</div>
);
}
});
export default {
Line,
Circle,
10 years ago
};