Skip to content

Commit

Permalink
Merge pull request #110 from petermikitsh/disable-jsx
Browse files Browse the repository at this point in the history
feat: disable jsx per story
  • Loading branch information
hipstersmoothie authored Jun 5, 2020
2 parents e7787e2 + 1d73ec9 commit 9a509cd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 28 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ storiesOf('test 2', module).addWithJSX(
// <div>Inner HTML</div>
```

### Disable JSX Addon

If enabled globally, the JSX addon can be disabled on individual stories:

```jsx
export const Simple = () => <div>Hello</div>;

Simple.story = {
parameters: {
jsx: {
disable: true
}
}
};
```

### Not JSX

If a Vue story defines its view with a template string then it will be displayed
Expand Down
60 changes: 32 additions & 28 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import {
addons,
makeDecorator,
StoryContext,
StoryFn,
StoryApi,
Expand Down Expand Up @@ -157,39 +158,42 @@ const defaultOpts = {
};

/** Extract components from story and emit them to the panel */
export const jsxDecorator = (
storyFn: StoryFn<React.ReactElement<any>>,
parameters?: StoryContext
) => {
const channel = addons.getChannel();
const story: ReturnType<typeof storyFn> & VueComponent = storyFn();
const options = {
...defaultOpts,
...((parameters && parameters.parameters.jsx) || {})
} as Required<JSXOptions>;

let components: ComponentMap = {};
let jsx = '';

if (story.template) {
if (options.enableBeautify) {
jsx = beautifyHTML(story.template, options);
export const jsxDecorator = makeDecorator({
name: 'jsx',
parameterName: 'jsx',
wrapper: (storyFn: any, parameters: StoryContext) => {
const story: ReturnType<typeof storyFn> & VueComponent = storyFn();

const channel = addons.getChannel();

const options = {
...defaultOpts,
...((parameters && parameters.parameters.jsx) || {})
} as Required<JSXOptions>;

let components: ComponentMap = {};
let jsx = '';

if (story.template) {
if (options.enableBeautify) {
jsx = beautifyHTML(story.template, options);
} else {
jsx = story.template;
}
} else {
jsx = story.template;
}
} else {
const rendered = renderJsx(story, options);
const rendered = renderJsx(story, options);

if (rendered) {
jsx = rendered;
components = getDocs(story);
if (rendered) {
jsx = rendered;
components = getDocs(story);
}
}
}

channel.emit(EVENTS.ADD_JSX, (parameters || {}).id, jsx, components);
channel.emit(EVENTS.ADD_JSX, (parameters || {}).id, jsx, components);

return story;
};
return story;
}
});

export default {
addWithJSX(this: StoryApi, kind: string, storyFn: StoryFn<any>) {
Expand Down

0 comments on commit 9a509cd

Please sign in to comment.