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

[Proof of Concept] Multiple Stories inside one MD #178

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tuchk4
Copy link
Owner

@tuchk4 tuchk4 commented Jun 18, 2019

Current blockers:

Importing components from md code blocks

The problem is that we parse it in runtime and seems it is not possible to make dynamic imports.
To make it possible we should parse it with webpack but this seems to be a complicated solution.

import Button  from '../components/Button';
<Button>Hello World</Button>

Maybe it is better to pass components as story arguments instead of importing them.

storiesOf('Button', module).add(
  'Button variants',
  mdx({
    content: require('./Multiple.md'),
    components: { Button }
  }),
);

Implementation for VUE

I am not experienced with vue. Would be nice if someone with experience would help with implementation.


We could start with React implementation and then add support for Vue.

@lonyele What do you think?

```

```js
// const Button = require('../components/Button');
Copy link
Owner Author

Choose a reason for hiding this comment

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

Right now don't know how correctly import components.
It should work in context of md file dir.

@@ -130,10 +130,11 @@ export default class ReadmeContent extends React.Component {
case LAYOUT_TYPE_MD:
return (
<DocPreview key={index}>
<div
<div className={'markdown-body'}>{content}</div>
Copy link
Owner Author

Choose a reason for hiding this comment

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

content is rendered components tree

@@ -66,6 +66,14 @@ export default function getDocsLayout({
}) {
const mdAsArray = Array.isArray(md) ? [...md] : [md];
// const mdWithEmojis = mdAsArray.map(md => transformEmojis(md));

return [
Copy link
Owner Author

Choose a reason for hiding this comment

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

remove old md features for Proof of convept. Returns only compiled md content


const unsemicolon = s => s.replace(/;\s*$/, '');

function processCode(code) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

const value = state.counter || 0;

<button
  onClick={() => {
    setState({
      counter: value + 1,
    });
  }}
>
  Hello World {value}
</button>;

Transforms into

const value = state.counter || 0;

return <button
  onClick={() => {
    setState({
      counter: value + 1,
    });
  }}
>
  Hello World {value}
</button>;

}

const getStoryComponent = code => {
return new Function('require', 'state', 'setState', 'React', code);
Copy link
Owner Author

Choose a reason for hiding this comment

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

eval

@tuchk4 tuchk4 changed the title Proof of concept: MDX Multiple Stories inside one MD Proof of concept Jun 18, 2019
@tuchk4 tuchk4 changed the title Multiple Stories inside one MD Proof of concept [Proof of Concept] Multiple Stories inside one MD Jun 18, 2019
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.

1 participant