storybook/docs/snippets/vue/list-story-template.ts-2.ts.mdx
2022-11-30 20:25:47 +00:00

57 lines
1.1 KiB
Plaintext

```ts
// List.stories.ts
import List from './List.vue';
import ListItem from './ListItem.vue';
//👇 Imports a specific story from ListItem stories
import { Unchecked } from './ListItem.stories';
import type { Meta, StoryObj } from '@storybook/vue';
const meta: Meta<typeof List> = {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/7.0/vue/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'List',
component: List,
};
export default meta;
type Story = StoryObj<typeof List>;
//👇 The ListTemplate construct will be spread to the existing stories.
const ListTemplate = {
render: (args, { argTypes }) => ({
components: { List, ListItem },
props: Object.keys(argTypes),
template: `
<List v-bind="$props">
<div v-for="item in items" :key="item.title">
<ListItem :item="item" />
</div>
</List>
`,
}),
};
export const Empty: Story = {
...ListTemplate,
args: {
items: [],
},
};
export const OneItem: Story = {
...ListTemplate,
args: {
items: [
{
...Unchecked.args,
},
],
},
};
```