I am trying to find a way to disable canvas at a story level in the new storybook 6. I am making a library of components and, depending on the story, some of them will only have canvas, while others will only have docs.
I have tried using
myStory.parameters = {
previewTabs: {
canvas: {
hidden: true,
},
},
};
or
myStory.parameters = {
previewTabs: {
'storybook/docs/panel': {
hidden: false,
},
},
};
depending on the story. However, this leads to no tab name being shown. As a result of this, the following happens:
As a workaround for docs, I have found this (thanks to Benjamin, in this post here):
myStory.parameters = {
docs: { page: null },
};
With this, I can still see both canvas and docs tabs, but the docs one is now empty for the story where this parameter has been set.
I am looking to do something similar for canvas, and have tried
myStory.parameters = {
canvas: { page: null },
};
myStory.parameters = {
canvas: { disabled: true },
};
but have not worked.
Storybook's Canvas Doc Block is a wrapper featuring a toolbar that allows you to interact with its content while automatically providing the required Source snippets.
ArgTypes are a first-class feature in Storybook for specifying the behaviour of Args. By specifying the type of an arg, you constrain the values that it can take and provide information about args that are not explicitly set (i.e., not required).
I don't know if this solution will fit your needs, but the workaroud I found was to write my stories in .mdx
and disable canvas on Meta
:
import { Meta } from '@storybook/addon-docs/blocks';
import { MyComponent } from './MyComponent';
<Meta
title="Section/MyComponent"
parameters={{
viewMode: 'docs',
previewTabs: {
canvas: { hidden: true }
},
}}
/>
# My markdown title
<Canvas>
<Story name="mycomponent">
<MyComponent />
</Story>
</Canvas>
Yes the tabs are saved from the previous story, but you can set a default view mode for that story, that should solve your problem.
myStory.parameters = {
previewTabs: {
canvas: {
hidden: true,
},
},
viewMode: 'docs',
};
More examples on https://github.com/storybookjs/storybook/blob/master/addons/docs/docs/recipes.md#controlling-a-storys-view-mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With