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: Override generated code snippet. #10026

Closed
alanshortis opened this issue Mar 2, 2020 · 3 comments
Closed

Addon-docs: Override generated code snippet. #10026

alanshortis opened this issue Mar 2, 2020 · 3 comments

Comments

@alanshortis
Copy link

Part of my system is to show typography, and something I would like to do is wrap my tags in a div with contentEditable so that the sample text can be edited. This works well, expect my wrapping div appears in the genrated code snippet as they're also children of the Preview and Story componnents.

<Preview inline="false">
  <Story name="Heading 1">
    <Editable>
      <h1>Why should I register to vote?</h1>
    </Editable>
  </Story>
</Preview>

As above, the code snippet would inclide my Editable wrapper but this isn't something an end user should even be aware of.

Ideally, it'd be possible to provide an optional snippet that is show as the code sample rather than the automatically generated one.

A workaround for this particular scenario is to use the knobs addon to allow text editing in the Canvas view, but this doesn't help with other scenarios where some wrapping HTML might help with showing off a component but is not relevent to the code snippet.

I'd be willing to take a look at implemting a solution if this feature is deemed helpful.

@VladimirPittner
Copy link

Hi,
I think what you are looking for is prop mdxSource of Preview that will let you pass custom "source code" -> https://github.com/storybookjs/storybook/blob/v5.3.14/addons/docs/src/blocks/Preview.tsx#L15

@alanshortis
Copy link
Author

Thanks @VladimirPittner - that's exactly what I needed.

@shilman
Copy link
Member

shilman commented Mar 4, 2020

Duplicate to #7479

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

No branches or pull requests

3 participants