Addon-docs: "Native"/natural MDX syntax
See original GitHub issueUmbrella issue to extend “native” MDX from React to other frameworks
Problem
Currently in @storybook/react
you can write JSX directly in your MDX file:
<Story name='foo'><div className='bar'>baz</div></Story>
For @storybook/html
you’d probably like to write the following, but it won’t work:
<Story name='foo'><div class='bar'>baz</div></Story>
Instead you’d have to write:
<Story name='foo'>{`<div class='bar'>baz</div>`}</Story>
Here’s what’s going on:
- The MDX is getting parsed by the
@mdx-js/mdx
parser - The resulting JSX is getting processed by our
mdx-compiler-plugin
- The output of the plug in CSF
- CSF is getting loaded into the
storiesOf
API
The contents of the <Story>
element is isomorphic to the return value of the CSF function, which is equal to the storiesOf
storyFn
.
Solution
For an alternative syntax to work, there are a bunch of things that need to happen:
- We need to determine the desired syntax
- Can it be parsed by the MDX parser?
- Can it be transformed into the format required by the
storiesOf
API (the return value ofstoryFn
for that particular framework) - Is that the currently
storiesOf
format we want to support in the future? I.e. if CSF is meant to become an open standard, we probably might to give that more thought to that. E.g. https://github.com/storybookjs/storybook/pull/7682 rethinks that for Svelte
Frameworks
We can do this framework by framework. Here are the ones that are on my radar right now. Can add more later.
- React
- Vue
- Angular
- HTML
- Svelte
- StencilJS
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:12 (11 by maintainers)
Top Results From Across the Web
MDX Format - Storybook - JS.ORG
MDX is the syntax Storybook Docs uses to capture long-form Markdown documentation and stories in one file. You can also write pure documentation...
Read more >Compare DocsPage and MDX syntax in Storybook with example
This post compares the DocsPage and MDX syntax to write story of your UI components using Storybook. We will continue with the Card...
Read more >storybook/addon-docs - npm
MDX is a syntax for writing long-form documentation and stories side-by-side in the same file. In contrast to DocsPage , which provides smart ......
Read more >@storybook/addon-docs | Yarn - Package Manager
Storybook Docs · DocsPage · MDX · Framework support · Installation · Preset options · Manual configuration · TypeScript configuration · More resources....
Read more >Styling tags generated by @storybook/addon-docs from MDX ...
The <Story> tag has an "inline" attribute that tells Storybook whether to inline the story in the html or to render it in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For information, on Svelte side, the equivalent of MDX is https://github.com/pngwn/MDsveX I did some extensive tests, it’s handled pretty well by the Svelte compiler (as a preprocess step that is feeded on the compiler). On Storybook side, I still have to catch up on the corresponding MRs.
Here’s a comment from a slack user, kind of contradicting what I said above:
Here’s a snippet: