-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Addon-docs: "Native"/natural MDX syntax #7984
Comments
Have you considered writing a Honestly the macro approach for a lot of the work that the compiler plug-in is doing would probably need to a nicer, more modular approach all-around for augmenting mdx to suit the needs of storybook. And we wouldn't have to deal with a bunch Babel configuration. Also Kent Dodds is brilliant and I never miss a chance to use his work :) |
@Aaron-Pool I'm not familiar with it. Sounds very cool though! Can you sketch out what that solution might look like? |
Sorry, I am bit new to the source code and it seems I might be missing something especially wrt html. Anyway, here is what i tried for html:
changed the code as follow:
and changed the 'addon-doc.stories.mdx' example from 'examples/html-kitchen-sink':
and the output is: |
tried also the above example: it works, except the html prop names need to follow the react syntax, so this works instead: |
@atanasster Are you running that in When you write
The point of
It's possible that JSX syntax is a pure superset of HTML and we can fake out the MDX parser to convert that JSX back into a string. But I wouldn't count on this working in all cases unless it's explicitly part of the spec. |
For the rest - I am getting there, correct me if I am wrong:
|
Until we've fully switched over #3889 (much later ... hopefully SB7.0?) each framework has its own app. In the monorepo those are There are a couple different ways to know what framework you're in. You probably have a line in your module.exports = ['@storybook/addon-docs/react/preset']; If you're using Another way to tell what framework you're in is to look at the This has all come together a bit organically with SB Docs, and I expect we'll want to rethink it as part of #3889 (probably as a breaking change in 6.0 cc @Hypnosphi ) |
@shilman yeah, I'll try to do a little summary of what a |
Here's a comment from a slack user, kind of contradicting what I said above:
Here's a snippet: import '.';
import '../icon';
import { Meta, Story, Preview, html, text, boolean } from '[redacted]';
import ReadMe from './README.md';
<Meta title="UI Kit|Accordion" />
<!-- Workaround until transclusion of md files is supported outright -->
<ReadMe.parameters.docs.page />
## Stories
<Preview>
<Story name="default">
<magic-ui-accordion>
<b slot="toggle">{text('Toggle Text', 'Default Toggle Text')}</b>
<ul slot="content">
<p>This is some content to display!</p>
<p>It's toggled every time the page is toggled</p>
</ul>
</magic-ui-accordion>
</Story>
</Preview> |
@shilman then what about we |
@shilman I believe that's what they call it when a bug becomes a feature 😄 |
For information, on Svelte side, the equivalent of MDX is https://github.com/pngwn/MDsveX |
In 7.0 we've deprecated defining stories in MDX and have introduced a better syntax for importing CSF stories into MDX. More information https://storybook.js.org/blog/storybook-7-docs/ |
Umbrella issue to extend "native" MDX from React to other frameworks
Problem
Currently in
@storybook/react
you can write JSX directly in your MDX file:For
@storybook/html
you'd probably like to write the following, but it won't work:Instead you'd have to write:
Here's what's going on:
@mdx-js/mdx
parsermdx-compiler-plugin
storiesOf
APIThe contents of the
<Story>
element is isomorphic to the return value of the CSF function, which is equal to thestoriesOf
storyFn
.Solution
For an alternative syntax to work, there are a bunch of things that need to happen:
storiesOf
API (the return value ofstoryFn
for that particular framework)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. Svelte: Svelte syntax Component Story Format #7682 rethinks that for SvelteFrameworks
We can do this framework by framework. Here are the ones that are on my radar right now. Can add more later.
The text was updated successfully, but these errors were encountered: