mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 15:31:16 +08:00
add withMarkdownNotes
This commit is contained in:
parent
b331f2d24c
commit
0bfe868cb1
@ -3,18 +3,19 @@
|
||||
[](https://circleci.com/gh/storybooks/storybook)
|
||||
[](https://www.codefactor.io/repository/github/storybooks/storybook)
|
||||
[](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847)
|
||||
[](https://bettercodehub.com/results/storybooks/storybook) [](https://codecov.io/gh/storybooks/storybook)
|
||||
[](https://bettercodehub.com/results/storybooks/storybook) [](https://codecov.io/gh/storybooks/storybook)
|
||||
[](https://now-examples-slackin-rrirkqohko.now.sh/)
|
||||
[](#backers) [](#sponsors)
|
||||
|
||||
* * *
|
||||
---
|
||||
|
||||
Storybook Addon Notes allows you to write notes (text or HTML) for your stories in [Storybook](https://storybook.js.org).
|
||||
|
||||
This addon works with Storybook for:
|
||||
- [React](https://github.com/storybooks/storybook/tree/master/app/react)
|
||||
- [React Native](https://github.com/storybooks/storybook/tree/master/app/react-native)
|
||||
- [Vue](https://github.com/storybooks/storybook/tree/master/app/vue)
|
||||
|
||||
* [React](https://github.com/storybooks/storybook/tree/master/app/react)
|
||||
* [React Native](https://github.com/storybooks/storybook/tree/master/app/react-native)
|
||||
* [Vue](https://github.com/storybooks/storybook/tree/master/app/vue)
|
||||
|
||||

|
||||
|
||||
@ -29,7 +30,7 @@ Then create a file called `addons.js` in your storybook config.
|
||||
Add following content to it:
|
||||
|
||||
```js
|
||||
import '@storybook/addon-notes/register';
|
||||
import "@storybook/addon-notes/register";
|
||||
```
|
||||
|
||||
Then write your stories like this:
|
||||
@ -49,25 +50,48 @@ storiesOf('Component', module)
|
||||
To use markdown in your notes simply import a markdown file and use that in your note.
|
||||
|
||||
```js
|
||||
import { storiesOf } from '@storybook/react';
|
||||
import { withNotes } from '@storybook/addon-notes';
|
||||
import Component from './Component';
|
||||
import someMarkdownText from './someMarkdownText.md';
|
||||
|
||||
storiesOf('Component', module)
|
||||
.add('With Markdown', withNotes(someMarkdownText)(() => <Component/>));
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import { withNotes } from "@storybook/addon-notes";
|
||||
import Component from "./Component";
|
||||
import someMarkdownText from "./someMarkdownText.md";
|
||||
|
||||
storiesOf("Component", module).add("With Markdown", withNotes(someMarkdownText)(() => <Component />));
|
||||
```
|
||||
|
||||
If you want to use Github flavored markdown inline, use `withMarkdownNotes`:
|
||||
|
||||
```js
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import { withMarkdownNotes } from "@storybook/addon-notes";
|
||||
import Component from "./Component";
|
||||
|
||||
storiesOf("Component", module).add(
|
||||
"With Markdown",
|
||||
withMarkdownNotes(`
|
||||
# Hello World
|
||||
|
||||
This is some code showing usage of the component and other inline documentation
|
||||
|
||||
~~~js
|
||||
<div>
|
||||
hello world!
|
||||
<Component/>
|
||||
</div>
|
||||
~~~
|
||||
`)(() => <Component />)
|
||||
);
|
||||
```
|
||||
|
||||
### Deprecated API
|
||||
|
||||
This API is slated for removal in 4.0
|
||||
|
||||
```js
|
||||
import { WithNotes } from '@storybook/addon-notes';
|
||||
import { WithNotes } from "@storybook/addon-notes";
|
||||
|
||||
storiesOf('Addon Notes', module)
|
||||
.add('using deprecated API', () => (
|
||||
<WithNotes notes="Hello">
|
||||
<BaseButton onClick={action('clicked')} label="😀 😎 👍 💯" />
|
||||
</WithNotes>
|
||||
));
|
||||
storiesOf("Addon Notes", module).add("using deprecated API", () => (
|
||||
<WithNotes notes="Hello">
|
||||
<BaseButton onClick={action("clicked")} label="😀 😎 👍 💯" />
|
||||
</WithNotes>
|
||||
));
|
||||
```
|
||||
|
@ -21,6 +21,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.26.0",
|
||||
"marked": "^0.3.12",
|
||||
"prop-types": "^15.6.0",
|
||||
"util-deprecate": "^1.0.2"
|
||||
},
|
||||
|
@ -1,7 +1,18 @@
|
||||
import deprecate from 'util-deprecate';
|
||||
import addons from '@storybook/addons';
|
||||
import marked from 'marked';
|
||||
import { WithNotes as ReactWithNotes } from './react';
|
||||
|
||||
export const withMarkdownNotes = text => {
|
||||
const channel = addons.getChannel();
|
||||
|
||||
return getStory => context => {
|
||||
// send the notes to the channel before the story is rendered
|
||||
channel.emit('storybook/notes/add_notes', marked(text));
|
||||
return getStory(context);
|
||||
};
|
||||
};
|
||||
|
||||
export const withNotes = textOrOptions => {
|
||||
const channel = addons.getChannel();
|
||||
const options = typeof textOrOptions === 'string' ? { text: textOrOptions } : textOrOptions;
|
||||
|
Loading…
x
Reference in New Issue
Block a user