Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forced renders in @storybook/html #6190

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/html/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ import { stripIndents } from 'common-tags';
const rootElement = document.getElementById('root');

export default function renderMain({
parameters = {},
storyFn,
selectedKind,
selectedStory,
showMain,
showError,
forceRender,
}) {
const { html = {} } = parameters;
const element = storyFn();

showMain();
if (typeof element === 'string') {
rootElement.innerHTML = element;
} else if (element instanceof Node) {
if (forceRender === true) {
if (html.preventForcedRender === true && forceRender === true) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions examples/html-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { configure, addParameters } from '@storybook/html';

addParameters({
html: {
preventForcedRender: false, // default
},
options: {
hierarchyRootSeparator: /\|/,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ exports[`Storyshots Addons|Knobs All knobs 1`] = `
</div>
`;

exports[`Storyshots Addons|Knobs DOM 1`] = `
<p>
John Doe
</p>
`;

exports[`Storyshots Addons|Knobs Simple 1`] = `
<div>
I am John Doe and I'm 44 years old.
Expand Down
7 changes: 7 additions & 0 deletions examples/html-kitchen-sink/stories/addon-knobs.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ storiesOf('Addons|Knobs', module)

return `<div>${content}</div>`;
})
.add('DOM', () => {
const name = text('Name', 'John Doe');
// eslint-disable-next-line
const container = document.createElement('p');
container.textContent = name;
return container;
})
.add('All knobs', () => {
const name = text('Name', 'Jane');
const stock = number('Stock', 20, {
Expand Down