Skip to content
Merged
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
1 change: 1 addition & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f
### Enhancements

- Prevented `KeypressListener` attaching/detaching on every render ([#4173](https://github.com/Shopify/polaris-react/pull/4173))
- Added `animated` prop in `ProgressBar` ([#4251](https://github.com/Shopify/polaris-react/pull/4251))

### Bug fixes

Expand Down
8 changes: 5 additions & 3 deletions src/components/ProgressBar/ProgressBar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@
.Indicator {
height: inherit;
width: 0;
will-change: width;
background-color: var(--p-progressbar-indicator);
animation: fillup duration(slowest) easing();
transition: width duration(slowest) easing();

@media screen and (-ms-high-contrast: active) {
border: progress-bar-height() solid
ms-high-contrast-color('selected-text-background');
}
}
.Animated {
will-change: width;
animation: fillup duration(slowest) easing();
transition: width duration(slowest) easing();
}

.Progress,
.Label {
Expand Down
11 changes: 10 additions & 1 deletion src/components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ export interface ProgressBarProps {
* @default 'highlight'
*/
color?: Color;
/**
* Whether the fill animation is triggered
* @default 'true'
*/
animated?: boolean;
}

export function ProgressBar({
progress = 0,
size = 'medium',
color = 'highlight',
animated = true,
}: ProgressBarProps) {
const i18n = useI18n();

Expand All @@ -50,7 +56,10 @@ export function ProgressBar({
return (
<div className={className}>
<progress className={styles.Progress} value={parsedProgress} max="100" />
<div className={styles.Indicator} style={{width: `${parsedProgress}%`}}>
<div
className={classNames(styles.Indicator, animated && styles.Animated)}
style={{width: `${parsedProgress}%`}}
>
<span className={styles.Label}>{parsedProgress}%</span>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/components/ProgressBar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Use the color option when you need to blend the progress bar in a context that c
</div>
```

### Non-animated progress bar

Use the animated prop when you want to show a static progress bar.

```jsx
<ProgressBar progress={80} animated={false} />
```

---

## Related components
Expand Down
40 changes: 28 additions & 12 deletions src/components/ProgressBar/tests/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
import React from 'react';
// eslint-disable-next-line no-restricted-imports
import {mountWithAppProvider} from 'test-utilities/legacy';
import {mountWithApp} from 'test-utilities';

import {ProgressBar} from '../ProgressBar';

describe('<ProgressBar />', () => {
it('sets the progress element to 80 when the progress is 80', () => {
const progress = mountWithAppProvider(<ProgressBar progress={80} />);
expect(progress.find('progress').prop('value')).toBe(80);
const progress = mountWithApp(<ProgressBar progress={80} />);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just updating to not use the legacy test suite

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're a gentleman and a scholar!

expect(progress).toContainReactComponent('progress', {value: 80});
});

it('sets the progress element to 0 when the progress is negative', () => {
const progress = mountWithAppProvider(<ProgressBar progress={-40} />);
expect(progress.find('progress').prop('value')).toBe(0);
const progress = mountWithApp(<ProgressBar progress={-40} />);
expect(progress).toContainReactComponent('progress', {value: 0});
});

it('sets the progress element to 100 when the progress is greater than 100', () => {
const progress = mountWithAppProvider(<ProgressBar progress={120} />);
expect(progress.find('progress').prop('value')).toBe(100);
const progress = mountWithApp(<ProgressBar progress={120} />);
expect(progress).toContainReactComponent('progress', {value: 100});
});

it('sets the progress element to 0 when progress is not provided', () => {
const progress = mountWithAppProvider(<ProgressBar />);
expect(progress.find('progress').prop('value')).toBe(0);
const progress = mountWithApp(<ProgressBar />);
expect(progress).toContainReactComponent('progress', {value: 0});
});

describe('animated prop', () => {
it('sets the progress bar to include the Animated class by default', () => {
const progress = mountWithApp(<ProgressBar progress={20} />);
expect(progress).toContainReactComponent('div', {
className: 'Indicator Animated',
});
});
it('sets the progress bar to exclude the Animated class when animated is false', () => {
const progress = mountWithApp(
<ProgressBar animated={false} progress={20} />,
);
expect(progress).toContainReactComponent('div', {
className: 'Indicator',
});
});
});

describe('console.warn', () => {
Expand All @@ -46,7 +62,7 @@ describe('<ProgressBar />', () => {
it('warns when a negative number is passed to progress in development', () => {
process.env.NODE_ENV = 'development';

mountWithAppProvider(<ProgressBar progress={-1} />);
mountWithApp(<ProgressBar progress={-1} />);

expect(warnSpy).toHaveBeenCalledWith(
'Values passed to the progress prop shouldn’t be negative. Resetting -1 to 0.',
Expand All @@ -56,7 +72,7 @@ describe('<ProgressBar />', () => {
it('warns when a number larger than 100 is passed to progress in development', () => {
process.env.NODE_ENV = 'development';

mountWithAppProvider(<ProgressBar progress={101} />);
mountWithApp(<ProgressBar progress={101} />);

expect(warnSpy).toHaveBeenCalledWith(
'Values passed to the progress prop shouldn’t exceed 100. Setting 101 to 100.',
Expand Down