Skip to content

Commit 9c9570d

Browse files
committed
breadcrumb composition
1 parent 23c19d0 commit 9c9570d

File tree

4 files changed

+32
-54
lines changed

4 files changed

+32
-54
lines changed

client/dashboard/components/page-header/index.stories.tsx

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Breadcrumbs } from '@automattic/components/src/breadcrumbs';
12
import { Meta, StoryObj } from '@storybook/react';
23
import { Button, Icon, DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
34
import { help, wordpress, moreVertical } from '@wordpress/icons';
@@ -37,61 +38,36 @@ export const WithActions: Story = {
3738
},
3839
};
3940

40-
export const FullExample: Story = {
41+
export const ImageDecoration: Story = {
4142
args: {
4243
title: 'Site Customization',
4344
description: 'Make your site look exactly how you want it to',
44-
decoration: <Icon icon={ wordpress } />,
45-
breadcrumbItems: [
46-
{ label: 'Dashboard', href: 'javascript:void(0)' },
47-
{ label: 'Appearance', href: 'javascript:void(0)' },
48-
{ label: 'Customize', href: 'javascript:void(0)' },
49-
{ label: 'Theme', href: 'javascript:void(0)' },
50-
{ label: 'Advanced', href: 'javascript:void(0)' },
51-
],
45+
decoration: <img src="https://placecats.com/300/200" alt="Cat" />,
5246
actions: (
5347
<>
54-
<Button icon={ help } variant="tertiary" __next40pxDefaultSize>
55-
Help
56-
</Button>
57-
<Button variant="secondary" __next40pxDefaultSize>
58-
Preview
59-
</Button>
60-
<DropdownMenu
61-
icon={ moreVertical }
62-
label="More actions"
63-
toggleProps={ { __next40pxDefaultSize: true } }
64-
>
65-
{ () => (
66-
<>
67-
<MenuGroup>
68-
<MenuItem>Import</MenuItem>
69-
<MenuItem>Export</MenuItem>
70-
<MenuItem>Settings</MenuItem>
71-
</MenuGroup>
72-
<MenuGroup>
73-
<MenuItem>Help</MenuItem>
74-
</MenuGroup>
75-
</>
76-
) }
77-
</DropdownMenu>
48+
<Button variant="secondary">Cancel</Button>
49+
<Button variant="primary">Save Changes</Button>
7850
</>
7951
),
8052
},
8153
};
8254

83-
export const ImageDecoration: Story = {
55+
export const FullExample: Story = {
8456
args: {
8557
title: 'Site Customization',
8658
description: 'Make your site look exactly how you want it to',
87-
decoration: <img src="https://placecats.com/300/200" alt="Cat" />,
88-
breadcrumbItems: [
89-
{ label: 'Dashboard', href: 'javascript:void(0)' },
90-
{ label: 'Appearance', href: 'javascript:void(0)' },
91-
{ label: 'Customize', href: 'javascript:void(0)' },
92-
{ label: 'Theme', href: 'javascript:void(0)' },
93-
{ label: 'Advanced', href: 'javascript:void(0)' },
94-
],
59+
decoration: <Icon icon={ wordpress } />,
60+
breadcrumb: (
61+
<Breadcrumbs
62+
items={ [
63+
{ label: 'Dashboard', href: 'javascript:void(0)' },
64+
{ label: 'Appearance', href: 'javascript:void(0)' },
65+
{ label: 'Customize', href: 'javascript:void(0)' },
66+
{ label: 'Theme', href: 'javascript:void(0)' },
67+
{ label: 'Advanced', href: 'javascript:void(0)' },
68+
] }
69+
/>
70+
),
9571
actions: (
9672
<>
9773
<Button icon={ help } variant="tertiary" __next40pxDefaultSize>

client/dashboard/components/page-header/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Breadcrumbs } from '@automattic/components/src/breadcrumbs';
21
import {
32
__experimentalVStack as VStack,
43
__experimentalHStack as HStack,
@@ -37,11 +36,11 @@ export const PageHeader = ( {
3736
description,
3837
actions,
3938
decoration,
40-
breadcrumbItems,
39+
breadcrumb,
4140
}: PageHeaderProps ) => {
4241
return (
4342
<VStack spacing={ 2 }>
44-
{ !! breadcrumbItems?.length && <Breadcrumbs items={ breadcrumbItems } /> }
43+
{ breadcrumb }
4544
<HStack spacing={ 4 } justify="flex-start" alignment="flex-start">
4645
{ decoration && (
4746
<span className="client-dashboard-components-page-header__decoration">

client/dashboard/components/page-header/test/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @jest-environment jsdom
33
*/
4+
import { Breadcrumbs } from '@automattic/components/src/breadcrumbs';
45
import { render, screen } from '@testing-library/react';
56
import { Button, Icon } from '@wordpress/components';
67
import { cog } from '@wordpress/icons';
@@ -43,11 +44,15 @@ describe( 'PageHeader', () => {
4344
render(
4445
<PageHeader
4546
title="Test Title"
46-
breadcrumbItems={ [
47-
{ label: 'Home', href: '/' },
48-
{ label: 'Products', href: '/products' },
49-
{ label: 'Categories', href: '/products/categories' },
50-
] }
47+
breadcrumb={
48+
<Breadcrumbs
49+
items={ [
50+
{ label: 'Home', href: '/' },
51+
{ label: 'Products', href: '/products' },
52+
{ label: 'Categories', href: '/products/categories' },
53+
] }
54+
/>
55+
}
5156
/>
5257
);
5358
expect( screen.getByRole( 'heading', { name: 'Test Title' } ).tagName ).toBe( 'H1' );

client/dashboard/components/page-header/types.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import type { BreadcrumbItemProps } from '@automattic/components/src/breadcrumbs/types';
32

43
export interface PageHeaderProps {
54
/**
@@ -22,9 +21,8 @@ export interface PageHeaderProps {
2221
*/
2322
decoration?: React.ReactNode;
2423
/**
25-
* An optional breadcrumb trail used to indicate the user's current position
24+
* An optional breadcrumb component used to indicate the user's current position
2625
* in a complex navigational structure and allow quick access to parent levels.
27-
* Internally it uses the `Breadcrumbs` component.
2826
*/
29-
breadcrumbItems?: BreadcrumbItemProps[];
27+
breadcrumb?: React.ReactNode[];
3028
}

0 commit comments

Comments
 (0)