@@ -2,13 +2,15 @@ import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
2
2
import { presetPrimaryColors } from '@ant-design/colors' ;
3
3
import { computed , defineComponent } from 'vue' ;
4
4
import type { Direction } from '../config-provider' ;
5
- import type { StringGradients , ProgressGradient } from './props' ;
5
+ import type { StringGradients , ProgressGradient , ProgressSize } from './props' ;
6
6
import { progressProps } from './props' ;
7
- import { getSuccessPercent , validProgress } from './utils' ;
7
+ import { getSize , getSuccessPercent , validProgress } from './utils' ;
8
+ import devWarning from '../vc-util/devWarning' ;
9
+ import { anyType } from '../_util/type' ;
8
10
9
11
export const lineProps = ( ) => ( {
10
12
...progressProps ( ) ,
11
- prefixCls : String ,
13
+ strokeColor : anyType < string | ProgressGradient > ( ) ,
12
14
direction : {
13
15
type : String as PropType < Direction > ,
14
16
} ,
@@ -84,6 +86,8 @@ export default defineComponent({
84
86
backgroundColor : strokeColor as string ,
85
87
} ;
86
88
} ) ;
89
+ const borderRadius =
90
+ props . strokeLinecap === 'square' || props . strokeLinecap === 'butt' ? 0 : undefined ;
87
91
88
92
const trailStyle = computed < CSSProperties > ( ( ) =>
89
93
props . trailColor
@@ -93,32 +97,53 @@ export default defineComponent({
93
97
: undefined ,
94
98
) ;
95
99
100
+ const mergedSize = computed (
101
+ ( ) => props . size ?? [ - 1 , props . strokeWidth || ( props . size === 'small' ? 6 : 8 ) ] ,
102
+ ) ;
103
+
104
+ const sizeRef = computed ( ( ) =>
105
+ getSize ( mergedSize . value as ProgressSize , 'line' , { strokeWidth : props . strokeWidth } ) ,
106
+ ) ;
107
+
108
+ if ( process . env . NODE_ENV !== 'production' ) {
109
+ devWarning (
110
+ 'strokeWidth' in props ,
111
+ 'Progress' ,
112
+ '`strokeWidth` is deprecated. Please use `size` instead.' ,
113
+ ) ;
114
+ }
115
+
96
116
const percentStyle = computed < CSSProperties > ( ( ) => {
97
- const { percent, strokeWidth , strokeLinecap , size } = props ;
117
+ const { percent } = props ;
98
118
return {
99
119
width : `${ validProgress ( percent ) } %` ,
100
- height : `${ strokeWidth || ( size === 'small' ? 6 : 8 ) } px` ,
101
- borderRadius : strokeLinecap === 'square' ? 0 : undefined ,
102
- ...( backgroundProps . value as any ) ,
120
+ height : `${ sizeRef . value . height } px` ,
121
+ borderRadius,
122
+ ...backgroundProps . value ,
103
123
} ;
104
124
} ) ;
105
125
106
126
const successPercent = computed ( ( ) => {
107
127
return getSuccessPercent ( props ) ;
108
128
} ) ;
109
129
const successPercentStyle = computed < CSSProperties > ( ( ) => {
110
- const { strokeWidth , size , strokeLinecap , success } = props ;
130
+ const { success } = props ;
111
131
return {
112
132
width : `${ validProgress ( successPercent . value ) } %` ,
113
- height : `${ strokeWidth || ( size === 'small' ? 6 : 8 ) } px` ,
114
- borderRadius : strokeLinecap === 'square' ? 0 : undefined ,
133
+ height : `${ sizeRef . value . height } px` ,
134
+ borderRadius,
115
135
backgroundColor : success ?. strokeColor ,
116
136
} ;
117
137
} ) ;
118
138
139
+ const outerStyle : CSSProperties = {
140
+ width : sizeRef . value . width < 0 ? '100%' : sizeRef . value . width ,
141
+ height : `${ sizeRef . value . height } px` ,
142
+ } ;
143
+
119
144
return ( ) => (
120
145
< >
121
- < div { ...attrs } class = { [ `${ props . prefixCls } -outer` , attrs . class ] } >
146
+ < div { ...attrs } class = { [ `${ props . prefixCls } -outer` , attrs . class ] } style = { outerStyle } >
122
147
< div class = { `${ props . prefixCls } -inner` } style = { trailStyle . value } >
123
148
< div class = { `${ props . prefixCls } -bg` } style = { percentStyle . value } />
124
149
{ successPercent . value !== undefined ? (
0 commit comments