Closed nicholaai closed 6 years ago
I've made a bit of progress in addressing this issue.
Expanded my webpack config to exclude the stories and filter out props (copy-paste indent sucks, sorry)
{
loader: 'react-docgen-typescript-loader',
options: {
skipPropsWithoutDoc: false,
excludes: ["\\.stories.tsx$"],
propFilter: function(prop) {
if (prop.parent == null) {
return true;
}
return prop.parent.fileName.indexOf('node_modules/@types/react') < 0;
}
}
}
Within loader.js
I experimented with hardcoding in my component displayName after running the parse function
var componentDocs = parser.parse(this.resourcePath);
if (componentDocs[0]) {
componentDocs[0].displayName = 'Box';
}
This resulted in the Box props being rendered along with being added to window.STORYBOOK_REACT_CLASS
So, it seems like there is an issue with var parser_js_1 = require("react-docgen-typescript/lib/parser.js");
and displayNames. Any thoughts on that?
Found an associated issue https://github.com/styleguidist/react-docgen-typescript/issues/82
switched from
const Box = styled.div<IBox>`
${color}
${fontSize}
${p => p.css}
${space}
${width}
`;
Box.displayName = 'Box';
export default Box;
to
export const Box = styled.div<IBox>`
${color}
${fontSize}
${p => p.css}
${space}
${width}
`;
Box.displayName = 'Box';
And i got it working. That seems to be a workaround. PR https://github.com/styleguidist/react-docgen-typescript/pull/87 was supposed to fix this
"ogic, essentially, is if displayName is extracted from stateless or functional component, then use that. otherwise fall back to previous logic without changes."
which leads me to believe it should work (maybe i'm wrong?). i think perhaps styled-components is causing the issue here.
Hello,
Thanks for the detailed report. I won’t be able to dig in until Sunday, possibly Saturday due to some current obligations.
You might want to try disabling the loader option to set display names automatically.
The styled component display names I think may be actually “styled(Box)”. I will need to look into that.
So setting an explicit display name to the component in code may work with that option disabled.
The info addon I think tries to match the display name to the story name.
Hi guys, I'm having an issue getting PropTypes to render.
I'm using Styled Components - TypeScript - Storybook - Storybook info add-on - react-docgen-typescript-loader.
I Have done a good amount of googling, but I haven't been able to fix my issue. I've dug into my node_modules file for
react-docgen-typescript-loader
and here's what i've found.Here's my code (Please excuse copy/paste formatting)
(.storybook and src is in root)
./storybook/decorators/webpack.config.js
./storybook/decorators/CenterDecorator.tsx
src/Box/Box.tsx
Using my Box component in a story like so
Placing a console log in
loader.js
in my node_modulesGives me the following for
componentDocs
forBox
:(note: displayName is set to 'StyledComponentClass' and not 'Box'. My interface props are defined at the end of the object)
Using .addDecorator(CenterDecorator) like so:
Results in
CenterDecorator
being added towindow.STORYBOOK_REACT_CLASS
. None of the components show up in the object, onlyCenterDecorator
I placed a console.log
If I remove the
.addDecorator(CenterDecorator)
from the code above, then the CenterDecorator is no longer appears inwindow.STORYBOOK_REACT_CLASS
Also, none of the other component docs are anywhere to be found.
Not having an issue with the other info pieces like Story Source rendering.
Any idea what I'm doing wrong here? Thank you