question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code preview with CSF Stories with MDX Docs shows only imported function

See original GitHub issue

Describe the bug When creating story according to this recipe https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-mdx-docs

To Reproduce Steps to reproduce the behaviour:

  1. Create story by recipe mentioned above
  2. Start storybook
  3. See the docs tabs

Expected behaviour Code will be available from real story

Screenshots

image

Code snippets

import { Meta, Story, Preview } from "@storybook/addon-docs/blocks";
import * as stories from "./mix.stories.js";

<Meta title="a/mix" />

# Button

<Preview>
  <Story name="basic">{stories.basic()}</Story>
</Preview>
import React from "react";
import { Button } from "@storybook/react/demo";

export default {
  title: "a/mix",
  includeStories: []
};

export const basic = () => <Button>Hello Button</Button>;

System:

  System:
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
  Browsers:
    Chrome: 79.0.3945.130
    Firefox: 70.0.1
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-actions: ^5.3.7 => 5.3.7
    @storybook/addon-docs: ^5.3.7 => 5.3.7
    @storybook/addon-links: ^5.3.7 => 5.3.7
    @storybook/addons: ^5.3.7 => 5.3.7
    @storybook/react: ^5.3.7 => 5.3.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:11
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

17reactions
shilmancommented, Feb 28, 2020

Hope to spend time on this during this 6.0 cycle. This is a dealbreaker for the currently recommended CSF/MDX mix.

3reactions
persefoniaicommented, May 14, 2020

@lpoulter Sure. Here you go using the OP examples:

mdx

import * as stories from "./mix.stories.js";

<Meta title="a/mix" parameters={{ docs: { source: { code: stories.jsxCode } } }} />

# Button

<Preview>
  <Story name="basic">{stories.basic()}</Story>
</Preview>

story

import { Button } from "@storybook/react/demo";

export default {
  title: "a/mix",
  includeStories: []
};

export const basic = () => <Button>Hello Button</Button>;

export const jsxCode = `<Button>Hello Button</Button>;`

If you are using the external Source block you can also pipe the source code in without the Meta param approach:

<Source code={stories.jsxCode} />

which could potentially let you get into more complicated combinations depending upon what you are doing with your mdx layout. Or the last option we found was you can pipe it to the Story directly for more control if you have multiple Preview blocks:

<Preview>
     <Story name="basic" parameters={{docs: { source: { code: stories.jsxCode}}}}>...

HTH.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MDX - Storybook
MDX -flavored Component Story Format (CSF) includes a collection of components called "Doc Blocks", that allow Storybook to translate MDX files into Storybook ......
Read more >
Setup CSF + MDX stories with @storybook/addon-docs - GitLab
Component Story Format (CSF) is a new way to write stories that drops ... shown below stories and are also imported in design.gitlab.com...
Read more >
Storybook Docs with mdx support and addon knobs - Medium
To get this source code to show up, we need to add source: true in the example .storybook/preview.js file at the top of...
Read more >
Storybook for everyone: CSF vs. MDX - DEV Community ‍ ‍
The PropTypes function will be used in our Docs Block later to show our ArgsTable with all the args (props) included in our...
Read more >
storybook/addon-docs - npm
import { Meta, Story, Canvas } from '@storybook/addon-docs'; import { Checkbox } from './Checkbox'; <Meta title="MDX/Checkbox" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found