Skip to content

Commit

Permalink
Merge 16795e3 into ce2c674
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerJDev authored Aug 23, 2024
2 parents ce2c674 + 16795e3 commit 2cd5c70
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions packages/react/src/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const shimmer = keyframes`
to { mask-position: 0%; }
`

export const Item = styled.span<ProgressProp & SxProp>`
const ProgressItem = styled.span<ProgressProp & SxProp>`
width: ${props => (props.progress ? `${props.progress}%` : 0)};
background-color: ${get('colors.success.emphasis')};
Expand All @@ -31,8 +31,6 @@ export const Item = styled.span<ProgressProp & SxProp>`
${sx};
`

Item.displayName = 'ProgressBar.Item'

const sizeMap = {
small: '5px',
large: '10px',
Expand All @@ -57,21 +55,12 @@ const ProgressContainer = styled.span<StyledProgressContainerProps>`
${sx};
`

export type ProgressBarProps = React.HTMLAttributes<HTMLSpanElement> & {bg?: string} & StyledProgressContainerProps &
ProgressProp

export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
(
{animated, progress, bg = 'success.emphasis', barSize = 'default', children, ...rest}: ProgressBarProps,
forwardRef,
) => {
if (children && progress) {
throw new Error('You should pass `progress` or children, not both.')
}
export type ProgressBarItems = React.HTMLAttributes<HTMLSpanElement> & {'aria-label'?: string} & ProgressProp & SxProp

export const Item = forwardRef<HTMLSpanElement, ProgressBarItems>(
({progress, 'aria-label': ariaLabel, ...rest}, forwardRef) => {
warning(
children &&
typeof (rest as React.AriaAttributes)['aria-valuenow'] === 'undefined' &&
typeof (rest as React.AriaAttributes)['aria-valuenow'] === 'undefined' &&
typeof (rest as React.AriaAttributes)['aria-valuetext'] === 'undefined',
'Expected `aria-valuenow` or `aria-valuetext` to be provided to <ProgressBar>. Provide one of these values so screen reader users can determine the current progress. This warning will become an error in the next major release.',
)
Expand All @@ -85,8 +74,45 @@ export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
}

return (
<ProgressContainer ref={forwardRef} role="progressbar" barSize={barSize} {...ariaAttributes} {...rest}>
{children ?? <Item data-animated={animated} progress={progress} sx={{backgroundColor: bg}} />}
<ProgressItem
role="progressbar"
aria-label={ariaLabel}
ref={forwardRef}
progress={progress}
{...ariaAttributes}
{...rest}
/>
)
},
)

Item.displayName = 'ProgressBar.Item'

export type ProgressBarProps = React.HTMLAttributes<HTMLSpanElement> & {bg?: string} & StyledProgressContainerProps &
ProgressProp

export const ProgressBar = forwardRef<HTMLSpanElement, ProgressBarProps>(
(
{
animated,
progress,
bg = 'success.emphasis',
barSize = 'default',
children,
'aria-label': ariaLabel,
...rest
}: ProgressBarProps,
forwardRef,
) => {
if (children && progress) {
throw new Error('You should pass `progress` or children, not both.')
}

return (
<ProgressContainer ref={forwardRef} barSize={barSize} {...rest}>
{children ?? (
<Item data-animated={animated} progress={progress} aria-label={ariaLabel} sx={{backgroundColor: bg}} />
)}
</ProgressContainer>
)
},
Expand Down

0 comments on commit 2cd5c70

Please sign in to comment.