Skip to content

Commit

Permalink
feat: allow custom code to be used instead of story source (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbardini authored Apr 19, 2020
1 parent ec6df5c commit c4cd667
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ See [`example`](example) for a minimal working setup.

The addon can be configured globally and per story with the `playroom` parameter. The following options are available:

| Option | Description | Default |
|:---------------------------------|:-----------------------------------------|:------------------------|
| `url` | the Playroom URL | `http://localhost:9000` |
| `disabled` | whether to disable the addon | `false` |
| `reactElementToJSXStringOptions` | [react-element-to-jsx-string options][1] | `{ sortProps: false }` |
| Option | Type | Description | Default |
|:---------------------------------|:----------|:-----------------------------------------|:------------------------|
| `url` | `string` | the Playroom URL | `http://localhost:9000` |
| `code` | `string` | code to be used instead of story source | |
| `disabled` | `boolean` | whether to disable the addon | `false` |
| `reactElementToJSXStringOptions` | `object` | [react-element-to-jsx-string options][1] | `{ sortProps: false }` |

### Global configuration

Expand Down
6 changes: 6 additions & 0 deletions example/stories/0-Welcome.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ export const ToStorybook = () => <Welcome showApp={linkTo('Button')} />;

ToStorybook.story = {
name: 'to Storybook',
parameters: {
playroom: {
// Links addon doesn't work in Playroom, so display an alert instead
code: "<Welcome showApp={() => alert('Button')} />",
},
},
};
3 changes: 2 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ const Story: FC<Props> = ({
settings: {
parameters: {
url = 'http://localhost:9000',
code,
disabled = false,
reactElementToJSXStringOptions = { sortProps: false },
} = {},
},
}) => {
const story = getStory(context);
const jsxString = reactElementToJSXString(story, reactElementToJSXStringOptions);
const jsxString = code || reactElementToJSXString(story, reactElementToJSXStringOptions);
const channel = addons.getChannel();
const codeUrl = url && `${url}#?code=${base64Url.encode(jsxString)}`;

Expand Down

0 comments on commit c4cd667

Please sign in to comment.