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

ProgressBar: Simplify default width implementation and make it more easily overridable #61976

Merged
merged 37 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
023e5c4
Remove "experimental" designation for `ProgressBar`
fullofcaffeine Apr 19, 2024
b1fe7cd
Add optional width prop to override/set the progress bar track container
fullofcaffeine Apr 25, 2024
fe9129d
Revert "Add optional width prop to override/set the progress bar trac…
fullofcaffeine May 22, 2024
64c72e2
Keep an unconstrained width by default, while allowing consumers to o…
fullofcaffeine May 22, 2024
c88ece0
Revert "Keep an unconstrained width by default, while allowing consum…
fullofcaffeine May 24, 2024
ad0fff9
Make the component public
fullofcaffeine May 24, 2024
dc299ed
Update consumers to import the public component
fullofcaffeine May 24, 2024
4c0b8fd
Expose docs for the now public ProgressBar component
fullofcaffeine May 24, 2024
0ff6637
Update CHANGELOG
fullofcaffeine May 24, 2024
ad2fd28
Merge branch 'trunk' into remove/wp-components-experimental-designati…
fullofcaffeine May 24, 2024
adf39a1
Run docs:build after docs/manifest.js change
fullofcaffeine May 24, 2024
ceb2840
Merge branch 'trunk' into remove/wp-components-experimental-designati…
fullofcaffeine May 24, 2024
9b3db94
Remove remaining private usage of ProgressBar
fullofcaffeine May 24, 2024
a219fa8
Small formatting fix in the changelog
fullofcaffeine May 24, 2024
1d22f24
Add basic docs to the README
fullofcaffeine May 24, 2024
b096ca4
Add jsdoc
fullofcaffeine May 24, 2024
3af0985
Formatting fix in README jsx block
fullofcaffeine May 27, 2024
846ccc0
Another formatting fix in README jsx block
fullofcaffeine May 27, 2024
39b92a5
YAFF (yet another formatting fix) in the README jsx
fullofcaffeine May 27, 2024
3241379
Improve wording in descripton of the `value` prop in the README
fullofcaffeine May 27, 2024
ff982fb
YAFF: Missing semicolon in README jsx
fullofcaffeine May 27, 2024
b0eca3f
YAFF: missing semicolon in jsx block in README
fullofcaffeine May 27, 2024
59d46cc
YAFF: missing semicolon in jsx block in README
fullofcaffeine May 27, 2024
0832e40
YAFF: use tab instead of spaces in jsx code block in README
fullofcaffeine May 27, 2024
5ca947a
Move export out of the HOC export section
fullofcaffeine May 27, 2024
47183b7
Fix CHANGELOG: Move entry to the existing enhacements section
fullofcaffeine May 27, 2024
eed1dba
Merge branch 'trunk' into remove/wp-components-experimental-designati…
fullofcaffeine May 27, 2024
d132170
Spacing fix
fullofcaffeine May 28, 2024
43e1a57
Sort import alphabetically
fullofcaffeine May 28, 2024
7a00da3
Allow `ProgressBar` to have unconstrained width, which is disabled by…
fullofcaffeine May 24, 2024
a9c174b
Revert "Allow `ProgressBar` to have unconstrained width, which is dis…
fullofcaffeine May 28, 2024
66e8223
Update docs and add story to illustrate a custom width
fullofcaffeine May 28, 2024
3a95761
Update CHANGELOG
fullofcaffeine May 28, 2024
a076910
Merge branch 'trunk' into improve/progress-bar-width-control
fullofcaffeine May 29, 2024
2454c7a
Simplify description in the story
fullofcaffeine May 29, 2024
981ce6f
Improve jsdoc in story, do not encourage more customization than needed
fullofcaffeine May 29, 2024
67d97df
Inherit the second story from the main template
fullofcaffeine May 29, 2024
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
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,12 @@
"markdown_source": "../packages/components/src/popover/README.md",
"parent": "components"
},
{
"title": "ProgressBar",
"slug": "progress-bar",
"markdown_source": "../packages/components/src/progress-bar/README.md",
"parent": "components"
},
{
"title": "QueryControls",
"slug": "query-controls",
Expand Down
1 change: 0 additions & 1 deletion docs/tool/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const componentPaths = glob( 'packages/components/src/*/**/README.md', {
'packages/components/src/theme/README.md',
'packages/components/src/view/README.md',
'packages/components/src/dropdown-menu-v2/README.md',
'packages/components/src/progress-bar/README.md',
'packages/components/src/tabs/README.md',
'packages/components/src/custom-select-control-v2/README.md',
],
Expand Down
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

- `Tabs`: Animate indicator ([#60560](https://github.com/WordPress/gutenberg/pull/60560)).
- `ComboboxControl`: Introduce Combobox expandOnFocus prop ([#61705](https://github.com/WordPress/gutenberg/pull/61705)).
- Components: Make the `ProgressBar` public ([#61062](https://github.com/WordPress/gutenberg/pull/61062)).
- `ProgressBar`: Simplify default width implementation and make it more easily overridable ([#61976](https://github.com/WordPress/gutenberg/pull/61976)).

### Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions packages/components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export { default as PanelHeader } from './panel/header';
export { default as PanelRow } from './panel/row';
export { default as Placeholder } from './placeholder';
export { default as Popover } from './popover';
export { ProgressBar } from './progress-bar';
export { default as QueryControls } from './query-controls';
export { default as __experimentalRadio } from './radio-group/radio';
export { default as __experimentalRadioGroup } from './radio-group';
Expand Down
2 changes: 0 additions & 2 deletions packages/components/src/private-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from './composite/v2';
import { default as CustomSelectControl } from './custom-select-control';
import { positionToPlacement as __experimentalPopoverLegacyPositionToPlacement } from './popover/utils';
import { default as ProgressBar } from './progress-bar';
import { createPrivateSlotFill } from './slot-fill';
import {
DropdownMenu as DropdownMenuV2,
Expand Down Expand Up @@ -44,7 +43,6 @@ lock( privateApis, {
__experimentalPopoverLegacyPositionToPlacement,
createPrivateSlotFill,
ComponentsContext,
ProgressBar,
Tabs,
Theme,
DropdownMenuV2,
Expand Down
44 changes: 39 additions & 5 deletions packages/components/src/progress-bar/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,47 @@
# ProgressBar

<div class="callout callout-alert">
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
</div>

A simple horizontal progress bar component.

Supports two modes: determinate and indeterminate. A progress bar is determinate when a specific progress value has been specified (from 0 to 100), and indeterminate when a value hasn't been specified.

## Usage

Basic usage:

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

const MyLoadingComponent = () => {
return <ProgressBar />;
};
```

You can also make it determinate by passing a `value` (from 0 to 100) representing the progress:

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

const MyLoadingComponent = ( { progress } ) => {
return <ProgressBar value={ progress } />;
};
```

You can customize its appearance by passing a custom CSS class name to `className`.

```css
.my-custom-progress-bar {
width: 100%;
}
```

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

const MyLoadingComponent = () => {
return <ProgressBar className="my-custom-progress-bar" />;
};
```

### Props

The component accepts the following props:
Expand All @@ -23,7 +57,7 @@ If a `value` is not specified, the progress bar will be considered indeterminate

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

- Required: No
- Required: No

#### Inherited props

Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/progress-bar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ function UnforwardedProgressBar(
);
}

/* A simple horizontal progress bar component.
*
* Supports two modes: determinate and indeterminate. A progress bar is determinate when a specific progress value has been specified (from 0 to 100), and indeterminate when a value hasn't been specified.
*
* ```jsx
* import { ProgressBar } from '@wordpress/components';
*
* const MyLoadingComponent = () => {
* return <ProgressBar />;
* };
* ```
*/
export const ProgressBar = forwardRef( UnforwardedProgressBar );

export default ProgressBar;
34 changes: 32 additions & 2 deletions packages/components/src/progress-bar/stories/index.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import { ProgressBar } from '..';

const meta: Meta< typeof ProgressBar > = {
component: ProgressBar,
title: 'Components (Experimental)/ProgressBar',
title: 'Components/ProgressBar',
argTypes: {
value: { control: { type: 'number', min: 0, max: 100, step: 1 } },
},
tags: [ 'status-private' ],
parameters: {
controls: {
expanded: true,
Expand All @@ -30,3 +29,34 @@ const Template: StoryFn< typeof ProgressBar > = ( { ...args } ) => {

export const Default: StoryFn< typeof ProgressBar > = Template.bind( {} );
Default.args = {};

const withCustomWidthCustomCSS = `
.custom-progress-bar {
width: 100%;
}
`;

/**
* A progress bar with a custom overriden width.
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
*
* You can override the default `width` or further customize the behavior
* and visuals by passing a custom CSS class via the `cssName` prop.
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
*
* This example shows a progress bar with an overriden `width` of `100%` which
* makes it fit all available horizontal space of the parent element. The CSS
* class looks like this:
*
* ```css
* .custom-progress-bar {
* width: 100%;
* }
* ```
*/
export const WithCustomWidth: StoryFn< typeof ProgressBar > = () => {
return (
<>
<style>{ withCustomWidthCustomCSS }</style>
<ProgressBar className="custom-progress-bar" />
</>
);
};
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 4 additions & 2 deletions packages/components/src/progress-bar/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export const INDETERMINATE_TRACK_WIDTH = 50;
export const Track = styled.div`
position: relative;
overflow: hidden;
width: 100%;
max-width: 160px;
height: ${ CONFIG.borderWidthFocus };
/* Text color at 10% opacity */
background-color: color-mix(
Expand All @@ -38,6 +36,10 @@ export const Track = styled.div`
// Windows high contrast mode.
outline: 2px solid transparent;
outline-offset: 2px;

:where( & ) {
fullofcaffeine marked this conversation as resolved.
Show resolved Hide resolved
width: 160px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not specific to this PR, but is there any reason we're not using rem almost everywhere? It is good practice for proper zoom support, which is an important accessibility feature. @WordPress/gutenberg-components

Copy link
Member

Choose a reason for hiding this comment

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

I've always assumed that this was a "that ship has sailed" situation, since WordPress/Gutenberg is already built entirely on a non-rem basis 😓

}
`;

export const Indicator = styled.div< {
Expand Down
7 changes: 5 additions & 2 deletions packages/edit-site/src/components/canvas-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import {
privateApis as componentsPrivateApis,
ProgressBar,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

Expand All @@ -12,7 +15,7 @@ import { useSelect } from '@wordpress/data';
import { unlock } from '../../lock-unlock';
import { useStylesPreviewColors } from '../global-styles/hooks';

const { ProgressBar, Theme } = unlock( componentsPrivateApis );
const { Theme } = unlock( componentsPrivateApis );
const { useGlobalStyle } = unlock( blockEditorPrivateApis );

export default function CanvasLoader( { id } ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
Button,
DropdownMenu,
SearchControl,
privateApis as componentsPrivateApis,
ProgressBar,
} from '@wordpress/components';
import { debounce } from '@wordpress/compose';
import { sprintf, __, _x } from '@wordpress/i18n';
Expand All @@ -45,8 +45,6 @@ import GoogleFontsConfirmDialog from './google-fonts-confirm-dialog';
import { downloadFontFaceAssets } from './utils';
import { sortFontFaces } from './utils/sort-font-faces';
import CollectionFontVariant from './collection-font-variant';
import { unlock } from '../../../lock-unlock';
const { ProgressBar } = unlock( componentsPrivateApis );

const DEFAULT_CATEGORY = {
slug: 'all',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
__experimentalVStack as VStack,
Flex,
Notice,
privateApis as componentsPrivateApis,
ProgressBar,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
Expand All @@ -26,12 +26,10 @@ import { chevronLeft } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { unlock } from '../../../lock-unlock';
import { FontLibraryContext } from './context';
import FontCard from './font-card';
import LibraryFontVariant from './library-font-variant';
import { sortFontFaces } from './utils/sort-font-faces';
const { ProgressBar } = unlock( componentsPrivateApis );

function InstalledFonts() {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
Notice,
FormFileUpload,
FlexItem,
privateApis as componentsPrivateApis,
ProgressBar,
} from '@wordpress/components';
import { useContext, useState } from '@wordpress/element';

Expand All @@ -23,9 +23,6 @@ import { FontLibraryContext } from './context';
import { Font } from '../../../../lib/lib-font.browser';
import makeFamiliesFromFaces from './utils/make-families-from-faces';
import { loadFontFaceInBrowser } from './utils';
import { unlock } from '../../../lock-unlock';

const { ProgressBar } = unlock( componentsPrivateApis );

function UploadFonts() {
const { installFonts, notice, setNotice } =
Expand Down
1 change: 1 addition & 0 deletions storybook/manager-head.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'navigation',
'customselectcontrol-v2',
'theme',
'progressbar',
];
const REDIRECTS = [
{
Expand Down
Loading