import { Circle as Progresscircle } from 'rc-progress'; import React from 'react'; import assign from 'object-assign'; import warning from 'warning'; import Icon from '../icon'; 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.oneOfType([ React.PropTypes.node, React.PropTypes.string, React.PropTypes.func, ]), }, getDefaultProps() { return { percent: 0, strokeWidth: 10, status: 'normal', // exception active showInfo: true, trailColor: '#f3f3f3' }; }, render() { let props = assign({}, this.props); if (parseInt(props.percent, 10) === 100) { props.status = 'success'; } let progressInfo; let fullCls = ''; if (props.format) { warning(typeof props.format === 'function', 'antd.Progress props.format type is function, change format={xxx} to format={() => xxx}'); } let text = props.format || `${props.percent}%`; if (typeof props.format === 'string') { // 向下兼容原来的字符串替换方式 text = props.format.replace('${percent}', props.percent); } else if (typeof props.format === 'function') { text = props.format(props.percent); } if (props.showInfo) { if (props.status === 'exception') { progressInfo = ( {props.format ? text : } ); } else if (props.status === 'success') { progressInfo = ( {props.format ? text : } ); } else { progressInfo = ( {text} ); } } else { fullCls = ` ${prefixCls}-line-wrap-full`; } let percentStyle = { width: `${props.percent}%`, height: props.strokeWidth }; return (
{progressInfo}
); } }); 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.oneOfType([ React.PropTypes.node, React.PropTypes.string, React.PropTypes.func, ]), }, getDefaultProps() { return { width: 132, percent: 0, strokeWidth: 6, status: 'normal', // exception trailColor: '#f3f3f3', }; }, render() { let props = assign({}, this.props); if (parseInt(props.percent, 10) === 100) { props.status = 'success'; } let style = { width: props.width, height: props.width, fontSize: props.width * 0.16 + 6 }; let progressInfo; let text = props.format || `${props.percent}%`; if (props.format) { warning(typeof props.format === 'function', 'antd.Progress props.format type is function, change format={xxx} to format={() => xxx}'); } if (typeof props.format === 'string') { // 向下兼容原来的字符串替换方式 text = props.format.replace('${percent}', props.percent); } else if (typeof props.format === 'function') { text = props.format(props.percent); } if (props.status === 'exception') { progressInfo = ( {props.format ? text : } ); } else if (props.status === 'success') { progressInfo = ( {props.format ? text : } ); } else { progressInfo = ( {text} ); } return (
{progressInfo}
); } }); export default { Line, Circle, };