-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<Preview /> Does not show code sample unless it's also using <Story /> #8505
Comments
This should be fixed in #7966 and available in |
@shilman Is this currently in an alpha release? I tried |
@JamesIves yeah i'm classifying this as a feature, so it will be part of 5.3.0 according to sever. released in |
@RohitRajendran Sorry it's #7966. What does your |
@atanasster would you mind looking into this? |
here is the source:
|
@JamesIves you need to:
|
Renaming it to It does work however if the titles are unique, but that's not ideal because it doesn't create an association. |
@JamesIves HMMmmm 🤔 Take a look at https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs This pattern is only available in 5.3, but would that work for you? |
Sorry I have so many questions. I attempted this pattern using the following:
import React from 'react';
import TwitterIcon from './TwitterIcon';
import {text} from '@storybook/addon-knobs';
const defaultProps = () => ({
fill: text('fill', '#000'),
height: text('height', '2rem'),
width: text('width', '2rem'),
});
export default {
title: 'Atoms/Icons/TwitterIcon',
component: TwitterIcon,
includedStories: ['basic'],
}
const basic = () => <TwitterIcon {...defaultProps()} />;
basic.story = {
title: 'story'
} And within
The problem I'm running into now is that it doesn't generate the basic story, instead now all I see is the |
@JamesIves You need to follow the recipe. In this recipe, the includeStories: [], // or don't load this file at all Then, in <Story name="story">{stories.basic}</Story> It would probably be a lot easier if you just did everything in MDX? |
The issue with both of these recipes (mdx and csf with mdx) is that I can't define stories without showing the preview for them. If I define the stories directly in the mdx file I end up with this issue #8342 which was the inspiration behind having the I feel like I could probably hide the story definitions using a div, but that feels very hacky. Maybe there should be some sort of wrapper component from I wish I could just override the docs page and have code previews without it running through the Storybook mdx compiler 😢 |
@JamesIves Sorry this is ending up being such an ordeal for you. Hopefully we can get a clean recipe going for you that satisfies all your needs. A few things...
<Story name="foo" parameters={{ docs: { disable: true }}} />
...
</Story>
|
Can confirm this is also a pain point for me, i would much rather keep my stories and docs seperate. @shilman are you planning on supporting preview blocks like this when .mdx files are used purely for docs? |
@sami616 You can already create a docs-only
|
@shilman right, but not when it's used in the context detailed in this issue? ie calling the docs page for my story Accordion.docs.mdx and consuming it via Accordion.story = {
parameters: {
docs: { page: accordionMDX },
},
} I see |
@shilman I'm seeing the exact same issue as @sami616 on 5.3.18 everything. I have to have my stories as CSF to be able to integrate them with InVision DSM. |
@shilman code is available but its not the output its the export in CSF file - would be great to get the rendered output |
Does it work with the v6 version @shilman ? We are experiencing the same issue. Preview is not visible if importing the mdx file :/ We are on a 5.3 version. |
Which pattern are you using @darkowic ? The following are all working in 6.0: import { importedCsf } from './csf.stories.js';
<Canvas>
<div>some jsx</div>
</Canvas>
<Canvas>
<Story name="some story"><div>some story</div></Story>
</Canvas>
<Canvas>
<Story name="imported CSF story" story={importedCsf} />
</Canvas> |
@shilman the pattern from the original question here or what others have been asking above here:
or here:
For 5.3, the preview is visible only if the MDX files are parsed by the story parser. It won't work without import cardsDocs from './cards.mdx';
export default {
title: 'Components/Cards',
component: Card,
parameters: {
docs: {
page: cardsDocs,
},
},
}; |
@darkowic the recommended way is embedding CSF in MDX, and it's supported quite well in 6.0, IMO, with the |
Our use-case is that we have some Component story (with knobs/controls) and we want to have a docs page for it. We want to switch between the docs page and the example by using the tabs (Canvas and Docs). The docs page describes the component details (with some code samples) and how it works and the canvas is a simple playground. We want to keep the docs page in a separate mdx file. That's it. Well, sounds like pretty common approach ;) But maybe we should rethink our storybooks approach. |
@darkowic I believe the recommended recipe I described above will suit your needs (and actually work in storybook). More info here: https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs |
The recipe at https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs does not work (storybook 6.0.16) as intended, and does not explain where to add includeStories: [] when it cannot go inside the default export you are not supposed to have in the CSF example. Use case: I want to create a docs page that has stories, without creating a story/menu entry for every story used in the MDX. That said, Preview seems to offer just what I need. |
@lars-bo-colourbox can you explain what doesn't work in that recipe? the |
@shilman The recipe says "Your stories are defined in CSF, but because of includeStories: [], they are not actually added to Storybook." But the stories are added to storybook. Shouldn't the recipe be updated to match Storybook 6? Or explicitly say that it's for 5.2? As it is, a piece of code is referred to (includeStories: []), although it is not mentioned anywhere on the page. I am new to SB 6, and I find it hard to find comprehensive documentation. Like a list of components @storybook/addon-docs/blocks gives us, and which props they have. Also, it would be helpful to address the issues people will have with components using createPortal (obviously), and forwardRef (maybe less obvious). It can all be done, but it would be great to know how instead of spending hours of trial and failure. Apart from that, upgrading from 5 to 6 feels like going from 5 to 10. Someone did an absolutely amazing job. |
reading this while trying to upgrade and setup 5.3. Having the same issue as OP |
I'm using 6.3.2 and still having the same issue. We want to use this recipe https://github.com/storybookjs/storybook/blob/master/addons/docs/docs/recipes.md#csf-stories-with-arbitrary-mdx but blocks display as 'no code available'. Are you saying that recipe is not correct for v6? |
@annidavenport that recipe never showed the source of the components. this is not explained very well in the documentation but there is a distinction between "foo.mdx" and "foo.stories.mdx", and reflects a design we'll probably revisit in the next major iteration of storybook docs. "foo.mdx" former is vanilla mdx that is similar to any random MDX you'd write in another site. the latter is "storybook mdx" which can render "doc blocks" like |
Describe the bug
When using
<Preview />
to render a component in amdx
file, it doesn't show the code sample unless the sample also defines a story using<Story />
in the child.To Reproduce
Use the following in a
stories.js
file;And then put this in the
mdx
file.You'll get
No Code Available
.Expected behavior
I expect it to show the code that is used to power whatever is placed within the
Preview
components.Additional context
I'm unsure if this is a bug or not, but I feel the name
Preview
is a little bit confusing.The text was updated successfully, but these errors were encountered: