-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[addon-docs] DocGen description are not displayed with StyledComponent #8279
Comments
I think this is related to storybookjs/babel-plugin-react-docgen#74. Can we get some feedback on that PR? |
In 5.2.4 I see the props from styled components in some components, not in all. Idk if it's my fault or not but I have all components styled and with stories in the same way. Can you confirm this issue is resolved on 5.2.4? Thanks. |
@KoshiroKun since there are no comments on the issue and no PRs that reference it, it means that the issue is still active (unfixed) as far as I know. |
Hi @shilman I am having this issue as well but in my case, it seems to happen when I am deconstructing the rest of the props in my component. For example:
when I remove |
@michaelcitro thanks for the info. i'm making a bunch of repros now for all of the issues raised in #8435 (umbrella issue, that includes this one) and then will go through & diagnose. appreciate your patience! |
Repro: eaa147a |
Not sure if this adds much - but I am able to show the docGen if I create a React functional component that returns the Styled Component. But it means wrapping all the styled components that way... import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';
const Anchor = styled.a`
color: ${props => props.color};
text-decoration: none;
`;
/** Now this would `work` but it's not the best approach */
const NewAnchor = (props) => <Anchor {...props}/>
NewAnchor.propTypes = {
/** Show me your color */
color: PropTypes.string
}
NewAnchor.defaultProps = { color: teal };
export default NewAnchor; All storybook versions are |
I personally don't like to change my Components so that they can work with Storybook. It's like changing code for making tests pass... |
@testacode that's why it's a workaround, not a proper fix |
@shilman to confirm - the issue here is in |
Yeah, this particular codepath (react PropTypes) gets handled by |
I'm pretty sure this is because of reactjs/react-docgen#256 There is a custom resolver https://github.com/jquense/react-docgen-styled-resolver But this only picks up use of jquense/react-docgen-styled-resolver#1 We encountered issues with the workaround mentioned above in govuk-react/govuk-react#527. Unfortunately it was a few years ago so can't remember the specifics. We resolved this by exporting the I would love a real fix for this :D |
@shilman any thoughts on this? Perhaps allowing Storybook's docgen to be configured with a custom resolver would help for some people? |
Chiming in - from the issue linked by the Storybook docs itself (see here), in this comment, @Winner95 explains he made another resolver Typescript-react-function-component-props-handler that even has an example running with the beta of Storybook 6. |
Unfortunately for our use case, we're not "generating props" but need something that pulls out the docgen comment from TypeScript for inclusion in storybook. I switched our project over to using TypeScript this morning (still using prop types for now) and noticed none of the docgen comments were appearing so had to switch to using this config in .storybook/main.js typescript: {
reactDocgen: 'react-docgen',
} It's good to see that it's possible to use a custom docgen resolver with Storybook, but from what I can see, the solution is to put this in .storybook/main.js: webpackFinal: async config => {
const reactDocgen = [
"babel-plugin-react-docgen",
{
DOC_GEN_COLLECTION_NAME: "STORYBOOK_REACT_CLASSES",
// custom handlers should go before the default ones
preHandlers: ["typescript-react-function-component-props-handler"]
}
];
config.module.rules[3].oneOf[1].options.plugins.push(reactDocgen);
return config;
} I expect this would be fairly fragile as-is so would be good to have a direct option for a custom resolver from the Storybook config, if that's seen as a possible way forwards. |
@penx we currently recommend |
@shilman Now do we have stylized way to configure react-docgen with a custom resolver? |
Describe the bug
Description related to the component or to the props are not displayed when component is based on StyledComponent.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Should display description as expected
Screenshots
Code snippets
System:
System:
OS: macOS Mojave 10.14.6
CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
Binaries:
Node: 12.4.0 - /usr/local/bin/node
Yarn: 1.17.0 - /usr/local/bin/yarn
npm: 6.11.3 - /usr/local/bin/npm
Browsers:
Chrome: 77.0.3865.90
Safari: 13.0.1
npmPackages:
@storybook/addon-actions: ^5.2.1 => 5.2.1
@storybook/addon-docs: ^5.3.0-alpha.6 => 5.3.0-alpha.6
@storybook/addon-info: ^5.2.1 => 5.2.1
@storybook/addon-knobs: ^5.2.1 => 5.2.1
@storybook/addon-links: ^5.2.1 => 5.2.1
@storybook/addon-storysource: ^5.2.1 => 5.2.1
@storybook/addons: ^5.2.1 => 5.2.1
@storybook/react: ^5.2.1 => 5.2.1
Additional context
Nothing special
The text was updated successfully, but these errors were encountered: