From f4713cf9b78cb8b897971abd771621de1d61d03a Mon Sep 17 00:00:00 2001 From: Marcelo Serpa Date: Wed, 22 May 2024 17:05:10 -0600 Subject: [PATCH] Rely on parent element for width --- .../components/src/progress-bar/README.md | 22 ++++++++++--- .../src/progress-bar/stories/index.story.tsx | 33 +++++++++++++++++-- .../components/src/progress-bar/styles.ts | 1 - 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/packages/components/src/progress-bar/README.md b/packages/components/src/progress-bar/README.md index ad69ab54b098af..e94bc6d813bfe0 100644 --- a/packages/components/src/progress-bar/README.md +++ b/packages/components/src/progress-bar/README.md @@ -1,13 +1,27 @@ # ProgressBar -
-This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes. -
- 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 + +Render a progress bar with a certain width. + +The ProgressBar will expand to take all the available horizontal space of its immediate parent container element. To control its width, just wrap it in a container element (e.g `
`) with a specified width: + +```jsx +import { ProgressBar } from '@wordpress/components'; + +const MyProgressBar = ( props ) => { + return ( +
+ +
+ ); +}; +``` + ### Props The component accepts the following props: diff --git a/packages/components/src/progress-bar/stories/index.story.tsx b/packages/components/src/progress-bar/stories/index.story.tsx index 944da75339f071..a2e6c71386a921 100644 --- a/packages/components/src/progress-bar/stories/index.story.tsx +++ b/packages/components/src/progress-bar/stories/index.story.tsx @@ -24,9 +24,36 @@ const meta: Meta< typeof ProgressBar > = { }; export default meta; -const Template: StoryFn< typeof ProgressBar > = ( { ...args } ) => { - return ; -}; +const Template: StoryFn< typeof ProgressBar > = ( { ...args } ) => ( + +); export const Default: StoryFn< typeof ProgressBar > = Template.bind( {} ); Default.args = {}; + +export const ParentWidth: StoryFn< { parentWidth: string } > = ( { + parentWidth, + ...args +} ) => ( +
+ +
+); + +ParentWidth.args = { + parentWidth: '300px', // Default width +}; + +ParentWidth.argTypes = { + ...meta.argTypes, + parentWidth: { control: { type: 'text' }, name: 'parent container width' }, +}; + +ParentWidth.storyName = 'With Specific Width'; +ParentWidth.parameters = { + docs: { + description: { + story: 'This story demonstrates how the ProgressBar takes the width of its parent container. You can edit the parent container\'s width using the "Parent element width" control.', + }, + }, +}; diff --git a/packages/components/src/progress-bar/styles.ts b/packages/components/src/progress-bar/styles.ts index f04002f458c0aa..29c251c97fb6d9 100644 --- a/packages/components/src/progress-bar/styles.ts +++ b/packages/components/src/progress-bar/styles.ts @@ -25,7 +25,6 @@ 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(