'Is it possible to limit the code example in Storybook Canvas?
I'm using Storybook .mdx files for my component library, and mostly it's working great. However, I often need to add additional components into my stories to make them fully functional. My issue is that these components end up in the "Show Code" feature, which means devs end up copy & pasting them. Is there a way to prevent this, or set my stories up differently?
My current implementation:
export const Template = (args) => (
<Spacer>
<Menu {...args} />
</Spacer>
);
<Canvas>
<Story
name="Default"
args={{...}}
>
{Template.bind({})}
</Story>
</Canvas>
Results in the "Show Code" feature:
<Spacer>
<Menu {...args} />
</Spacer>
My goal is just:
<Menu {...args} />
Note:
When I try putting the other elements inside the Story block, I get this error: Unexpected error while loading ./components/Menu.stories.mdx: Cannot add property storyName, object is not extensible TypeError: Cannot add property storyName, object is not extensible
Throws error:
<Canvas>
<Story
name="Default"
args={{...}}
>
<Spacer>
{Template.bind({})}
</Spacer>
</Story>
</Canvas>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
