1
1
import classNames from 'classnames' ;
2
2
import PropTypes from '../_util/vue-types' ;
3
3
import { getOptionProps , initDefaultProps } from '../_util/props-util' ;
4
+ import { ConfigConsumerProps } from '../config-provider' ;
4
5
import Icon from '../icon' ;
5
- import { Circle } from '../vc-progress' ;
6
+ import Line from './line' ;
7
+ import Circle from './circle' ;
8
+ import { validProgress } from './utils' ;
6
9
7
10
function addUnit ( num , unit ) {
8
11
const unitType = unit || 'px' ;
9
12
return num ? num + unitType : null ;
10
13
}
11
- const statusColorMap = {
12
- normal : '#108ee9' ,
13
- exception : '#ff5500' ,
14
- success : '#87d068' ,
15
- } ;
16
14
17
15
export const ProgressType = PropTypes . oneOf ( [ 'line' , 'circle' , 'dashboard' ] ) ;
18
16
export const ProgressSize = PropTypes . oneOf ( [ 'default' , 'small' ] ) ;
@@ -35,30 +33,46 @@ export const ProgressProps = {
35
33
size : ProgressSize ,
36
34
} ;
37
35
38
- const validProgress = progress => {
39
- if ( ! progress || progress < 0 ) {
40
- return 0 ;
41
- } else if ( progress > 100 ) {
42
- return 100 ;
43
- }
44
- return progress ;
45
- } ;
46
-
47
36
export default {
48
37
name : 'AProgress' ,
49
38
props : initDefaultProps ( ProgressProps , {
50
39
type : 'line' ,
51
40
percent : 0 ,
52
41
showInfo : true ,
53
42
trailColor : '#f3f3f3' ,
54
- prefixCls : 'ant-progress' ,
55
43
size : 'default' ,
44
+ gapDegree : 0 ,
45
+ strokeLinecap : 'round' ,
56
46
} ) ,
47
+ inject : {
48
+ configProvider : { default : ( ) => ( { } ) } ,
49
+ } ,
50
+ methods : {
51
+ renderProcessInfo ( prefixCls , progressStatus ) {
52
+ const { showInfo, format, type, percent, successPercent } = this . $props ;
53
+ if ( ! showInfo ) return null ;
57
54
55
+ let text ;
56
+ const textFormatter = format || ( percentNumber => `${ percentNumber } %` ) ;
57
+ const iconType = type === 'circle' || type === 'dashboard' ? '' : '-circle' ;
58
+ if ( format || ( progressStatus !== 'exception' && progressStatus !== 'success' ) ) {
59
+ text = textFormatter ( validProgress ( percent ) , validProgress ( successPercent ) ) ;
60
+ } else if ( progressStatus === 'exception' ) {
61
+ text = < Icon type = { `close${ iconType } ` } theme = { type === 'line' ? 'filled' : 'outlined' } /> ;
62
+ } else if ( progressStatus === 'success' ) {
63
+ text = < Icon type = { `check${ iconType } ` } theme = { type === 'line' ? 'filled' : 'outlined' } /> ;
64
+ }
65
+ return (
66
+ < span class = { `${ prefixCls } -text` } title = { typeof text === 'string' ? text : undefined } >
67
+ { text }
68
+ </ span >
69
+ ) ;
70
+ } ,
71
+ } ,
58
72
render ( ) {
59
73
const props = getOptionProps ( this ) ;
60
74
const {
61
- prefixCls,
75
+ prefixCls : customizePrefixCls ,
62
76
percent = 0 ,
63
77
status,
64
78
format,
@@ -75,84 +89,42 @@ export default {
75
89
strokeLinecap = 'round' ,
76
90
...restProps
77
91
} = props ;
92
+ const getPrefixCls = this . configProvider . getPrefixCls || ConfigConsumerProps . getPrefixCls ;
93
+ const prefixCls = getPrefixCls ( 'progress' , customizePrefixCls ) ;
94
+
78
95
const progressStatus =
79
- parseInt ( successPercent ? successPercent . toString ( ) : percent . toString ( ) , 10 ) >= 100 &&
96
+ parseInt ( successPercent !== undefined ? successPercent . toString ( ) : percent . toString ( ) , 10 ) >= 100 &&
80
97
! ( 'status' in props )
81
98
? 'success'
82
99
: status || 'normal' ;
83
- let progressInfo ;
84
100
let progress ;
85
- const textFormatter = format || ( percentNumber => `${ percentNumber } %` ) ;
86
-
87
- if ( showInfo ) {
88
- let text ;
89
- const iconType = type === 'circle' || type === 'dashboard' ? '' : '-circle' ;
90
- if ( format || ( progressStatus !== 'exception' && progressStatus !== 'success' ) ) {
91
- text = textFormatter ( validProgress ( percent ) , validProgress ( successPercent ) ) ;
92
- } else if ( progressStatus === 'exception' ) {
93
- text = < Icon type = { `close${ iconType } ` } theme = { type === 'line' ? 'filled' : 'outlined' } /> ;
94
- } else if ( progressStatus === 'success' ) {
95
- text = < Icon type = { `check${ iconType } ` } theme = { type === 'line' ? 'filled' : 'outlined' } /> ;
96
- }
97
- progressInfo = (
98
- < span class = { `${ prefixCls } -text` } title = { typeof text === 'string' ? text : undefined } >
99
- { text }
100
- </ span >
101
- ) ;
102
- }
101
+ const progressInfo = this . renderProcessInfo ( prefixCls , progressStatus ) ;
103
102
103
+ // Render progress shape
104
104
if ( type === 'line' ) {
105
- const percentStyle = {
106
- width : `${ validProgress ( percent ) } %` ,
107
- height : `${ strokeWidth || ( size === 'small' ? 6 : 8 ) } px` ,
108
- background : strokeColor ,
109
- borderRadius : strokeLinecap === 'square' ? 0 : '100px' ,
110
- } ;
111
- const successPercentStyle = {
112
- width : `${ validProgress ( successPercent ) } %` ,
113
- height : `${ strokeWidth || ( size === 'small' ? 6 : 8 ) } px` ,
114
- borderRadius : strokeLinecap === 'square' ? 0 : '100px' ,
105
+ const lineProps = {
106
+ props : {
107
+ ...props ,
108
+ prefixCls,
109
+ } ,
115
110
} ;
116
- const successSegment =
117
- successPercent !== undefined ? (
118
- < div class = { `${ prefixCls } -success-bg` } style = { successPercentStyle } />
119
- ) : null ;
120
111
progress = (
121
- < div >
122
- < div class = { `${ prefixCls } -outer` } >
123
- < div class = { `${ prefixCls } -inner` } >
124
- < div class = { `${ prefixCls } -bg` } style = { percentStyle } />
125
- { successSegment }
126
- </ div >
127
- </ div >
112
+ < Line { ...lineProps } >
128
113
{ progressInfo }
129
- </ div >
114
+ </ Line >
130
115
) ;
131
116
} else if ( type === 'circle' || type === 'dashboard' ) {
132
- const circleSize = width || 120 ;
133
- const circleStyle = {
134
- width : addUnit ( circleSize ) ,
135
- height : addUnit ( circleSize ) ,
136
- fontSize : addUnit ( circleSize * 0.15 + 6 ) ,
117
+ const circleProps = {
118
+ props : {
119
+ ...props ,
120
+ prefixCls,
121
+ progressStatus,
122
+ } ,
137
123
} ;
138
- const circleWidth = strokeWidth || 6 ;
139
- const gapPos = gapPosition || ( type === 'dashboard' && 'bottom' ) || 'top' ;
140
- const gapDeg = gapDegree || ( type === 'dashboard' && 75 ) ;
141
124
progress = (
142
- < div class = { `${ prefixCls } -inner` } style = { circleStyle } >
143
- < Circle
144
- percent = { validProgress ( percent ) }
145
- strokeWidth = { circleWidth }
146
- trailWidth = { circleWidth }
147
- strokeColor = { strokeColor || statusColorMap [ progressStatus ] }
148
- strokeLinecap = { strokeLinecap }
149
- trailColor = { trailColor }
150
- prefixCls = { prefixCls }
151
- gapDegree = { gapDeg || 0 }
152
- gapPosition = { gapPos }
153
- />
125
+ < Circle { ...circleProps } >
154
126
{ progressInfo }
155
- </ div >
127
+ </ Circle >
156
128
) ;
157
129
}
158
130
0 commit comments