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-docs: Exclude defaultProps from source

See original GitHub issue

It would be great if (if not already available) there was an option to exclude defaultProps from the source output.

Button.tsx

...
Button.defaultProps = {
  disabled: false,
  type: "button",
  block: false,
};
...

Button.stories.mdx

...
<Preview>
  <Story name="button-variant-secondary">
    <Button variant="secondary">Secondary</Button>
  </Story>
</Preview>
...

current behavior of addon-docs source code

<Button
  block={false}
  disabled={false}
  type="button"
  variant="secondary"
>
  Secondary
</Button>

desired behavior

<Button
  variant="secondary"
>
  Secondary
</Button>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
zeckdudecommented, Nov 1, 2020

@shilman @Lueton This is actually possible in Storybook 6.0. As you can see in jsxDecorator.tsx, it is using the reactElementToString method from the react-element-to-jsx-string package. If you check their options, they accept a showDefaultProps property, which when set to false omits the default props in the JSX.

In my opinion, I feel like storybook should have the showDefaultProps option set to false by default and then let the individual components or stories change it when they want it to show. Thoughts on that @shilman?

For now though, you can just use the parameters.jsx object which gets passed to the reactElementToString method and therefore stops the default props from showing.

Note: This is the CSF style

export default {
  title: 'Example/Container',
  component: Container,
  parameters: {
    jsx: {
      showDefaultProps: false
    },
  }
};
1reaction
shilmancommented, Nov 4, 2020

Ta-da!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-beta.2 containing PR #13003 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there’s still more to do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

storybook-addon-react-docgen
FC is the quickest way to ramp up the complexity of your components. Once you use that you lose the defaultProps experience. Using...
Read more >
Storybook Docs with mdx support and addon knobs - Medium
I can remove .storybook/addons.js and .storybook/config.js ... name: '@storybook/addon-docs', // new addon for docs options: {
Read more >
@storybook/source-loader | Yarn - Package Manager
Addon-docs : Hide React default props in source block (#13003); Addon-docs: Angular empty string now infers to "string" instead of "void" (#12994) ...
Read more >
Storybook Addon-Docs don´t show Code Snipped
I found it through help from the Storybook Github Page. In preset.js the line sourceLoaderOptions: null, kills the loading of the ...
Read more >
@storybook/addon-docs 6.1.0-beta.2 on Node.js NPM
Bug Fixes. Addon-docs: Hide React default props in source block (#13003); Addon-docs: Angular empty string now infers to "string" instead of "void" (#12994) ......
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