storybook-addon-react-live-edit
Version:
storybook.js addon providing live react story editing and preview
113 lines (87 loc) • 3.26 kB
Markdown

```bash
yarn add -D storybook-addon-react-live-edit
```
To get this addon in your story book you have to register the panel, `addLiveSource` story creator
and optionally add a scope decorator to make additional components and utilities available in live editor scope
Add to .storybook/addons.js
```javascript
import 'storybook-addon-react-live-edit/dist/register';
```
Add to .storybook/config.js
```javascript
import {setAddon} from '@storybook/react';
import LiveEdit, {setOptions} from 'storybook-addon-react-live-edit';
setOptions({ theme: 'darcula', presets: ['react'] });
setAddon(LiveEdit);
```
addDecorator to .storybook/config.js
```javascript
import {addDecorator} from '@storybook/react';
import {withLiveEditScope} from 'storybook-addon-react-live-edit';
import ExternalComponent from 'a-apackage';
addDecorator(withLiveEditScope({ ExternalComponent }));
```
> or
addDecorator to particular stories
```javascript
import {withLiveEditScope} from 'storybook-addon-react-live-edit';
import ExternalComponent from 'a-apackage';
storiesOf("Demo", module)
.addDecorator(withLiveEditScope({ React, ExternalComponent }))
.addLiveSource('demo', `return <div>{scopeTest}</div>`);
```
When LiveEdit addon is registered with storybooks `setAddon` function new method `addLiveSource`
to add a story from source provided as a string. This source can be edited in "Live edit" panel
```javascript
storiesOf("Demo", module)
.addLiveSource('demo', `return <div>{scopeTest}</div>`);
```
> or
You can use `withLiveEdit` story creator
```javascript
storiesOf("Demo", module)
.add('demo', withLiveEdit(`return <div>{scopeTest}</div>`));
```
```
addLiveSource(name, source[, scope])
```
- `name` (string, required) - the story name
- `source` (string, required) - story source to be rendered in preview and
available for editing in "Live edit" panel
- `scope` (object, optional) - variables provided to rendered story,
these can be additional components, utilities or any other data.
Scope is merged with all variables previously provided
by `withLiveEditScope` decorators.
```
withLiveEdit(source[, scope])
```
- `source` (string, required) - story source to be rendered in preview and
available for editing in "Live edit" panel
- `scope` (object, optional) - variables provided to rendered story,
these can be additional components, utilities or any other data.
Scope is merged with all variables previously provided
by `withLiveEditScope` decorators.
```
withLiveEditScope(scope)
```
- `scope` (object, required) - variables provided to rendered story,
these can be additional components, utilities or any other data.
Scope is merged with all variables previously provided
by `withLiveEditScope` decorators. React should be imported and provided within the scope object.
To run provided example execute following command, storybook will run on port 3000
```bash
yarn example
```