Addon-docs: Exclude defaultProps from source
See original GitHub issueIt 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:
- Created 3 years ago
- Reactions:2
- Comments:15 (13 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
@shilman @Lueton This is actually possible in Storybook 6.0. As you can see in
jsxDecorator.tsx
, it is using thereactElementToString
method from the react-element-to-jsx-string package. If you check their options, they accept ashowDefaultProps
property, which when set tofalse
omits the default props in the JSX.In my opinion, I feel like storybook should have the
showDefaultProps
option set tofalse
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 thereactElementToString
method and therefore stops the default props from showing.Note: This is the CSF style
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!Closing this issue. Please re-open if you think there’s still more to do.