Merge pull request #12164 from storybookjs/12138-html-fix-inline-rendering

Addon-docs: Fix inline rendering for DOM nodes in HTML
This commit is contained in:
Michael Shilman 2020-08-20 18:21:27 +08:00 committed by GitHub
commit ff5f4804de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,9 +4,13 @@ import { StoryFn } from '@storybook/addons';
export const parameters = {
docs: {
inlineStories: true,
prepareForInline: (storyFn: StoryFn<string>) => (
// eslint-disable-next-line react/no-danger
<div dangerouslySetInnerHTML={{ __html: storyFn() }} />
),
prepareForInline: (storyFn: StoryFn<string>) => {
const html = storyFn();
if (typeof html === 'string') {
// eslint-disable-next-line react/no-danger
return <div dangerouslySetInnerHTML={{ __html: html }} />;
}
return <div ref={(node) => (node ? node.appendChild(html) : null)} />;
},
},
};