@@ -73,7 +73,7 @@ const ProgressContainer = toggleStyledComponent(
73
73
)
74
74
75
75
export type ProgressBarItems = React . HTMLAttributes < HTMLSpanElement > & {
76
- 'aria-label' ? : string
76
+ 'aria-label' : string
77
77
className ?: string
78
78
} & ProgressProp &
79
79
SxProp
@@ -127,63 +127,75 @@ export const Item = forwardRef<HTMLSpanElement, ProgressBarItems>(
127
127
128
128
Item . displayName = 'ProgressBar.Item'
129
129
130
- export type ProgressBarProps = React . HTMLAttributes < HTMLSpanElement > & {
131
- bg ?: string
132
- className ?: string
133
- } & StyledProgressContainerProps &
134
- ProgressProp
135
-
136
- export const ProgressBar = forwardRef < HTMLSpanElement , ProgressBarProps > (
137
- (
138
- {
139
- animated,
140
- progress,
141
- bg = 'success.emphasis' ,
142
- barSize = 'default' ,
143
- children,
144
- 'aria-label' : ariaLabel ,
145
- 'aria-valuenow' : ariaValueNow ,
146
- 'aria-valuetext' : ariaValueText ,
147
- className,
148
- ...rest
149
- } : ProgressBarProps ,
150
- forwardRef ,
151
- ) => {
152
- if ( children && progress ) {
153
- throw new Error ( 'You should pass `progress` or children, not both.' )
154
- }
155
-
156
- // Get the number of non-empty nodes passed as children, this will exclude
157
- // booleans, null, and undefined
158
- const validChildren = React . Children . toArray ( children ) . length
159
- const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
130
+ export type ProgressBarBaseProps = Omit <
131
+ React . HTMLAttributes < HTMLSpanElement > & {
132
+ bg ?: string
133
+ className ?: string
134
+ } & StyledProgressContainerProps &
135
+ ProgressProp ,
136
+ 'children' | 'aria-label'
137
+ >
138
+
139
+ export type WithChildren = {
140
+ children : React . ReactNode
141
+ 'aria-label' ?: never
142
+ }
160
143
161
- const cssModulesProps = ! enabled
162
- ? { barSize}
163
- : { 'data-progress-display' : rest . inline ? 'inline' : 'block' , 'data-progress-bar-size' : barSize }
144
+ export type WithoutChildren = {
145
+ children ?: never
146
+ 'aria-label' : string
147
+ }
164
148
165
- return (
166
- < ProgressContainer
167
- ref = { forwardRef }
168
- className = { clsx ( className , { [ classes . ProgressBarContainer ] : enabled } ) }
169
- { ...cssModulesProps }
170
- { ...rest }
171
- >
172
- { validChildren ? (
173
- children
174
- ) : (
175
- < Item
176
- data-animated = { animated }
177
- progress = { progress }
178
- aria-label = { ariaLabel }
179
- aria-valuenow = { ariaValueNow }
180
- aria-valuetext = { ariaValueText }
181
- bg = { bg }
182
- />
183
- ) }
184
- </ ProgressContainer >
185
- )
186
- } ,
187
- )
149
+ export type ProgressBarProps = ProgressBarBaseProps & ( WithChildren | WithoutChildren )
150
+
151
+ export const ProgressBar = forwardRef < HTMLSpanElement , ProgressBarProps > ( ( props , forwardRef ) => {
152
+ const {
153
+ animated,
154
+ progress,
155
+ bg = 'success.emphasis' ,
156
+ barSize = 'default' ,
157
+ children,
158
+ 'aria-label' : ariaLabel ,
159
+ 'aria-valuenow' : ariaValueNow ,
160
+ 'aria-valuetext' : ariaValueText ,
161
+ className,
162
+ ...rest
163
+ } = props
164
+
165
+ if ( children && progress ) {
166
+ throw new Error ( 'You should pass `progress` or children, not both.' )
167
+ }
168
+
169
+ // Get the number of non-empty nodes passed as children, this will exclude
170
+ // booleans, null, and undefined
171
+ const validChildren = React . Children . toArray ( children ) . length
172
+ const enabled = useFeatureFlag ( CSS_MODULES_FEATURE_FLAG )
173
+
174
+ const cssModulesProps = ! enabled
175
+ ? { barSize}
176
+ : { 'data-progress-display' : rest . inline ? 'inline' : 'block' , 'data-progress-bar-size' : barSize }
177
+
178
+ return (
179
+ < ProgressContainer
180
+ ref = { forwardRef }
181
+ className = { clsx ( className , { [ classes . ProgressBarContainer ] : enabled } ) }
182
+ { ...cssModulesProps }
183
+ { ...rest }
184
+ >
185
+ { validChildren ? (
186
+ children
187
+ ) : (
188
+ < Item
189
+ data-animated = { animated }
190
+ progress = { progress }
191
+ aria-label = { ariaLabel as string }
192
+ aria-valuenow = { ariaValueNow }
193
+ aria-valuetext = { ariaValueText }
194
+ bg = { bg }
195
+ />
196
+ ) }
197
+ </ ProgressContainer >
198
+ )
199
+ } )
188
200
189
201
ProgressBar . displayName = 'ProgressBar'
0 commit comments