Skip to content

Commit

Permalink
HTML: support knobs for both cached and uncached nodes (#6783)
Browse files Browse the repository at this point in the history
HTML: support knobs for both cached and uncached nodes
  • Loading branch information
ndelangen authored May 18, 2019
2 parents b826fdd + 8ee658c commit cb27dc1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
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

1 comment on commit cb27dc1

@vercel
Copy link

@vercel vercel bot commented on cb27dc1 May 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.