Fix stories

Signed-off-by: Charles de Dreuille <charles.dedreuille@gmail.com>
This commit is contained in:
Charles de Dreuille
2025-07-18 15:41:24 +01:00
parent d90cfb2650
commit beba895c5c
2 changed files with 21 additions and 59 deletions
@@ -40,7 +40,7 @@ const meta = {
export default meta;
type Story = StoryObj<typeof meta>;
const withRouter = (Story: StoryFn) => (
export const withRouter = (Story: StoryFn) => (
<MemoryRouter>
<Story />
</MemoryRouter>
@@ -113,7 +113,7 @@ const menuItems: HeaderMenuItem[] = [
];
// Extract layout decorator as a reusable constant
const layoutDecorator = [
export const layoutDecorator = [
(Story: StoryFn) => (
<>
<div
@@ -281,10 +281,10 @@ export const WithMockedURLCampaigns: Story = {
<MemoryRouter initialEntries={['/campaigns']}>
<Header {...args} />
<Container>
<Text>
<Text as="p">
Current URL is mocked to be: <strong>/campaigns</strong>
</Text>
<Text>
<Text as="p">
Notice how the "Campaigns" tab is selected (highlighted) because it
matches the current path.
</Text>
@@ -301,10 +301,10 @@ export const WithMockedURLIntegrations: Story = {
<MemoryRouter initialEntries={['/integrations']}>
<Header {...args} />
<Container>
<Text>
<Text as="p">
Current URL is mocked to be: <strong>/integrations</strong>
</Text>
<Text>
<Text as="p">
Notice how the "Integrations" tab is selected (highlighted) because it
matches the current path.
</Text>
@@ -321,14 +321,14 @@ export const WithMockedURLNoMatch: Story = {
<MemoryRouter initialEntries={['/some-other-page']}>
<Header {...args} />
<Container>
<Text>
<Text as="p">
Current URL is mocked to be: <strong>/some-other-page</strong>
</Text>
<Text>
<Text as="p">
No tab is selected because the current path doesn't match any tab's
href.
</Text>
<Text>
<Text as="p">
Tabs without href (like "Overview", "Checks", "Tracks") fall back to
React Aria's internal state.
</Text>
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import type { Meta, StoryObj, StoryFn } from '@storybook/react';
import type { Meta, StoryObj } from '@storybook/react';
import { HeaderPage } from './HeaderPage';
import type { HeaderTab, HeaderMenuItem } from '../Header/types';
import { MemoryRouter } from 'react-router-dom';
import { Button } from '../Button';
import { layoutDecorator, withRouter } from '../Header/Header.stories';
const meta = {
title: 'Components/HeaderPage',
@@ -26,13 +26,6 @@ const meta = {
parameters: {
layout: 'fullscreen',
},
decorators: [
(Story: StoryFn) => (
<MemoryRouter>
<Story />
</MemoryRouter>
),
],
} satisfies Meta<typeof HeaderPage>;
export default meta;
@@ -72,47 +65,6 @@ const menuItems: HeaderMenuItem[] = [
},
];
// Extract layout decorator as a reusable constant
const layoutDecorator = [
(Story: StoryFn) => (
<>
<div
style={{
width: '250px',
position: 'fixed',
left: 8,
top: 8,
bottom: 8,
backgroundColor: 'var(--bui-bg-surface-1',
borderRadius: 'var(--bui-radius-2)',
border: '1px solid var(--bui-border)',
zIndex: 1,
}}
/>
<div
style={{
paddingInline: '266px',
}}
>
<Story />
</div>
<div
style={{
width: '250px',
position: 'fixed',
right: 8,
top: 8,
bottom: 8,
backgroundColor: 'var(--bui-bg-surface-1',
borderRadius: 'var(--bui-radius-2)',
border: '1px solid var(--bui-border)',
zIndex: 1,
}}
/>
</>
),
];
export const Default: Story = {
args: {
title: 'Header Page',
@@ -124,6 +76,7 @@ export const WithTabs: Story = {
...Default.args,
tabs,
},
decorators: [withRouter],
};
export const WithMenuItems: Story = {
@@ -144,6 +97,7 @@ export const WithCustomActions: Story = {
};
export const WithEverything: Story = {
decorators: [withRouter],
render: () => (
<HeaderPage
{...Default.args}
@@ -159,4 +113,12 @@ export const WithLayout: Story = {
...WithEverything.args,
},
decorators: layoutDecorator,
render: () => (
<HeaderPage
{...Default.args}
menuItems={menuItems}
tabs={tabs}
customActions={<Button>Custom action</Button>}
/>
),
};