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

Documentation based on propTypes #25

Open
pekala opened this issue Jul 6, 2015 · 6 comments
Open

Documentation based on propTypes #25

pekala opened this issue Jul 6, 2015 · 6 comments

Comments

@pekala
Copy link
Contributor

pekala commented Jul 6, 2015

It would be nice to display auto-generated component API documentation based on the propTypes and optional comments. I have a partial implementation of this using https://github.com/reactjs/react-docgen and their markdown example. I can prepare a pull request if you think this is a good idea.

@ovidiuch
Copy link
Owner

ovidiuch commented Jul 7, 2015

Cool. I think this is in line with the project mission, since good interfaces play a bit role in componitization.

But before rushing into a PR, let's talk about the implementation a bit. E.g. where in the code will you extract the info and where would it be the best way to display it in the UI.

PS. I did a small UI refresh to the header+buttons yesterday, get the latest and see if it's sharper than before :-)

@pekala
Copy link
Contributor Author

pekala commented Jul 8, 2015

In my sketch implementation I had a separate script that I ran before playground that generated Markdown files next to components. Then in cosmos I would load these md files with a markdown-loader, pass the markup for each component to component-playground and render it in a container (a copy of the editor container).
But this is not the optimal way to do it. I suppose the docs generation should done be runtime by cosmos (so that when you update comments/propTypes the docs hot-reload) and without creating actual docs files. It would be really cool, although maybe too far fetched, to have the docs and editor somehow integrated, so that when you edit props you know what are the valid values. Another option is to just display the docs in another sidebar in the playground.

@ovidiuch
Copy link
Owner

ovidiuch commented Jul 8, 2015

I think it should be another panel, hidden by default, with a discrete button somewhere.

A bit offtopic, but you could also generate random fixtures from propTypes, akin to factories. That would be pretty cool as well as I'm sure writing fixtures is a drag for people who discover Cosmos.

@pekala
Copy link
Contributor Author

pekala commented Jul 9, 2015

We could integrate something like https://github.com/marak/Faker.js/ to generate these fixtures. Based on comment annotation, property type and property name we could make an educated guess on what makes sense to put in there. What do you think?

@pekala
Copy link
Contributor Author

pekala commented Jul 9, 2015

For example, we could set a convention that if you annotate your propTypes like this:

propTypes: {
    /**
     * Description of prop "color".
     * faker:internet.color
     */
    color: React.PropTypes.string,
    /**
     * Description of prop "desc"
     * faker:lorem.sentence
     */
    desc: React.PropTypes.string
},

you get a nice random fixture every time.

@ovidiuch
Copy link
Owner

For example, we could set a convention that if you annotate your propTypes like this:

Cool idea!

Faker looks pretty powerful.

We could add a 2nd executable like node_modules/.bin/generate-fixtures in Cosmos. It would be nice to have the faker: annotation optional, and be able to use some Faker generics based on prop type.

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

No branches or pull requests

2 participants