1- import type { StyleXStyles } from '@stylexjs/stylex ' ;
1+ import type { ProgressBarVariants } from './styles/ProgressBar.css ' ;
22import type { ForwardedRef } from 'react' ;
33import type { ProgressBarProps as AriaProgressBarProps } from 'react-aria-components' ;
44
5- import * as stylex from '@stylexjs/stylex' ;
65import { clsx } from 'clsx' ;
76import { forwardRef } from 'react' ;
87import { ProgressBar as AriaProgressBar } from 'react-aria-components' ;
98
10- import { tokens } from './tokens.stylex ' ;
9+ import { base , indeterminate , outerCircle , innerCircle , variants } from './styles/ProgressBar.css ' ;
1110
12- const spin = stylex . keyframes ( {
13- from : { transform : 'rotate(0deg)' } ,
14- to : { transform : 'rotate(359deg)' } ,
15- } ) ;
16-
17- const styles = stylex . create ( {
18- base : {
19- display : 'inline-block' ,
20- transformOrigin : '0 0' ,
21- } ,
22- indeterminate : {
23- animationName : spin ,
24- animationDuration : tokens [ 'duration.350' ] ,
25- animationTimingFunction : 'linear' ,
26- animationIterationCount : 'infinite' ,
27- } ,
28- outerCircle : {
29- stroke : tokens [ 'color.white.100' ] ,
30- } ,
31- innerCircle : {
32- stroke : tokens [ 'color.gray.500' ] ,
33- } ,
34- } ) ;
35-
36- const variants = stylex . create ( {
37- small : {
38- transform : 'scale(0.25)' ,
39- } ,
40- medium : {
41- transform : 'scale(0.375)' ,
42- } ,
43- large : {
44- transform : 'scale(0.5)' ,
45- } ,
46- } ) ;
47-
48- interface ProgressBarProps extends Omit < AriaProgressBarProps , 'style' > {
49- style ?: StyleXStyles ;
50- size ?: keyof typeof variants ;
51- }
11+ type ProgressBarProps = AriaProgressBarProps & ProgressBarVariants ;
5212
5313const ProgressBar = forwardRef (
5414 (
55- { style , size = 'small' , className, ...props } : ProgressBarProps ,
15+ { size = 'small' , className, ...props } : ProgressBarProps ,
5616 ref : ForwardedRef < HTMLDivElement >
5717 ) => {
5818 const center = 16 ;
5919 const strokeWidth = 4 ;
6020 const r = 16 - strokeWidth ;
6121 const c = 2 * r * Math . PI ;
6222
63- const stylexProps = stylex . props ( styles . base , variants [ size ] , style ) ;
64-
6523 return (
66- < AriaProgressBar
67- { ...props }
68- ref = { ref }
69- className = { clsx ( stylexProps . className , className ) }
70- style = { stylexProps . style }
71- >
24+ < AriaProgressBar { ...props } ref = { ref } className = { clsx ( base , variants ( { size } ) , className ) } >
7225 { ( { percentage } ) => (
7326 < svg
7427 width = { 64 }
7528 height = { 64 }
7629 viewBox = "0 0 32 32"
7730 fill = "none"
7831 strokeWidth = { strokeWidth }
79- { ... stylex . props ( props . isIndeterminate && styles . indeterminate ) }
32+ className = { clsx ( props . isIndeterminate && indeterminate ) }
8033 >
8134 < circle
8235 cx = { center }
8336 cy = { center }
8437 r = { r }
8538 strokeWidth = { strokeWidth }
86- { ... stylex . props ( styles . outerCircle ) }
39+ className = { outerCircle }
8740 />
8841 < circle
8942 cx = { center }
@@ -92,7 +45,7 @@ const ProgressBar = forwardRef(
9245 strokeDasharray = { `${ c } ${ c } ` }
9346 strokeDashoffset = { c - ( props . isIndeterminate ? 0.34 : percentage ! / 100 ) * c }
9447 transform = "rotate(-90 16 16)"
95- { ... stylex . props ( styles . innerCircle ) }
48+ className = { innerCircle }
9649 />
9750 </ svg >
9851 ) }
0 commit comments