1
1
import type { CSSProperties } from 'vue' ;
2
2
import { computed , defineComponent } from 'vue' ;
3
- import { presetPrimaryColors } from '@ant-design/colors' ;
4
3
import { Circle as VCCircle } from '../vc-progress' ;
5
- import { getSuccessPercent , validProgress } from './utils' ;
4
+ import { getPercentage , getStrokeColor } from './utils' ;
6
5
import type { ProgressProps } from './props' ;
7
6
import { progressProps } from './props' ;
7
+ import { initDefaultProps } from '../_util/props-util' ;
8
+ import Tooltip from '../tooltip' ;
8
9
9
10
export type CircleProps = ProgressProps ;
10
11
11
- function getPercentage ( { percent, success, successPercent } : CircleProps ) {
12
- const realSuccessPercent = validProgress ( getSuccessPercent ( { success, successPercent } ) ) ;
13
- return [ realSuccessPercent , validProgress ( validProgress ( percent ) - realSuccessPercent ) ] ;
14
- }
12
+ const CIRCLE_MIN_STROKE_WIDTH = 3 ;
15
13
16
- function getStrokeColor ( {
17
- success = { } ,
18
- strokeColor,
19
- } : Partial < CircleProps > ) : ( string | Record < string , string > ) [ ] {
20
- const { strokeColor : successColor } = success ;
21
- return [ successColor || presetPrimaryColors . green , strokeColor || null ! ] ;
22
- }
14
+ const getMinPercent = ( width : number ) : number => ( CIRCLE_MIN_STROKE_WIDTH / width ) * 100 ;
23
15
24
16
export default defineComponent ( {
25
17
compatConfig : { MODE : 3 } ,
26
18
name : 'Circle' ,
27
19
inheritAttrs : false ,
28
- props : progressProps ( ) ,
20
+ props : initDefaultProps ( progressProps ( ) , {
21
+ width : 120 ,
22
+ trailColor : null as unknown as string ,
23
+ } ) ,
29
24
setup ( props , { slots } ) {
30
25
const gapDeg = computed ( ( ) => {
31
26
// Support gapDeg = 0 when type = 'dashboard'
@@ -39,17 +34,19 @@ export default defineComponent({
39
34
} ) ;
40
35
41
36
const circleStyle = computed < CSSProperties > ( ( ) => {
42
- const circleSize = props . width || 120 ;
37
+ const circleSize = props . width ;
43
38
return {
44
39
width : typeof circleSize === 'number' ? `${ circleSize } px` : circleSize ,
45
40
height : typeof circleSize === 'number' ? `${ circleSize } px` : circleSize ,
46
41
fontSize : `${ circleSize * 0.15 + 6 } px` ,
47
42
} ;
48
43
} ) ;
49
44
50
- const circleWidth = computed ( ( ) => props . strokeWidth || 6 ) ;
45
+ const circleWidth = computed (
46
+ ( ) => props . strokeWidth ?? Math . max ( getMinPercent ( props . width ) , 6 ) ,
47
+ ) ;
51
48
const gapPos = computed (
52
- ( ) => props . gapPosition || ( props . type === 'dashboard' && 'bottom' ) || 'top' ,
49
+ ( ) => props . gapPosition || ( props . type === 'dashboard' && 'bottom' ) || undefined ,
53
50
) ;
54
51
55
52
// using className to style stroke color
@@ -65,8 +62,8 @@ export default defineComponent({
65
62
[ `${ props . prefixCls } -circle-gradient` ] : isGradient . value ,
66
63
} ) ) ;
67
64
68
- return ( ) => (
69
- < div class = { wrapperClassName . value } style = { circleStyle . value } >
65
+ return ( ) => {
66
+ const circleContent = (
70
67
< VCCircle
71
68
percent = { percent . value }
72
69
strokeWidth = { circleWidth . value }
@@ -78,8 +75,19 @@ export default defineComponent({
78
75
gapDegree = { gapDeg . value }
79
76
gapPosition = { gapPos . value }
80
77
/>
81
- { slots . default ?.( ) }
82
- </ div >
83
- ) ;
78
+ ) ;
79
+ return (
80
+ < div class = { wrapperClassName . value } style = { circleStyle . value } >
81
+ { props . width <= 20 ? (
82
+ < Tooltip v-slots = { { title : slots . default } } > { circleContent } </ Tooltip >
83
+ ) : (
84
+ < >
85
+ { circleContent }
86
+ { slots . default ?.( ) }
87
+ </ >
88
+ ) }
89
+ </ div >
90
+ ) ;
91
+ } ;
84
92
} ,
85
93
} ) ;
0 commit comments