storybook/docs/snippets/react/my-component-story-with-nonstory.ts.mdx
2022-07-07 19:47:29 +01:00

37 lines
1.0 KiB
Plaintext

```ts
// MyComponent.stories.ts|tsx
import React from 'react';
import type { ComponentStoryObj, ComponentMeta } from '@storybook/react';
import { MyComponent } from './MyComponent';
import someData from './data.json';
export default {
/* 👇 The title prop is optional.
* See https://storybook.js.org/docs/7.0/react/configure/overview#configure-story-loading
* to learn how to generate automatic titles
*/
title: 'MyComponent',
component: MyComponent,
includeStories: ['SimpleStory', 'ComplexStory'], // 👈 Storybook loads these stories
excludeStories: /.*Data$/, // 👈 Storybook ignores anything that contains Data
} as ComponentMeta<typeof MyComponent>;
export const simpleData = { foo: 1, bar: 'baz' };
export const complexData = { foo: 1, foobar: { bar: 'baz', baz: someData } };
export const SimpleStory: ComponentStoryObj<typeof MyComponent> = {
args: {
data: simpleData,
},
};
export const ComplexStory: ComponentStoryObj<typeof MyComponent> = {
args: {
data: complexData,
},
};
```