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

Conversation

bigassdragon
Copy link

Issue:
I'd like to see the component description from __docgenInfo in the story documentation in the info plugin.
I'd like to get the prop type from __docgenInfo for when the type comes back as "other".
PropVal had a problem where 'content' was being directly rendered as an object.

What I did

added to PropTable
added to PropVal
added to Story

How to test

Make a story with a component that has documented (via docgen-style text) description, and the description will show up.

Like this:

/** Component description here */
const Button = ({children, onClick}) => (
  <button onClick={onClick}>{children}</button>
)
Button.propTypes = {
  onClick: PropTypes.func // make sure this does not come from React, make it come from prop-types module.
}

storiesOf('Button', module)
  .addWithInfo('demo', 'Button with children', () => (
    <Button onClick={action('clicked')}>David</Button>
  ))
 .addWithInfo('demo', '', () => (
    <Button onClick={action('clicked')}>David</Button>
  ))

You will see a description under the info description, you will also see that the prop type is not 'other' when you use PropTypes from something other than React (for support of React >= 15.5.x.

Nelson, Joe added 5 commits May 10, 2017 12:52
…omponent, fixed issue with `content` was being rendered as an object and give errors for that, added a fix to when you use `PropTypes` from something other than `React` that you can get the type from docgen.
Copy link
Member

@ndelangen ndelangen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this PR!

_getComponentDescription() {
let retDiv = null;

if (Object.keys(window.STORYBOOK_REACT_CLASSES).length) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the usage of window here, and why this is necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ndelangen my linter gave syntax errors because it did not know where STORYBOOK_REACT_CLASSES came from. I understand that STORYBOOK_REACT_CLASSES is a global variable and that should work without the need of window at all. Sorry for any confusion I really only added it to get rid of the errors from my linter. I would be more than willing to do a commit that removes the need for window.

@danielduan
Copy link
Member

danielduan commented May 18, 2017

Hey @bigassdragon, I was actually going to open a PR to add these features as well. Thanks for doing this.

You should probably run your code through the project's eslint config and rebase off the latest master. A lot of lines in your changes are stylistic but it doesn't match the convention used across the project. That's why one of the bitHound tests is failing. I'd love to see this merged soon, let me know if you need help.

@bigassdragon
Copy link
Author

@danielduan Thank you for your comment, I was a little confused. I ran it through eslint using the config inside of storybook and committed the code that I modified.

@danielduan
Copy link
Member

@bigassdragon you still need to do a rebase unfortunately. there are conflicts which means that there have been changes to the files since you last edited them so your changes can't be automatically merged.

@bigassdragon
Copy link
Author

@danielduan I have rebased now and committed.

package.json Outdated
@@ -28,6 +28,7 @@
},
"scripts": {
"bootstrap": "lerna bootstrap",
"postinstall": "lerna bootstrap --hoist",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because a few reason we don't do this, and instead bootstrap manually.

  1. For some CI tasks bootstrapping is unnecessary, but installing is. Bootstrapping is rather slow.
  2. We do npm install in examples, this will cause the postinstall to re-run, causing a lot of unnecessary delay.
  3. When adding a root dependency for development, bootstrapping is not needed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this postinstall hook?

package.json Outdated
@@ -28,7 +28,6 @@
},
"scripts": {
"bootstrap": "lerna bootstrap",
"postinstall": "lerna bootstrap --hoist",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah never mind then

package.json Outdated
@@ -1,6 +1,5 @@
{
"name": "storybook",
"version": "1.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused 🙄

import Node from './Node';
import { baseFonts } from './theme';
import { Pre } from './markdown';
import PropTypes from 'prop-types'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, you linted everything right, and I made you revert it... Luckely linting will soon be fixed! #1000

@ndelangen ndelangen merged commit c777084 into storybookjs:master May 19, 2017
@ndelangen
Copy link
Member

Hey @bigassdragon,

Thanks you so much, quite a lot of work you did here, I'll be releasing a new alpha, I really hope you can help test this?

🏅

@bigassdragon
Copy link
Author

Hey @ndelangen,

You are very welcome, sorry for taking so long.

I would be more than happy to test it once it is available.

I hope to make more PR's in the future, I really like what you guys are doing here.

Thanks

@danielduan
Copy link
Member

Hey @bigassdragon, thanks for this. Might need your help updating the addon-info README as well. I personally haven't been able to get the __docgenInfo on the components so I'd love to see what you're doing to the .babelrc and other configs to get it running. Thanks again!

@bigassdragon
Copy link
Author

Hey @danielduan I am not actually doing anything special to get __docgenInfo running on my side at all.

I did however add window.STORYBOOK_REACT_CLASSES = {} to my storybook config.js. I do not use a .babelrc file at all, I put my babel inside of my package.json. It looks like this:
"babel": {
"presets": [
"latest",
"react",
"stage-2"
],
"ignore": [
"stories.js",
"**/story.js"
]
}

@ndelangen
Copy link
Member

It's published!

@bigassdragon
Copy link
Author

@ndelangen awesome thank you very much!

@bigassdragon
Copy link
Author

@ndelangen I am unable to download the new version. Maybe I am doing something wrong.

I tried this npm install --save-dev @kadira/storybook@3.0.0-alpha.1 <--- is that not correct?

@ndelangen
Copy link
Member

Yeah that's incorrect, package name is @storybook/react

@ndelangen
Copy link
Member

Did it work for you @bigassdragon ?

@ndelangen ndelangen changed the title Added component description from __docgenInfo, Added the ability to get the PropType from __docgenInfo for prop table, Fixed an issue with PropVal rendering an object Add better __docgenInfo integration in addon info May 27, 2017
@ndelangen ndelangen added the bug label May 27, 2017
@ndelangen ndelangen changed the title Add better __docgenInfo integration in addon info Fix half-working __docgenInfo integration in addon info May 27, 2017
@ndelangen ndelangen changed the title Fix half-working __docgenInfo integration in addon info Fix semi broken __docgenInfo integration in addon info May 27, 2017
@bigassdragon
Copy link
Author

Hey @ndelangen,

I have been busy with personal life and work, so I have not had time to try everything out yet sorry.

I will make some time to try it all out today.

Thanks for the reminder.

@bigassdragon
Copy link
Author

Hey @ndelangen,

I double checked everything, and it looks like everything is a drop in fix for it.

I am able to use all the docgen information without any issues.

Thanks again for taking this PR.

@shilman
Copy link
Member

shilman commented May 30, 2017

Yay! Thanks for your contribution @bigassdragon 🙇

BTW any thoughts on #1147?

@bigassdragon
Copy link
Author

Hey @shilman,

Would that be a new addon?

@konsumer
Copy link
Contributor

konsumer commented Aug 29, 2017

Does this still work? I worked on this with @bigassdragon when he originally fixed it, but I can't seem to get it to work in my current project using these versions:

    "@storybook/addon-info": "^3.2.9",
    "@storybook/addon-options": "^3.2.6",
    "@storybook/react": "^3.2.8",

I added this to config.js:

window.STORYBOOK_REACT_CLASSES = {}

and have comments like this:

MyComponent.propTypes = {
  /**
   *  number of stars to display full
   */
  stars: PropTypes.number,

  /** color to use for fill and stroke */
  color: PropTypes.string
}

In my stories, Component.__docgenInfo is still undefined.

@konsumer
Copy link
Contributor

konsumer commented Aug 29, 2017

I tried with both methods to add info, and .__docgenInfo is undefined in both.

I did this in my config.js:

import { configure, setAddon } from '@storybook/react'
import infoAddon from '@storybook/addon-info'

setAddon(infoAddon)

window.STORYBOOK_REACT_CLASSES = {}

function loadStories () {
  require('../src/stories')
}

configure(loadStories, module)

and made stories that looked like this:

import React from 'react'

import { storiesOf } from '@storybook/react'
import { withInfo } from '@storybook/addon-info'

import Docs from './Docs'

storiesOf('Docs', module)
  .add('withInfo', withInfo('Heading here')(() => (<Docs name='David' />)))
  .addWithInfo('addWithInfo', 'Heading here', () => (<Docs name='David' />))

and Docs.js looks like this:

import React from 'react'
import PropTypes from 'prop-types'

/** A dumb component that says "hello" */
export const Docs = ({name}) => (<div>Hello {name}</div>)

Docs.propTypes = {
  /** the name of the person to say "hello" to */
  name: PropTypes.string
}

Docs.defaultProps = {
  name: 'World'
}

export default Docs

I tried class Docs extends React.Component style, too.

Still no "description" field in either story:
screen shot 2017-08-28 at 5 37 06 pm

screen shot 2017-08-28 at 5 41 47 pm

steps to reproduce:

npm i -g create-react-app @storybook/cli
create-react-app demo
cd demo
getstorybook

Then I made changes, above.

@ndelangen
Copy link
Member

@konsumer Can you open a new issue?

@konsumer
Copy link
Contributor

@ndelangen Yep, no prob. #1762

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants