1

I'd like to reuse a common set of PropTypes across several components. Something like:

const textProps = {
  /** Header text */
  children: PropTypes.node.isRequired,
  /** Weight of the text */
  weight: PropTypes.oneOf(['thin', 'normal', 'semibold', 'bold']),
}

I've added this object to a file and am exporting it as a named export textProps.

I then import it into a component file as:

import { textProps } from 'path/to/textProps'

And the component file uses styled-components to define a component:

const H1 = styled.h1`
  font-size: "50px"
`;

H1.propTypes = textProps;

The problem is the 'Props & Methods' section isn't displayed in the Styleguidist guide when textProps is imported.

When I define textProps within the H1 file it works as expected.

Is there a way to define a common set of PropTypes, import them into a component, and have them appear in the Styleguidist guide?

Brett DeWoody
  • 59,771
  • 29
  • 135
  • 184
  • @Theo - I did try spreading `textProps` but that also didn't work. I'm now looking at this related issue on `react-docgen` - https://github.com/reactjs/react-docgen/issues/33 – Brett DeWoody Mar 28 '18 at 16:46
  • The react-docgen issue, you've linked, has a possible solution. Maybe someone can test and finish and, I've created an issue for that: https://github.com/styleguidist/react-styleguidist/issues/917 – Artem Sapegin Apr 02 '18 at 07:37

0 Answers0