From befe1fc521cab54b4ac4b6957b6da419f2b53840 Mon Sep 17 00:00:00 2001 From: afc163 Date: Tue, 5 Apr 2016 16:51:26 +0800 Subject: [PATCH] Merge circle into line component --- components/progress/Circle.jsx | 4 +- components/progress/Line.jsx | 123 +++++++++++++-------- components/progress/demo/circle-dynamic.md | 3 +- components/progress/demo/circle-mini.md | 7 +- components/progress/demo/circle.md | 7 +- components/progress/demo/dynamic.md | 4 +- components/progress/demo/format.md | 11 +- components/progress/demo/line-mini.md | 9 +- components/progress/demo/line.md | 11 +- components/progress/index.jsx | 11 +- style/components/progress.less | 69 +++++++----- 11 files changed, 145 insertions(+), 114 deletions(-) diff --git a/components/progress/Circle.jsx b/components/progress/Circle.jsx index 7e9ad28007..074d0ba142 100644 --- a/components/progress/Circle.jsx +++ b/components/progress/Circle.jsx @@ -1,4 +1,4 @@ -import { Circle as Progresscircle } from 'rc-progress'; +import { RcProgressCircle } from 'rc-progress'; import React from 'react'; import Icon from '../icon'; @@ -65,7 +65,7 @@ export default class Circle extends React.Component { return (
- {progressInfo}
diff --git a/components/progress/Line.jsx b/components/progress/Line.jsx index 13818d395c..c560516f2a 100644 --- a/components/progress/Line.jsx +++ b/components/progress/Line.jsx @@ -1,71 +1,96 @@ -import React from 'react'; +import React, { PropTypes } from 'react'; import Icon from '../icon'; +import { Circle } from 'rc-progress'; +import classNames from 'classnames'; + +const statusColorMap = { + normal: '#2db7f5', + exception: '#ff5500', + success: '#87d068' +}; -const prefixCls = 'ant-progress'; export default class Line extends React.Component { static defaultProps = { + type: 'line', percent: 0, - strokeWidth: 10, - status: 'normal', // exception active showInfo: true, - trailColor: '#f3f3f3' + trailColor: '#f3f3f3', + prefixCls: 'ant-progress', } static 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, + status: PropTypes.oneOf(['normal', 'exception', 'active', 'success']), + showInfo: PropTypes.bool, + percent: PropTypes.number, + strokeWidth: PropTypes.number, + trailColor: PropTypes.string, + format: PropTypes.func, } render() { - let props = { ...this.props }; - - if (parseInt(props.percent, 10) === 100) { - props.status = 'success'; - } - + const { prefixCls, status, format, percent, trailColor, + type, strokeWidth, width, className, showInfo, ...restProps } = this.props; + const progressStatus = (parseInt(percent, 10) >= 100 && !('status' in this.props)) + ? 'success' : (status || 'normal'); let progressInfo; - let fullCls = ''; + let progress; + const textFormatter = format || (percentNumber => `${percentNumber}%`); - const format = props.format || (percent => `${percent}%`); - - if (props.showInfo) { - if (props.status === 'exception') { - progressInfo = ( - - {props.format ? format(props.percent) : } - - ); - } else if (props.status === 'success') { - progressInfo = ( - - {props.format ? format(props.percent) : } - - ); + if (showInfo) { + let text; + const iconType = type === 'circle' ? '' : '-circle'; + if (progressStatus === 'exception') { + text = format ? textFormatter(percent) : ; + } else if (progressStatus === 'success') { + text = format ? textFormatter(percent) : ; } else { - progressInfo = ( - {format(props.percent)} - ); + text = textFormatter(percent); } - } else { - fullCls = ` ${prefixCls}-line-wrap-full`; + progressInfo = {text}; } - let percentStyle = { - width: `${props.percent}%`, - height: props.strokeWidth - }; + + if (type === 'line') { + const percentStyle = { + width: `${percent}%`, + height: strokeWidth || 10, + }; + progress = ( +
+
+
+
+
+
+ {progressInfo} +
+ ); + } else if (type === 'circle') { + const circleSize = width || 132; + const circleStyle = { + width: circleSize, + height: circleSize, + fontSize: circleSize * 0.16 + 6, + }; + progress = ( +
+ + {progressInfo} +
+ ); + } + + const classString = classNames({ + [`${prefixCls}`]: true, + [`${prefixCls}-${type}`]: true, + [`${prefixCls}-status-${progressStatus}`]: true, + [`${prefixCls}-show-info`]: showInfo, + [className]: !!className, + }); return ( -
-
-
-
-
-
- {progressInfo} +
+ {progress}
); } diff --git a/components/progress/demo/circle-dynamic.md b/components/progress/demo/circle-dynamic.md index 3778a86713..57f8165466 100644 --- a/components/progress/demo/circle-dynamic.md +++ b/components/progress/demo/circle-dynamic.md @@ -7,7 +7,6 @@ title: 进度圈动态展示 ````jsx import { Progress, Button, Icon } from 'antd'; -const ProgressCircle = Progress.Circle; const ButtonGroup = Button.Group; const MyProgress = React.createClass({ @@ -33,7 +32,7 @@ const MyProgress = React.createClass({ render() { return (
- +