mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-08 07:41:58 +08:00
52 lines
1.0 KiB
Plaintext
52 lines
1.0 KiB
Plaintext
```tsx
|
|
// List.stories.ts|tsx
|
|
|
|
import type { Meta, StoryObj } from '@storybook/react';
|
|
|
|
import { List } from './List';
|
|
import { ListItem } from './ListItem';
|
|
|
|
//👇 Imports a specific story from ListItem stories
|
|
import { Unchecked } from './ListItem.stories';
|
|
|
|
const meta = {
|
|
/* 👇 The title prop is optional.
|
|
* Seehttps://storybook.js.org/docs/7.0/react/configure/overview#configure-story-loading
|
|
* to learn how to generate automatic titles
|
|
*/
|
|
title: 'List',
|
|
|
|
component: List,
|
|
} satisfies Meta<typeof List>;
|
|
|
|
export default meta;
|
|
type Story = StoryObj<typeof meta>;
|
|
|
|
//👇 The ListTemplate construct will be spread to the existing stories.
|
|
const ListTemplate: Story = {
|
|
render: ({ items, ...args }) => {
|
|
return (
|
|
<List>
|
|
{items.map((item) => (
|
|
<ListItem {...item} />
|
|
))}
|
|
</List>
|
|
);
|
|
},
|
|
};
|
|
|
|
export const Empty = {
|
|
...ListTemplate,
|
|
args: {
|
|
items: [],
|
|
},
|
|
};
|
|
|
|
export const OneItem = {
|
|
...ListTemplate,
|
|
args: {
|
|
items: [{ ...Unchecked.args }],
|
|
},
|
|
};
|
|
```
|