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

HTML: support knobs for both cached and uncached nodes #6783

Merged
merged 1 commit into from
May 18, 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: 2 additions & 2 deletions app/html/src/client/preview/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export default function renderMain({
showError,
forceRender,
}) {
const { html = {} } = parameters;
const element = storyFn();

showMain();
if (typeof element === 'string') {
rootElement.innerHTML = element;
} else if (element instanceof Node) {
if (html.preventForcedRender === true && forceRender === true) {
// Don't re-mount the element if it didn't change and neither did the story
if (rootElement.firstChild === element && forceRender === true) {
return;
}

Expand Down
3 changes: 0 additions & 3 deletions examples/html-kitchen-sink/.storybook/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ addParameters({
restoreScroll: true,
},
},
html: {
preventForcedRender: false, // default
},
options: {
hierarchyRootSeparator: /\|/,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ exports[`Storyshots Addons|Knobs All knobs 1`] = `
</div>
`;

exports[`Storyshots Addons|Knobs CSS transitions 1`] = `
<p
style="transition: color 0.5s ease-out; color: orangered;"
>
John Doe
</p>
`;

exports[`Storyshots Addons|Knobs DOM 1`] = `
<p>
John Doe
Expand Down
11 changes: 10 additions & 1 deletion examples/html-kitchen-sink/stories/addon-knobs.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { storiesOf } from '@storybook/html';
import { action } from '@storybook/addon-actions';
import { document } from 'global';

import {
array,
Expand All @@ -13,6 +14,7 @@ import {
number,
} from '@storybook/addon-knobs';

const cachedContainer = document.createElement('p');
storiesOf('Addons|Knobs', module)
.addDecorator(withKnobs)
.add('Simple', () => {
Expand All @@ -24,11 +26,18 @@ storiesOf('Addons|Knobs', module)
})
.add('DOM', () => {
const name = text('Name', 'John Doe');
// eslint-disable-next-line
const container = document.createElement('p');
container.textContent = name;
return container;
})
.add('CSS transitions', () => {
const name = text('Name', 'John Doe');
const textColor = color('Text color', 'orangered');
cachedContainer.textContent = name;
cachedContainer.style.transition = 'color 0.5s ease-out';
cachedContainer.style.color = textColor;
return cachedContainer;
})
.add('All knobs', () => {
const name = text('Name', 'Jane');
const stock = number('Stock', 20, {
Expand Down