storybook/docs/snippets/vue/my-component-story-with-nonstory.ts-3.ts.mdx
2023-01-06 19:15:31 +00:00

58 lines
1.4 KiB
Plaintext

```ts
// Button.stories.ts
import MyComponent from './Button.vue';
import type { Meta, StoryObj } from '@storybook/vue3';
import someData from './data.json';
const meta: Meta<typeof MyComponent> = {
/* 👇 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: 'MyComponent',
component: MyComponent,
includeStories: ['SimpleStory', 'ComplexStory'],
excludeStories: /.*Data$/, // 👈 Storybook ignores anything that contains Data
};
export const simpleData = { foo: 1, bar: 'baz' };
export const complexData = { foo: 1, foobar: { bar: 'baz', baz: someData } };
export default meta;
type Story = StoryObj<typeof MyComponent>;
/*
*👇 Render functions are a framework specific feature to allow you control on how the component renders.
* See https://storybook.js.org/docs/7.0/vue/api/csf
* to learn how to use render functions.
*/
export const SimpleStory: Story = {
render: (args) => ({
components: { MyComponent },
setup() {
return { args };
},
template: `<MyComponent v-bind="args"/>`,
}),
args: {
data: simpleData,
},
};
export const ComplexStory: Story = {
render: (args) => ({
components: { MyComponent },
setup() {
return { args };
},
template: `<MyComponent v-bind="args"/>`,
}),
args: {
data: complexData,
},
};
```