addon withInfo propTablesExclude does not exclude
See original GitHub issueBug or support request summary
I am trying to exclude components from being shown in Prop Tables section like mentioned herer: docs https://github.com/storybooks/storybook/tree/master/addons/info#options-and-defaults
{
/**
* Exclude Components from being shown in Prop Tables section
* Accepts an array of component classes or functions
* @default []
*/
propTablesExclude: Array<React.ComponentType>,
}
However it does not seem to work and I am getting Prop Tables even for excluded components.
Steps to reproduce
Here is small sample code to test propTablesExclude
:
// @flow
import React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
/* eslint-disable react/no-unused-prop-types,react/require-default-props */
type PropsType = {
label: string,
onClick?: Function,
disabled?: boolean,
};
const Button = ({ label, onClick, disabled }: PropsType) => (
<button onClick={onClick} disabled={disabled}>
{label}
</button>
);
Button.defaultProps = {
disabled: false,
onClick: () => {},
};
storiesOf('Test', module).add(
'Exclude component from prop tables',
withInfo({
text: 'This can exclude extraneous components from being displayed in prop tables.',
propTablesExclude: [Button],
})(() => (
<div>
<Button label="Button" />
</div>
))
);
Here is screenshot of Prop Tables for Button being not excluded:
Please specify which version of Storybook and optionally any affected addons that you’re running
"@storybook/addon-info": "4.0.0-alpha.9",
"@storybook/react": "4.0.0-alpha.9",
Where to start
My humble guess is that something goes wrong somewhere here: https://github.com/storybooks/storybook/blob/master/addons/info/src/components/Story.js#L314-L324
if (
typeof children === 'string' ||
typeof children.type === 'string' ||
(Array.isArray(this.props.propTablesExclude) && // also ignore excluded types
~this.props.propTablesExclude.indexOf(children.type)) // eslint-disable-line no-bitwise
) {
return;
}
if (children.type && !types.has(children.type)) {
types.set(children.type, true);
}
When I have changed this code a bit into something like this:
if (
typeof children === 'string' ||
typeof children.type === 'string' ||
~this.props.propTablesExclude.toString().indexOf(children.type) // eslint-disable-line no-bitwise
) {
return;
} else if (!types.has(children.type)) {
types.set(children.type, true);
}
it seemed to fix the issue. But I am not sure if this is the correct/safe way. It would be cool if someone could investigate this.
Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (10 by maintainers)
Top Results From Across the Web
addon withInfo propTablesExclude does not exclude - - Bountysource
addon withInfo propTablesExclude does not exclude. ... I am trying to exclude components from being shown in Prop Tables section like mentioned herer:...
Read more >Storybook Info Addon
Storybook Info Addon will show additional information for your stories in Storybook. ... Then, add withInfo as a decorator to your book of...
Read more >Storybook Info Addon - npm
Storybook Info Addon will show additional information for your stories ... this components propTablesExclude: [], // Exclude Components from ...
Read more >@nlabs/storybook-addon-info NPM | npm.io
Storybook Info Addon will show additional information for your stories in Storybook. ... displays Prop Tables with this components propTablesExclude: [] ...
Read more >storybook-addon-prettier-source - npm package - Snyk
Learn more about storybook-addon-prettier-source: package health score, ... context) => withInfo({ source: false, propTablesExclude: [PrettierSource] })( ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Still not working as of v5.0.5.
As above, same issue. propTablesExclude does not work. Also using TypeScript.