-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Admin UI: Add Storybook stories for Breadcrumbs and Page components #76467
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
Merged
ciampo
merged 7 commits into
WordPress:trunk
from
CGastrell:add/admin-ui-storybook-stories
Mar 17, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c381c77
Admin UI: Add Storybook stories for Breadcrumbs and Page components
CGastrell 6179d65
Admin UI: Use Text component for Page story content
CGastrell 2b8d203
Admin UI: Use package-styles config for Storybook style loading
CGastrell a944e47
Admin UI: Remove ThemeProvider from Storybook stories
CGastrell 5d5c31b
Admin UI: Extract shared withRouter decorator using @wordpress/route …
CGastrell caacc6e
Admin UI: Add min-height to Page stories decorator
CGastrell c898635
Update package-lock.json for @wordpress/private-apis dependency
CGastrell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import Breadcrumbs from '..'; | ||
| import { withRouter } from '../../stories/with-router'; | ||
|
|
||
| const meta: Meta< typeof Breadcrumbs > = { | ||
| component: Breadcrumbs, | ||
| title: 'Admin UI/Breadcrumbs', | ||
| decorators: [ withRouter ], | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj< typeof meta >; | ||
|
|
||
| export const SingleItem: Story = { | ||
| args: { | ||
| items: [ { label: 'Root breadcrumb' } ], | ||
| }, | ||
| }; | ||
|
|
||
| export const TwoLevels: Story = { | ||
| args: { | ||
| items: [ | ||
| { label: 'Root breadcrumb', to: '/settings' }, | ||
| { label: 'Level 1 breadcrumb' }, | ||
| ], | ||
| }, | ||
| }; | ||
|
|
||
| export const ThreeLevels: Story = { | ||
| args: { | ||
| items: [ | ||
| { label: 'Root breadcrumb', to: '/settings' }, | ||
| { label: 'Level 1 breadcrumb', to: '/settings/connectors' }, | ||
| { label: 'Level 2 breadcrumb' }, | ||
| ], | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; | ||
|
|
||
| export const { lock, unlock } = | ||
| __dangerousOptInToUnstableAPIsOnlyForCoreModules( | ||
| 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', | ||
| '@wordpress/admin-ui' | ||
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import type { Meta, StoryObj } from '@storybook/react-vite'; | ||
| import { __experimentalText as Text } from '@wordpress/components'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import Page from '..'; | ||
| import Breadcrumbs from '../../breadcrumbs'; | ||
| import { withRouter } from '../../stories/with-router'; | ||
|
|
||
| const meta: Meta< typeof Page > = { | ||
| component: Page, | ||
| title: 'Admin UI/Page', | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
| decorators: [ | ||
| ( Story ) => ( | ||
| <div style={ { minHeight: '400px' } }> | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| withRouter, | ||
| ], | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj< typeof meta >; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| title: 'Page title', | ||
| showSidebarToggle: false, | ||
| children: ( | ||
| <Text style={ { padding: '24px 24px' } }>Page content here</Text> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const WithSubtitle: Story = { | ||
| args: { | ||
| title: 'Page title', | ||
| subTitle: 'All of the subtitle text you need goes here.', | ||
| showSidebarToggle: false, | ||
| children: ( | ||
| <Text style={ { padding: '24px 24px' } }>Page content here</Text> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const WithBreadcrumbs: Story = { | ||
| args: { | ||
ciampo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| showSidebarToggle: false, | ||
| breadcrumbs: ( | ||
| <Breadcrumbs | ||
| items={ [ | ||
| { label: 'Root breadcrumb', to: '/connectors' }, | ||
| { label: 'Level 1 breadcrumb' }, | ||
| ] } | ||
| /> | ||
| ), | ||
| children: ( | ||
| <Text style={ { padding: '24px 24px' } }>Page content here</Text> | ||
| ), | ||
| }, | ||
| }; | ||
|
|
||
| export const WithBreadcrumbsAndSubtitle: Story = { | ||
| args: { | ||
| showSidebarToggle: false, | ||
| subTitle: 'All of the subtitle text you need goes here.', | ||
| breadcrumbs: ( | ||
| <Breadcrumbs | ||
| items={ [ | ||
| { label: 'Root breadcrumb', to: '/connectors' }, | ||
| { label: 'Level 1 breadcrumb' }, | ||
| ] } | ||
| /> | ||
| ), | ||
| children: ( | ||
| <Text style={ { padding: '24px 24px' } }>Page content here</Text> | ||
| ), | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { privateApis as routePrivateApis } from '@wordpress/route'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { unlock } from '../lock-unlock'; | ||
|
|
||
| const { createMemoryHistory, createRootRoute, createRouter, RouterProvider } = | ||
| unlock( routePrivateApis ); | ||
|
|
||
| /** | ||
| * Storybook decorator that provides a router context. | ||
| * | ||
| * Wraps stories in a minimal tanstack router (via @wordpress/route private | ||
| * APIs) so that components consuming `Link` from `@wordpress/route` can | ||
| * render without errors. | ||
| */ | ||
| export function withRouter( Story: React.ComponentType ) { | ||
| const rootRoute = createRootRoute( { component: Story } ); | ||
| const router = createRouter( { | ||
| routeTree: rootRoute, | ||
| history: createMemoryHistory( { initialEntries: [ '/' ] } ), | ||
| defaultNotFoundComponent: () => null, | ||
| } ); | ||
| return <RouterProvider router={ router } />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @import "../../packages/admin-ui/build-style/style.css"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @import "../../packages/admin-ui/build-style/style-rtl.css"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker, but I don't think that consumers of
Pageshould have to pass a custom padding every time they use the component. Ideally, the main spacing should be provided byPageand the consumers should only worry about content + intra-content spacing(here and everywhere else in the PR)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you on consumers not having to pass custom padding, but this is how it looks without the injected padding:

Do you know if we have some container for this purpose already? Should the Page component handle this so its children are already contained with paddings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, we can leave it with or without the injected paddings while we figure out whose responsibility is the children's paddings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameskoster ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took a look at the
Pagecomponent, and it has a dedicatedhasPaddingprop, which serves exactly that purpose.Now, we normally code stories so that they use as many default prop values as possible (and
hasPaddingisfalseby default), so I suggest that at least:paddingon the default story, we change it to a shorthand (ie just24px) and add a code comment explaining that, by default,Pagedoesn't add padding to its contentwith paddingstoryAlso curious to hear @jameskoster and @mirka 's thoughts on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we ought to consider reusing the technique from
Card. IEContentandFullBleedsub-components that handle padding (Contentwould have padding applied). This seems a more flexible solution compared to unilaterally saying the contents are padded or not.