Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-progress): add isRounded to ProgressBar #1805

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/ui-progress/src/ProgressBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ type: example
> `<ProgressBar />` defaults to setting the meter color to `success` when
> complete.

### `isRounded`

Rounded variant of the progress bar is available via the `isRounded` prop

```js
---
type: example
---
<div>
<ProgressBar
size="x-small"
screenReaderLabel="Loading completion"
valueNow={40}
valueMax={60}
margin="0 0 small"
/>
<ProgressBar
size="small"
screenReaderLabel="Loading completion"
valueNow={40}
valueMax={60}
margin="0 0 small"
/>
<ProgressBar
screenReaderLabel="Loading completion"
valueNow={40}
valueMax={60}
margin="0 0 small"
/>
<ProgressBar
size="large"
screenReaderLabel="Loading completion"
valueNow={60}
valueMax={60}
isRounded
/>
</div>
```

### `renderValue` / `formatScreenReaderValue`

Via the `renderValue` prop, developers can use `valueMax` and `valueNow` props to format the
Expand Down
7 changes: 7 additions & 0 deletions packages/ui-progress/src/ProgressBar/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ type ProgressBarOwnProps = {
*/
margin?: Spacing

/**
* Control the border-radius of the progress meter.
*/
isRounded?: boolean

/**
* Provides a reference to the component's root HTML element
*/
Expand Down Expand Up @@ -147,6 +152,7 @@ const propTypes: PropValidators<PropKeys> = {
]),
shouldAnimate: PropTypes.bool,
margin: ThemeablePropTypes.spacing,
isRounded: PropTypes.bool,
elementRef: PropTypes.func,
as: PropTypes.elementType
}
Expand All @@ -162,6 +168,7 @@ const allowedProps: AllowedPropKeys = [
'meterColor',
'shouldAnimate',
'margin',
'isRounded',
'elementRef',
'as'
]
Expand Down
7 changes: 6 additions & 1 deletion packages/ui-progress/src/ProgressBar/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const generateStyle = (
size,
color,
meterColor,
shouldAnimate
shouldAnimate,
isRounded
} = props

const meterColorClassName =
Expand All @@ -58,6 +59,8 @@ const generateStyle = (

const currentValuePercent = `${(currentValue / valueMax) * 100}%`

const borderRadius = isRounded ? '20px' : 0

const sizeVariants = {
'x-small': {
track: { height: componentTheme.xSmallHeight },
Expand Down Expand Up @@ -138,6 +141,7 @@ const generateStyle = (
borderBottomWidth: componentTheme.trackBottomBorderWidth,
borderBottomStyle: 'solid',
background: 'transparent',
borderRadius,

...sizeVariants[size!].track,
...colorVariants[color!].trackBorder
Expand All @@ -150,6 +154,7 @@ const generateStyle = (
height: '100%',
width: currentValuePercent,
maxWidth: '100%',
borderRadius,

...(shouldAnimate && { transition: 'all 0.5s' }),
...(meterColorClassName &&
Expand Down
Loading