question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addon withInfo propTablesExclude does not exclude

See original GitHub issue

Bug 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: screenshot

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:closed
  • Created 5 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

7reactions
tomhuzecommented, Apr 4, 2019

Still not working as of v5.0.5.

7reactions
nimaiwalshcommented, Mar 12, 2019

As above, same issue. propTablesExclude does not work. Also using TypeScript.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found