Skip to content

Commit

Permalink
fix: smart addonControls parameter option
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Feb 13, 2020
1 parent 444af02 commit 7832976
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@
}</script><style>#root[hidden],
#docs-root[hidden] {
display: none !important;
}</style></head><body><div class="sb-nopreview sb-wrapper"><div class="sb-nopreview_main"><h1 class="sb-nopreview_heading sb-heading">No Preview</h1><p>Sorry, but you either have no stories or none are selected somehow.</p><ul><li>Please check the Storybook config.</li><li>Try reloading the page.</li></ul><p>If the problem persists, check the browser console, or the terminal you've run Storybook from.</p></div></div><div class="sb-errordisplay sb-wrapper"><pre id="error-message" class="sb-heading"></pre><pre class="sb-errordisplay_code"><code id="error-stack"></code></pre></div><div id="root"></div><div id="docs-root"></div><script src="runtime~main.72dcd7c5365d3cf59f16.bundle.js"></script><script src="vendors~main.72dcd7c5365d3cf59f16.bundle.js"></script><script src="main.72dcd7c5365d3cf59f16.bundle.js"></script></body></html>
}</style></head><body><div class="sb-nopreview sb-wrapper"><div class="sb-nopreview_main"><h1 class="sb-nopreview_heading sb-heading">No Preview</h1><p>Sorry, but you either have no stories or none are selected somehow.</p><ul><li>Please check the Storybook config.</li><li>Try reloading the page.</li></ul><p>If the problem persists, check the browser console, or the terminal you've run Storybook from.</p></div></div><div class="sb-errordisplay sb-wrapper"><pre id="error-message" class="sb-heading"></pre><pre class="sb-errordisplay_code"><code id="error-stack"></code></pre></div><div id="root"></div><div id="docs-root"></div><script src="runtime~main.d469950d70f32d2a26af.bundle.js"></script><script src="vendors~main.d469950d70f32d2a26af.bundle.js"></script><script src="main.d469950d70f32d2a26af.bundle.js"></script></body></html>
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
}</script><style>#root[hidden],
#docs-root[hidden] {
display: none !important;
}</style></head><body><div id="root"></div><div id="docs-root"></div><script>window['DOCS_MODE'] = false;</script><script src="runtime~main.6b70b35614cf83eab770.bundle.js"></script><script src="vendors~main.74dd2f2713e9a7e6c4e7.bundle.js"></script><script src="main.ddcd67bc385c829f8b8c.bundle.js"></script></body></html>
}</style></head><body><div id="root"></div><div id="docs-root"></div><script>window['DOCS_MODE'] = false;</script><script src="runtime~main.6b70b35614cf83eab770.bundle.js"></script><script src="vendors~main.74dd2f2713e9a7e6c4e7.bundle.js"></script><script src="main.cd108ddf69041f77f8b1.bundle.js"></script></body></html>
2 changes: 0 additions & 2 deletions docs/main.72dcd7c5365d3cf59f16.bundle.js

This file was deleted.

1 change: 0 additions & 1 deletion docs/main.72dcd7c5365d3cf59f16.bundle.js.map

This file was deleted.

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/main.d469950d70f32d2a26af.bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/main.d469950d70f32d2a26af.bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/runtime~main.72dcd7c5365d3cf59f16.bundle.js.map

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/runtime~main.d469950d70f32d2a26af.bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/vendors~main.72dcd7c5365d3cf59f16.bundle.js.map

This file was deleted.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/vendors~main.d469950d70f32d2a26af.bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ noColors.story = {

// this story does not have parameters, and smart controls will be disabled for it
export const noProps = () => <Button label="No properties" />;

noProps.story = {
parameters: {
addonControls: { smart: false }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import Button from '../components/BaseButton';
# Story with no parameters == no smart controls

<Preview>
<Story name="no controls" parameters={{ addonControls: { smart: true }}}>
<Story name="no controls" parameters={{ addonControls: { smart: false }}}>
<Button label="Hello"/>
</Story>
</Preview>
29 changes: 26 additions & 3 deletions integrations/storybook/src/shared/smartControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,32 @@ export type SmartControls = boolean | SmartControlsConfig;
export const docgenToControls = (
parameters: Parameters,
): ComponentControls | null => {
const { component } = parameters || {};
if (component && component.__docgenInfo && component.__docgenInfo.props) {
return controlsFromProps(component.__docgenInfo.props);
const params = parameters || {};
const { component, addonControls = {} } = params;
const { smart: smartControls } = addonControls;
if (!smartControls) {
return null;
}
if (!component) {
return null;
}
if (component.__docgenInfo && component.__docgenInfo.props) {
const newControls = controlsFromProps(component.__docgenInfo.props);
const { include, exclude } = smartControls;
if (Array.isArray(include) || Array.isArray(exclude)) {
return Object.keys(newControls)
.filter(key => {
if (Array.isArray(include) && !include.includes(key)) {
return false;
}
if (Array.isArray(exclude) && exclude.includes(key)) {
return false;
}
return true;
})
.reduce((acc, key) => ({ ...acc, [key]: newControls[key] }), {});
}
return newControls;
}
return null;
};

0 comments on commit 7832976

Please sign in to comment.