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.

Set react-docgen resolver to support styled-components

See original GitHub issue

Currently, the PropsTable component does not recognize components made with styled-components. react-styleguidist has the option to set a custom react-docgen resolver to fix this, as shown here: https://github.com/styled-components/styled-components/issues/945 Could we have something similar here? Or even better, to support styled-components by default?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
ilyanoskovcommented, Aug 7, 2018

@Emilios1995 you should not add babel-plugin-react-docgen as it’s already in Docz. I am using react-emotion styled-components and was able to get PropTypes descriptions by doing this:

const StyledBadge = styled('div')`
  ${baseStyles};
  ${colorStyles};
  ${circleStyles};
`;

/* Adding this line makes react-docgen work for styled-components */
const Badge = props => <StyledBadge {...props} />;

Badge.propTypes = {
  /**
   * Callback for the click event.
   */
  onClick: PropTypes.func,
  /**
   * Ensures text is centered and the badge looks like a circle.
   */
  circle: PropTypes.bool,
  color: PropTypes.oneOf(values(colorNames))
};

this seems like a simple workaround, maybe @pedronauck can close this issue.

P.S. is there a way to integrate this solution directly into Docz ? or may be we add custom resolvers to react-docgen setting in Docz?

This way nobody will have to type extra things, but also enabling styled-components support 😉

3reactions
lucasconstantinocommented, Jun 11, 2019

@ilyanoskov @antoniojps this is not really an option: doing so will break any styled-component functionality, as none of the properties from the styled-components will be available in the new wrapping component.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-docgen-styled-component-resolver - npm
Start using react-docgen-styled-component-resolver in your project by ... const docgen = require('react-docgen'); const styledResolver ...
Read more >
Automating React Documentation using React-Docgen ⚙️
It's a CLI and API that reads your React component files, grabs any documentation left in comments, and pumps out an object with...
Read more >
Documenting components - React Styleguidist
Styleguidist generates documentation for your components based on the comments in your source code, propTypes declarations, and Readme files.
Read more >
Tooling - styled-components
This option enhances the attached CSS class name on each component with richer output to help identify your components in the DOM without...
Read more >
reactjs - Setup react-styleguidist, Create React App, Typescript ...
ReactExample /ReactExample ; js Module ; found: Can ; resolve 'rsg-components/Wrapper ; ' in '/Users ...
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