Skip to content
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: Support MDX source in Preview w/ no Story blocks #7966

Merged
merged 10 commits into from
Oct 15, 2019

Conversation

atanasster
Copy link
Member

@atanasster atanasster commented Sep 2, 2019

Issue: #7844

What I did

The mdx compiler now works directly with the AST to change props of components
added test cases for

<Preview>
  <Button onClick={action('clicked')}>view source in preview</Button>
</Preview>

The <Preview /> component in addon-docs checks for the mdxSource property to display source code.

How to test

The change is a new double pass:

  1. babel parsing of the mdx ast @babel/parser
  2. generate back the code using @babel/generator

while previously the original ast was preserved, so it can be a breaking change

  • Is this testable with Jest or Chromatic screenshots?
    yes not sure how to test from the scripts, but this hint from @shilman works:
    yarn jest --testPathPattern=mdx-compiler-plugin.test.js

  • Does this need a new example in the kitchen sink apps?
    added example to addon-docs.stories.mdx in official-storybook

  • Does this need an update to the documentation?
    no

@vercel
Copy link

vercel bot commented Sep 2, 2019

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/storybook/monorepo/7kwn8a0km
🌍 Preview: https://monorepo-git-fork-atanasster-mdx-source-preview.storybook.now.sh

@stale
Copy link

stale bot commented Sep 29, 2019

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Sep 29, 2019
@stale stale bot removed the inactive label Sep 29, 2019
@sanchez
Copy link

sanchez commented Oct 3, 2019

Hi team I am wondering how far away this request is before it can be apart of the "@next" release? Thanks

@shilman
Copy link
Member

shilman commented Oct 4, 2019

@sanchez This works. I'm hesitant to merge, however, since it's just adding complexity to something that already seems unnecessarily complex. I'll try to figure it out with @atanasster once he's back from vacation next week.

@sanchez
Copy link

sanchez commented Oct 6, 2019

Awesome and Thanks. Currently as it stands the only way for me to test this feature is to pull the request and link to an existing project correct? If only there was a next of a next. Cheers!

@shilman
Copy link
Member

shilman commented Oct 6, 2019

@sanchez correct. it's really easy to pull & test it out in examples/official-storybook by using the instructions in CONTRIBUTING.md. much trickier to test it out in your own project.

@shilman shilman changed the title mdx compiler - add mdxSource prop to Preview Addon-docs: Show source even when there are no Story blocks inside Preview Oct 15, 2019
@shilman shilman changed the title Addon-docs: Show source even when there are no Story blocks inside Preview Addon-docs: Show source when there are no Story blocks inside Preview Oct 15, 2019
@shilman shilman changed the title Addon-docs: Show source when there are no Story blocks inside Preview Addon-docs: Show MDX source when no Story blocks inside Preview Oct 15, 2019
@shilman shilman changed the title Addon-docs: Show MDX source when no Story blocks inside Preview Addon-docs: Support MDX source in case of no Story blocks inside Preview Oct 15, 2019
@shilman shilman changed the title Addon-docs: Support MDX source in case of no Story blocks inside Preview Addon-docs: Support MDX source in Preview w/ no Story blocks Oct 15, 2019
Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Sorry for the slow merge!!!

@joshjeong
Copy link

Hrm I've seen to have run into this issue in v5.3.19. Not sure if I'm missing something.

buttons.stories.js

import mdx from './buttons.mdx';

export default {
  title: 'Atoms/Buttons/Basic',
  decorators: [withKnobs, withA11y],
  parameters: {
    docs: {
      page: mdx,
      includeStories: [],
    },
  },
  component: Button,
};

buttons.mdx

// This does not work. The code is not available for preview.
  <Preview>
      <Button>I am a button</Button>
  </Preview>


//This works perfectly fine and shows code
<Preview>
  <Story id="atoms-buttons-basic--secondary-button" />
</Preview>

@shilman
Copy link
Member

shilman commented Jun 6, 2020

@joshjeong seems to be working here (see the button "view source in preview" mindway down the page) and the code in our monorepo:

https://storybookjs.netlify.app/official-storybook/?path=/docs/addons-docs-mdx-id--hello-story

do you need to rename your file "button.stories.mdx"?

@joshjeong
Copy link

Wouldn't that require a Meta tag and create separate stories?
I'm looking to replace the Docs tab for my current CSF Button components.
For example, create a mdx doc to replace the ones generated for these components
https://storybookjs.netlify.app/official-storybook/?path=/docs/basics-button--all-buttons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants