11
11
*/
12
12
13
13
import { CSSResultArray , html , TemplateResult } from 'lit' ;
14
- import { classMap } from 'lit/directives/class-map .js' ;
14
+ import { ifDefined } from 'lit/directives/if-defined .js' ;
15
15
16
16
import { ProgressCircleBase } from '@swc/core/components/progress-circle' ;
17
17
18
18
import progressCircleStyles from './progress-circle.css' ;
19
19
20
- function capitalize ( str ?: string ) : string {
21
- if ( typeof str !== 'string' ) {
22
- return '' ;
23
- }
24
- return str . charAt ( 0 ) . toUpperCase ( ) + str . slice ( 1 ) ;
25
- }
26
20
/**
27
21
* A progress circle component that visually represents the completion progress of a task.
28
22
* Can be used in both determinate (with specific progress value) and indeterminate (loading) states.
@@ -31,7 +25,12 @@ function capitalize(str?: string): string {
31
25
* @since 2.0.0
32
26
* @status stable
33
27
* @github https://github.com/adobe/spectrum-web-components/tree/main/second-gen/packages/swc/components/progress-circle
34
- * @figma https://www.figma.com/design/Mngz9H7WZLbrCvGQf3GnsY/S2-%2F-Desktop?node-id=13061-181
28
+ * @figma https://spectrum.figma.com/file/progress-circle
29
+ *
30
+ * @slot - Optional content to display inside the progress circle (e.g., percentage text)
31
+ *
32
+ * @csspart track - The background track of the progress circle
33
+ * @csspart fill - The filled portion of the progress circle
35
34
*
36
35
* @fires progress-change - Dispatched when the progress value changes
37
36
*
@@ -47,51 +46,29 @@ export class ProgressCircle extends ProgressCircleBase {
47
46
}
48
47
49
48
protected override render ( ) : TemplateResult {
50
- // SVG strokes are centered, so subtract half the stroke width from the radius to create an inner stroke.
51
- const radius = `calc(50% - ${ this . strokeWidth / 2 } px)` ;
52
-
49
+ const styles = [
50
+ this . makeRotation ( - 180 + ( 180 / 50 ) * Math . min ( this . progress , 50 ) ) ,
51
+ this . makeRotation (
52
+ - 180 + ( 180 / 50 ) * Math . max ( this . progress - 50 , 0 )
53
+ ) ,
54
+ ] ;
55
+ const masks = [ 'Mask1' , 'Mask2' ] ;
53
56
return html `
54
- < div
55
- class =${ classMap ( {
56
- [ 'spectrum-ProgressCircle' ] : true ,
57
- [ `spectrum-ProgressCircle--indeterminate` ] :
58
- this . indeterminate ,
59
- [ `spectrum-ProgressCircle--static${ capitalize ( this . staticColor ) } ` ] :
60
- typeof this . staticColor !== 'undefined' ,
61
- [ `spectrum-ProgressCircle--size${ this . size ?. toUpperCase ( ) } ` ] :
62
- typeof this . size !== 'undefined' ,
63
- } ) }
64
- >
65
- < svg
66
- fill ="none "
67
- width ="100% "
68
- height ="100% "
69
- class ="spectrum-outerCircle "
70
- >
71
- < circle
72
- class ="spectrum-innerCircle "
73
- cx ="50% "
74
- cy ="50% "
75
- r =${ `calc(50% - ${ this . strokeWidth / 1 } px)` }
76
- stroke-width =${ this . strokeWidth }
77
- />
78
- < circle
79
- cx ="50% "
80
- cy ="50% "
81
- class ="spectrum-ProgressCircle-track "
82
- r =${ radius }
83
- / >
84
- < circle
85
- cx ="50% "
86
- cy ="50% "
87
- r =${ radius }
88
- class ="spectrum-ProgressCircle-fill"
89
- pathLength="100"
90
- stroke-dasharray="100 200"
91
- stroke-dashoffset=${ 100 - this . progress }
92
- stroke-linecap="round"
93
- />
94
- </ svg >
57
+ < slot @slotchange =${ this . handleSlotchange } > </ slot >
58
+ < div class ="track "> </ div >
59
+ < div class ="fills ">
60
+ ${ masks . map (
61
+ ( mask , index ) => html `
62
+ < div class ="fill ${ mask } ">
63
+ < div
64
+ class ="fillSub ${ mask } "
65
+ style =${ ifDefined ( styles [ index ] ) }
66
+ >
67
+ < div class ="fill "> </ div >
68
+ </ div >
69
+ </ div >
70
+ `
71
+ ) }
95
72
</ div >
96
73
` ;
97
74
}
0 commit comments