storybook: addon-info doesn't show Proptypes and description
Addon-info doesn’t show Proptypes and description
Hi, I have problem with addon-info when I use my component as an external package. There is no problem when I copy the component source into my storybook project, but when call it from node module the PropType and description does not show
My Component source code :
import React from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import BreadcrumbStyled from './style/BreadcrumbStyled';
import OlStyled from './style/OlStyled';
import LiStyled from './style/LiStyled';
class Breadcrumb extends React.Component {
render() {
const {
items, primary, secondary, info, success, danger, warning, rtl
} = this.props;
const elements = [];
for (let i = 0; i < items.length - 1; i += 1) {
elements.push(items[i]);
}
const lastElement = items[items.length - 1];
const themeProps = {
primary, secondary, info, success, danger, warning, rtl
};
return (
<BreadcrumbStyled {...this.props}>
<OlStyled {...themeProps}>
{elements.map((item, index) => {
return (
<LiStyled
key={index}
{...themeProps}
>
<Link
to={item.path
}>
{item.name}
</Link>
</LiStyled>
);
})}
<LiStyled {...themeProps}>{lastElement.name}</LiStyled>
</OlStyled>
</BreadcrumbStyled>
);
}
}
Breadcrumb.propTypes = {
/** array of objects */
items: PropTypes.array.isRequired,
/** rtl is true component show in right side of the window, default is false (from left side). */
rtl: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.primary color */
primary: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.secondary color */
secondary: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.info color */
info: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.warning color */
warning: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.danger color */
danger: PropTypes.bool,
/** Boolean indicating whether the component renders with Theme.success color */
success: PropTypes.bool,
/** The inline-styles for the root element. */
style: PropTypes.object,
/** The className for the root element. */
className: PropTypes.string,
/** The color renders with Theme.foreColor . */
foreColor: PropTypes.string
};
Breadcrumb.defaultProps = {
rtl: false,
primary: false,
secondary: false,
info: false,
warning: false,
danger: false,
success: false,
style: {},
className: '',
foreColor: ''
};
export default Breadcrumb;
I tried both compiling and installing from npm and linking to source code in github, there was no different.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 13
- Comments: 47 (9 by maintainers)
It started working properly for me when I installed:
I fixed this by ‘extending’ the
PropTable
component from storybook/addon-info.Then override the TableComponent in storybook/config.js
I had a similar issue: propTypes and descriptions appear if I use a functional component, but doesn’t work if I use a class component (only properties names are displayed).
I had trouble with getting this to work while using Typescript 😃 Even though it is fairly easy to use Typescript with storybook it seams to break addon-info’s propTypes and description. However, defaultProps and property still works 😃
It still does not work for me with docgen @niecnasowa
Still had this issue even with the latest versions (see list below). @niecnasowa’s solution worked for me - I simply added
babel-plugin-react-docgen (add to .babelrc "plugins": ["react-docgen"])
without having to addreact-docgen
Package Version info:
Code example that was failing:
It still does not work for me with docgen
I’m facing this problem too!
Hi, I’m seeing a similar issue, and I’ve narrowed it down to a case where I have multiple exports
Given this:
The description will not show up for
randomProp
. HOWEVER, if I comment out the last line, as such:Then the description for
randomProp
will show up. This is even if my Story does not importTest2
at all.I don’t know if there are other situations where descriptions won’t show up, but the scenario I described above is definitely reproducible.
Incidentally, a use case for my code having a default export as well as other exports is to have a Redux-connected component as well as its unconnected component available for testing.
op’s example is added to https://github.com/storybooks/babel-plugin-react-docgen/pull/54 and fixed
We do not support multiple exports within the same file with Info documentation at the moment. It’s a limitation with our babel plugin and the way
react-docgen
works.https://github.com/storybooks/babel-plugin-react-docgen/pull/46
Another curious case.
Docgen works for this:
But this doesn’t:
Of course, in the storybook, I’m using
import Test from 'Test';
in the first scenario andimport { Test } from 'Test';
in the second.@kgwebsites That didn’t solve my problem
In my case the issue is only for stateless functional components defined as a regular function declaration, example…
The issue has to do with babel-plugin-react-docgen. I created a PR in the babel-plugin-react-docgen repo to address my issue in particular… https://github.com/storybooks/babel-plugin-react-docgen/pull/41/files