Skip to content

Commit da4a6f7

Browse files
authored
Update CardCommentCount stories to CSF v3 (#13621)
Component Story Format v3 is the default for Storybook 7+, and integrates better with some of its features. Using `satisfies` gives better type safety for args. Replaced the `Wrapper` component with a decorator. Since both stories were identical, deleted the second one. As there was then only one story, renamed the story to have the same name as the component, which allows storybook to hoist the story in the UI.
1 parent d9a1bde commit da4a6f7

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed
Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,26 @@
1-
import { css } from '@emotion/react';
21
import { space } from '@guardian/source/foundations';
3-
import { CardCommentCount } from './CardCommentCount.importable';
4-
import { Island } from './Island';
2+
import type { Meta, StoryObj } from '@storybook/react';
3+
import { CardCommentCount as CardCommentCountComponent } from './CardCommentCount.importable';
54

6-
export default {
7-
component: CardCommentCount,
8-
title: 'Components/CardCommentCount',
9-
};
5+
const meta = {
6+
component: CardCommentCountComponent,
7+
title: 'Components/Card Comment Count',
8+
} satisfies Meta<typeof CardCommentCountComponent>;
109

11-
const Wrapper = ({ children }: { children: React.ReactNode }) => {
12-
return (
13-
<div
14-
css={css`
15-
padding: ${space[6]}px;
16-
`}
17-
>
18-
{children}
19-
</div>
20-
);
21-
};
10+
export default meta;
2211

23-
export const CommentCountStory = () => {
24-
return (
25-
<Wrapper>
26-
<Island priority="critical">
27-
<CardCommentCount
28-
discussionApiUrl="https://discussion.theguardian.com/discussion-api"
29-
discussionId="/p/zemg8"
30-
/>
31-
</Island>
32-
</Wrapper>
33-
);
34-
};
35-
CommentCountStory.storyName = 'default';
12+
type Story = StoryObj<typeof meta>;
3613

37-
export const GalleryStory = () => {
38-
return (
39-
<Wrapper>
40-
<Island priority="critical">
41-
<CardCommentCount
42-
discussionApiUrl="https://discussion.theguardian.com/discussion-api"
43-
discussionId="/p/zemg8"
44-
/>
45-
</Island>
46-
</Wrapper>
47-
);
48-
};
49-
GalleryStory.storyName = 'Gallery';
14+
export const CardCommentCount = {
15+
args: {
16+
discussionApiUrl: 'https://discussion.theguardian.com/discussion-api',
17+
discussionId: '/p/zemg8',
18+
},
19+
decorators: [
20+
(Story) => (
21+
<div css={{ padding: space[6] }}>
22+
<Story />
23+
</div>
24+
),
25+
],
26+
} satisfies Story;

0 commit comments

Comments
 (0)