11import React , { forwardRef } from 'react'
2- import styled , { keyframes } from 'styled-components'
32import type { WidthProps } from 'styled-system'
4- import { width } from 'styled-system'
5- import { get } from '../constants'
63import type { SxProp } from '../sx'
7- import sx from '../sx'
8- import { toggleStyledComponent } from '../internal/utils/toggleStyledComponent'
94import { clsx } from 'clsx'
105import classes from './ProgressBar.module.css'
11- import { useFeatureFlag } from '../FeatureFlags '
6+ import { BoxWithFallback } from '../internal/components/BoxWithFallback '
127
138type ProgressProp = {
149 className ?: string
1510 progress ?: string | number
1611 bg ?: string
1712}
1813
19- const shimmer = keyframes `
20- from { mask-position: 200%; }
21- to { mask-position: 0%; }
22- `
23-
24- const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'
25-
26- const ProgressItem = toggleStyledComponent (
27- CSS_MODULES_FEATURE_FLAG ,
28- 'span' ,
29- styled . span < ProgressProp & SxProp > `
30- width: ${ props => ( props . progress ? `${ props . progress } %` : 0 ) } ;
31- background-color: ${ props => get ( `colors.${ props . bg || 'success.emphasis' } ` ) } ;
32-
33- @media (prefers-reduced-motion: no-preference) {
34- &[data-animated='true'] {
35- mask-image: linear-gradient(75deg, #000 30%, rgba(0, 0, 0, 0.65) 80%);
36- mask-size: 200%;
37- animation: ${ shimmer } ;
38- animation-duration: 1s;
39- animation-iteration-count: infinite;
40- }
41- }
42-
43- ${ sx } ;
44- ` ,
45- )
46-
4714const sizeMap = {
4815 small : '5px' ,
4916 large : '10px' ,
@@ -57,21 +24,6 @@ type StyledProgressContainerProps = {
5724} & WidthProps &
5825 SxProp
5926
60- const ProgressContainer = toggleStyledComponent (
61- CSS_MODULES_FEATURE_FLAG ,
62- 'span' ,
63- styled . span < StyledProgressContainerProps > `
64- display: ${ props => ( props . inline ? 'inline-flex' : 'flex' ) } ;
65- overflow: hidden;
66- background-color: ${ get ( 'colors.border.default' ) } ;
67- border-radius: ${ get ( 'radii.1' ) } ;
68- height: ${ props => sizeMap [ props . barSize || 'default' ] } ;
69- gap: 2px;
70- ${ width }
71- ${ sx } ;
72- ` ,
73- )
74-
7527export type ProgressBarItems = React . HTMLAttributes < HTMLSpanElement > & {
7628 'aria-label' ?: string
7729 className ?: string
@@ -100,8 +52,6 @@ export const Item = forwardRef<HTMLSpanElement, ProgressBarItems>(
10052 'aria-valuetext' : ariaValueText ,
10153 }
10254
103- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
104-
10555 const progressBarWidth = '--progress-width'
10656 const progressBarBg = '--progress-bg'
10757 const styles : { [ key : string ] : string } = { }
@@ -111,14 +61,15 @@ export const Item = forwardRef<HTMLSpanElement, ProgressBarItems>(
11161 styles [ progressBarBg ] = ( bgType && `var(--bgColor-${ bgType [ 0 ] } -${ bgType [ 1 ] } )` ) || 'var(--bgColor-success-emphasis)'
11262
11363 return (
114- < ProgressItem
115- className = { clsx ( className , { [ classes . ProgressBarItem ] : enabled } ) }
64+ < BoxWithFallback
65+ as = "span"
66+ className = { clsx ( className , classes . ProgressBarItem ) }
11667 { ...rest }
11768 role = "progressbar"
11869 aria-label = { ariaLabel }
11970 ref = { forwardRef }
12071 progress = { progress }
121- style = { enabled ? styles : undefined }
72+ style = { styles }
12273 { ...ariaAttributes }
12374 />
12475 )
@@ -145,6 +96,7 @@ export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
14596 'aria-valuenow' : ariaValueNow ,
14697 'aria-valuetext' : ariaValueText ,
14798 className,
99+ inline,
148100 ...rest
149101 } : ProgressBarProps ,
150102 forwardRef ,
@@ -156,17 +108,14 @@ export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
156108 // Get the number of non-empty nodes passed as children, this will exclude
157109 // booleans, null, and undefined
158110 const validChildren = React . Children . toArray ( children ) . length
159- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
160-
161- const cssModulesProps = ! enabled
162- ? { barSize}
163- : { 'data-progress-display' : rest . inline ? 'inline' : 'block' , 'data-progress-bar-size' : barSize }
164111
165112 return (
166- < ProgressContainer
113+ < BoxWithFallback
114+ as = "span"
167115 ref = { forwardRef }
168- className = { clsx ( className , { [ classes . ProgressBarContainer ] : enabled } ) }
169- { ...cssModulesProps }
116+ className = { clsx ( className , classes . ProgressBarContainer ) }
117+ data-progress-display = { inline ? 'inline' : 'block' }
118+ data-progress-bar-size = { barSize }
170119 { ...rest }
171120 >
172121 { validChildren ? (
@@ -181,7 +130,7 @@ export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
181130 bg = { bg }
182131 />
183132 ) }
184- </ ProgressContainer >
133+ </ BoxWithFallback >
185134 )
186135 } ,
187136)
0 commit comments