Skip to content

Commit 40fadf8

Browse files
fullofcaffeinetyxlamirkaDaniGuardiolajasmussen
authored andcommitted
ProgressBar: Simplify default width implementation and make it more easily overridable (WordPress#61976)
* Remove "experimental" designation for `ProgressBar` * Add optional width prop to override/set the progress bar track container * Revert "Add optional width prop to override/set the progress bar track container" This reverts commit b1fe7cd. * Keep an unconstrained width by default, while allowing consumers to override it with CSS * Revert "Keep an unconstrained width by default, while allowing consumers to override it with CSS" This reverts commit 64c72e2. * Make the component public * Update consumers to import the public component * Expose docs for the now public ProgressBar component * Update CHANGELOG * Run docs:build after docs/manifest.js change * Remove remaining private usage of ProgressBar * Small formatting fix in the changelog * Add basic docs to the README * Add jsdoc * Formatting fix in README jsx block Co-authored-by: Marin Atanasov <[email protected]> * Another formatting fix in README jsx block Co-authored-by: Marin Atanasov <[email protected]> * YAFF (yet another formatting fix) in the README jsx Co-authored-by: Marin Atanasov <[email protected]> * Improve wording in descripton of the `value` prop in the README Co-authored-by: Marin Atanasov <[email protected]> * YAFF: Missing semicolon in README jsx Co-authored-by: Marin Atanasov <[email protected]> * YAFF: missing semicolon in jsx block in README Co-authored-by: Marin Atanasov <[email protected]> * YAFF: missing semicolon in jsx block in README Co-authored-by: Marin Atanasov <[email protected]> * YAFF: use tab instead of spaces in jsx code block in README Co-authored-by: Marin Atanasov <[email protected]> * Move export out of the HOC export section * Fix CHANGELOG: Move entry to the existing enhacements section * Spacing fix Co-authored-by: Marin Atanasov <[email protected]> * Sort import alphabetically * Allow `ProgressBar` to have unconstrained width, which is disabled by default It has a default `max-width` of 160px, but allows consumers to explicitely disable it so that it expands to fit the parent's width by default. Consumers can then optionally set another width the way they see fit via a custom `className`. * Revert "Allow `ProgressBar` to have unconstrained width, which is disabled by default" This reverts commit 7a00da3. * Update docs and add story to illustrate a custom width * Update CHANGELOG * Simplify description in the story Co-authored-by: Marin Atanasov <[email protected]> * Improve jsdoc in story, do not encourage more customization than needed * Inherit the second story from the main template --------- Co-authored-by: fullofcaffeine <[email protected]> Co-authored-by: tyxla <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: DaniGuardiola <[email protected]> Co-authored-by: jasmussen <[email protected]>
1 parent 1050e1f commit 40fadf8

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- `Tabs`: Animate indicator ([#60560](https://github.com/WordPress/gutenberg/pull/60560)).
1313
- `ComboboxControl`: Introduce Combobox expandOnFocus prop ([#61705](https://github.com/WordPress/gutenberg/pull/61705)).
1414
- `ProgressBar`: Expose as public API ([#61062](https://github.com/WordPress/gutenberg/pull/61062)).
15+
- `ProgressBar`: Simplify default width implementation and make it more easily overridable ([#61976](https://github.com/WordPress/gutenberg/pull/61976)).
1516

1617
### Bug Fixes
1718

packages/components/src/progress-bar/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@ const MyLoadingComponent = ( { progress } ) => {
2626
};
2727
```
2828

29-
You can customize its appearance by passing a custom CSS class name to `className`:
29+
You can customize its appearance by passing a custom CSS class name to `className`.
3030

31+
```css
32+
.my-custom-progress-bar {
33+
width: 100%;
34+
}
35+
```
3136

3237
```jsx
3338
import { ProgressBar } from '@wordpress/components';
3439

3540
const MyLoadingComponent = () => {
36-
return <ProgressBar className="my-custom-css-class" />;
41+
return <ProgressBar className="my-custom-progress-bar" />;
3742
};
3843
```
3944

@@ -52,7 +57,7 @@ If a `value` is not specified, the progress bar will be considered indeterminate
5257

5358
A CSS class to apply to the underlying `div` element, serving as a progress bar track.
5459

55-
- Required: No
60+
- Required: No
5661

5762
#### Inherited props
5863

packages/components/src/progress-bar/stories/index.story.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,38 @@ const Template: StoryFn< typeof ProgressBar > = ( { ...args } ) => {
2929

3030
export const Default: StoryFn< typeof ProgressBar > = Template.bind( {} );
3131
Default.args = {};
32+
33+
const withCustomWidthCustomCSS = `
34+
.custom-progress-bar {
35+
width: 100%;
36+
}
37+
`;
38+
39+
/**
40+
* A progress bar with a custom width.
41+
*
42+
* You can override the default `width` by passing a custom CSS class via the
43+
* `className` prop.
44+
*
45+
* This example shows a progress bar with an overriden `width` of `100%` which
46+
* makes it fit all available horizontal space of the parent element. The CSS
47+
* class looks like this:
48+
*
49+
* ```css
50+
* .custom-progress-bar {
51+
* width: 100%;
52+
* }
53+
* ```
54+
*/
55+
export const WithCustomWidth = Template.bind( {} );
56+
WithCustomWidth.args = {
57+
className: 'custom-progress-bar',
58+
};
59+
WithCustomWidth.decorators = [
60+
( Story ) => (
61+
<>
62+
<style>{ withCustomWidthCustomCSS }</style>
63+
<Story />
64+
</>
65+
),
66+
];

packages/components/src/progress-bar/styles.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ export const INDETERMINATE_TRACK_WIDTH = 50;
2424
export const Track = styled.div`
2525
position: relative;
2626
overflow: hidden;
27-
width: 100%;
28-
max-width: 160px;
2927
height: ${ CONFIG.borderWidthFocus };
3028
/* Text color at 10% opacity */
3129
background-color: color-mix(
@@ -38,6 +36,10 @@ export const Track = styled.div`
3836
// Windows high contrast mode.
3937
outline: 2px solid transparent;
4038
outline-offset: 2px;
39+
40+
:where( & ) {
41+
width: 160px;
42+
}
4143
`;
4244

4345
export const Indicator = styled.div< {

0 commit comments

Comments
 (0)