Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 4.9 KB

doc-block-story.md

File metadata and controls

52 lines (39 loc) · 4.9 KB
title
Story

Stories (component tests) are Storybook's fundamental building blocks. In Storybook Docs, stories are rendered in the Story block.

Docs blocks with stories

Working with Automatic Docs

With each story you write, Storybook will automatically generate a new Story Doc Block, wrapped inside a Canvas(with a toolbar if it's the first "primary" story) alongside a source code preview underneath it. Below is a condensed table of the available configuration options.

Option Description
inlineStories Configures Storybook to render stories inline.
docs: { inlineStories: false }

Working with MDX

With MDX, the Story block is not only a way of rendering stories, but how you define them. Internally, Storybook looks for named Story instances located at the top of your document, or inside a Canvas. Below is an abridged example and table featuring all the available options.

Option Description
args Provide the required component inputs (e.g., props).
<Story args={{ text: 'Button' }}/>
Read the documentation to learn more.
decorators Provide additional markup or mock a data provider to allow proper story rendering.
<Story decorators={[(Story) => ( <div style={{ margin: '3em' }}><Story/></div>)]}/>
Read the documentation to learn more.
id Storybook's internal story identifier. Used for embedding Storybook stories inside Docs.
<Story id="example-mycomponent--starter"/>
Read the documentation to learn more.
inline Enables Storybook's inline renderer.
<Story inline={false}/>
Read the documentation to learn more.
loaders (Experimental) Asynchronous function for data fetching with stories.
<Story loaders={[async () => ({ data: await (await fetch('your-endpoint'))}) ]}/>
Read the documentation to learn more.
name Adds a name to the component story.
<Story name="Example"/> .
parameters Provides the necessary static named metadata related to the story.
Story parameters={{ backgrounds: { values: [{ name:'red', value:'#f00' }] } }} />
Read the documentation to learn more.
play Generate component interactions.
<Story play={async () => { await userEvent.click(screen.getByRole('button')) }}/>
Read the documentation to learn more.

<CodeSnippets paths={[ 'react/component-story-mdx-story-by-name.mdx.mdx', 'angular/component-story-mdx-story-by-name.mdx.mdx', 'vue/component-story-mdx-story-by-name.mdx-2.mdx.mdx', 'vue/component-story-mdx-story-by-name.mdx-3.mdx.mdx', 'svelte/component-story-mdx-story-by-name.mdx.mdx', 'common/component-story-mdx-reference-storyid.mdx.mdx', ]} usesCsf3 csf2Path="writing-docs/doc-block-story#snippet-component-story-mdx-story-by-name" />

Inline rendering

All stories are rendered in the Preview iframe for isolated development in Storybook's Canvas. With Docs, if your framework supports inline rendering, it will be used by default for both performance and convenience. However, you can force this feature by providing the required configuration option (see tables above).