-
-
Notifications
You must be signed in to change notification settings - Fork 249
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@storybook/react'; | ||
|
||
import Button from '../components/Button'; | ||
// import Button from '../components/Button'; | ||
|
||
import ButtonReadme from '../components/Button/README.md'; | ||
import ButtonUsage from '../components/Button/USAGE.md'; | ||
import Multiple from './Multiple.md'; | ||
|
||
const ButtonReadme = '# hi'; | ||
|
||
storiesOf('Button', module) | ||
.addParameters({ | ||
readme: { | ||
codeTheme: 'duotone-sea', | ||
content: ButtonReadme, | ||
sidebar: ButtonUsage, | ||
content: Multiple, | ||
}, | ||
}) | ||
.add('Button', () => <Button label={'Hello Im Button'} />) | ||
.add('Alert Button', () => ( | ||
<Button variant="alert" label={'Hello Im Button'} /> | ||
)) | ||
.add('Success Button', () => ( | ||
<Button variant="success" label={'Hello Im Button'} /> | ||
)); | ||
|
||
.add('README.md', () => { | ||
return null; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
## Title | ||
|
||
Some description | ||
|
||
```js | ||
// const Button = require('../components/Button'); | ||
|
||
<button>Hello World</button> | ||
``` | ||
|
||
```js | ||
// const Button = require('../components/Button'); | ||
|
||
const value = state.counter || 0; | ||
|
||
<button | ||
onClick={() => { | ||
setState({ | ||
counter: value + 1, | ||
}); | ||
}} | ||
> | ||
Hello World {value} | ||
</button>; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,34 @@ | ||
import React from 'react'; | ||
import { configureReadme, addFooter, addHeader } from 'storybook-readme'; | ||
|
||
configureReadme({ | ||
// codeTheme: 'far', | ||
header: ` | ||
// configureReadme({ | ||
// // codeTheme: 'far', | ||
// header: ` | ||
|
||
### \`storybook-readme\` addon example | ||
<img src="https://storybook.js.org//images/logos/logo-storybook.svg"/> | ||
// ### \`storybook-readme\` addon example | ||
// <img src="https://storybook.js.org//images/logos/logo-storybook.svg"/> | ||
|
||
--- | ||
// --- | ||
|
||
`, | ||
footer: ` | ||
// `, | ||
// footer: ` | ||
|
||
--- | ||
// --- | ||
|
||
- Sources of this storybook (with React components) [tuchk4/storybook-readme/packages/example-react](https://github.com/tuchk4/storybook-readme/tree/master/packages/example-react) | ||
- Sources of the same Vue storybook [tuchk4/storybook-readme/packages/example-vue](https://github.com/tuchk4/storybook-readme/tree/master/packages/example-vue) | ||
- Issues and suggestions [storybook-readme/issues](https://github.com/tuchk4/storybook-readme/issues). You are welcome to suggest to awesome feature or report an annoying bug. | ||
- <img src="https://upload.wikimedia.org/wikipedia/ru/thumb/9/9f/Twitter_bird_logo_2012.svg/1200px-Twitter_bird_logo_2012.svg.png" alt="twitter" style="width:16px;"/> [tuchk4](https://twitter.com/tuchk) | ||
// - Sources of this storybook (with React components) [tuchk4/storybook-readme/packages/example-react](https://github.com/tuchk4/storybook-readme/tree/master/packages/example-react) | ||
// - Sources of the same Vue storybook [tuchk4/storybook-readme/packages/example-vue](https://github.com/tuchk4/storybook-readme/tree/master/packages/example-vue) | ||
// - Issues and suggestions [storybook-readme/issues](https://github.com/tuchk4/storybook-readme/issues). You are welcome to suggest to awesome feature or report an annoying bug. | ||
// - <img src="https://upload.wikimedia.org/wikipedia/ru/thumb/9/9f/Twitter_bird_logo_2012.svg/1200px-Twitter_bird_logo_2012.svg.png" alt="twitter" style="width:16px;"/> [tuchk4](https://twitter.com/tuchk) | ||
|
||
|
||
`, | ||
}); | ||
// `, | ||
// }); | ||
|
||
import './Button'; | ||
import './withCustomPreview'; | ||
import './withSidebarDocs'; | ||
import './withContentDocs'; | ||
import './withEmoji'; | ||
import './withPropsTable'; | ||
import './withCustomTheme'; | ||
import './withCustomCodeTheme'; | ||
import './withOldApi'; | ||
// import './withCustomPreview'; | ||
// import './withSidebarDocs'; | ||
// import './withContentDocs'; | ||
// import './withEmoji'; | ||
// import './withPropsTable'; | ||
// import './withCustomTheme'; | ||
// import './withCustomCodeTheme'; | ||
// import './withOldApi'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{/* <div | ||
className={'markdown-body'} | ||
dangerouslySetInnerHTML={{ __html: content }} | ||
/> | ||
/> */} | ||
</DocPreview> | ||
); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,14 @@ export default function getDocsLayout({ | |
}) { | ||
const mdAsArray = Array.isArray(md) ? [...md] : [md]; | ||
// const mdWithEmojis = mdAsArray.map(md => transformEmojis(md)); | ||
|
||
return [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
{ | ||
type: LAYOUT_TYPE_MD, | ||
content: mdAsArray.map(processMd), | ||
}, | ||
]; | ||
|
||
const mdWithEmojis = mdAsArray.map(processMd); | ||
|
||
const main = mdWithEmojis[0]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,64 @@ | ||
import marked from 'marked'; | ||
// import marked from 'marked'; | ||
import React, { createElement } from 'react'; | ||
import * as buble from 'buble'; | ||
import { Parser } from 'acorn'; | ||
|
||
export default md => marked(md); | ||
import marksy from 'marksy/jsx'; | ||
|
||
const unsemicolon = s => s.replace(/;\s*$/, ''); | ||
|
||
function processCode(code) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Transforms into const value = state.counter || 0;
return <button
onClick={() => {
setState({
counter: value + 1,
});
}}
>
Hello World {value}
</button>; |
||
const ast = Parser.parse(code, { | ||
ecmaVersion: 2019, | ||
sourceType: 'module', | ||
}); | ||
|
||
if (!ast) { | ||
return code; | ||
} | ||
|
||
const firstExpression = ast.body | ||
.reverse() | ||
.find(({ type }) => type === 'ExpressionStatement'); | ||
|
||
if (!firstExpression) { | ||
return code; | ||
} | ||
|
||
const { start, end } = firstExpression; | ||
|
||
const firstExpressionCode = unsemicolon(code.substring(start, end)); | ||
return ` | ||
${unsemicolon(code.substring(0, start))}; | ||
|
||
return (${firstExpressionCode}); | ||
`; | ||
} | ||
|
||
const getStoryComponent = code => { | ||
return new Function('require', 'state', 'setState', 'React', code); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. eval |
||
}; | ||
|
||
export default md => { | ||
const compile = marksy({ | ||
createElement, | ||
elements: { | ||
code({ language, code, ...props }) { | ||
const transformedCode = processCode(buble.transform(code).code); | ||
const story = getStoryComponent(transformedCode); | ||
|
||
// find initial state variable at AST ans set in here | ||
const initialState = {}; | ||
const [state, setState] = React.useState({ | ||
...initialState, | ||
}); | ||
|
||
return <div>{story(require, state, setState, React)}</div>; | ||
}, | ||
}, | ||
}); | ||
|
||
const compiled = compile(md); | ||
|
||
return compiled.tree; | ||
}; |
There was a problem hiding this comment.
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.