Skip to content
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

Fix semi broken __docgenInfo integration in addon info #1030

Merged
merged 16 commits into from
May 19, 2017
Merged
12 changes: 11 additions & 1 deletion addons/info/src/components/PropTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,23 @@ export default class PropTable extends React.Component {
continue;
}
const typeInfo = type.propTypes[property];
const propType = PropTypesMap.get(typeInfo) || 'other';
let propType = PropTypesMap.get(typeInfo) || 'other';
const required = typeInfo.isRequired === undefined ? 'yes' : 'no';
const description = type.__docgenInfo &&
type.__docgenInfo.props &&
type.__docgenInfo.props[property]
? type.__docgenInfo.props[property].description
: null;
if (propType === 'other') {
if (
type.__docgenInfo &&
type.__docgenInfo.props &&
type.__docgenInfo.props[property] &&
type.__docgenInfo.props[property].type
) {
propType = type.__docgenInfo.props[property].type.name;
}
}
props[property] = { property, propType, required, description };
}
}
Expand Down
22 changes: 20 additions & 2 deletions addons/info/src/components/Story.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default class Story extends React.Component {
<div style={this.state.stylesheet.infoPage}>
<div style={this.state.stylesheet.infoBody}>
{this._getInfoContent()}
{this._getComponentDescription()}
{this._getSourceCode()}
{this._getPropTables()}
</div>
Expand Down Expand Up @@ -162,6 +163,7 @@ export default class Story extends React.Component {
<div style={this.state.stylesheet.infoBody}>
{this._getInfoHeader()}
{this._getInfoContent()}
{this._getComponentDescription()}
{this._getSourceCode()}
{this._getPropTables()}
</div>
Expand Down Expand Up @@ -214,6 +216,24 @@ export default class Story extends React.Component {
);
}

_getComponentDescription() {
let retDiv = null;

if (Object.keys(STORYBOOK_REACT_CLASSES).length) {
Object.keys(STORYBOOK_REACT_CLASSES).forEach((key, index) => {
if (STORYBOOK_REACT_CLASSES[key].name === this.props.context.kind) {
retDiv = (
<div>
{STORYBOOK_REACT_CLASSES[key].docgenInfo.description}
</div>
);
}
});
}

return retDiv;
}

_getSourceCode() {
if (!this.props.showSource) {
return null;
Expand Down Expand Up @@ -298,8 +318,6 @@ export default class Story extends React.Component {
{propTables}
</div>
);

return;
}

render() {
Expand Down