Experiment: automatic prop documentation #762
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

I've been experimenting a little with the idea of automatically generating docs from our components'
propTypes. This PR is currently pretty hacky and dirty, but it demonstrates a proof of concept.Result
I'll start from the endpoint: here is the props documentation for
SideNav, which has been automatically generated and displayed with aComponentPropscomponent dropped into the associated.mdxfile.As you can see, the props documentation contains the props for the component as well as the props made available due to the component "inheriting" from other components. Also, the system props section has been generated by walking the inheritance tree and collecting all the system props made available to each component in the tree.
The markdown used to display this is currently:
Generating the props data
In order to generate this content, the components'
propTypesdeclaration needs to be a little smarter about the props themselves. As an example, here's the JavaScript used to generate thepropTypesforSideNav:(I'm not a huge fan of this syntax, but it works for now.)
The system works with all the validators provided by the
prop-typespackage, and can also work with custom validators (such as our ownelementType). It also works withisRequired, as well as providing its owndesc()for setting the prop description andhiddento hide the prop from the documentation entirely.What's next
This was an experiment to scratch my own itch; it's pretty hacky and could use a lot of work. However, I wanted to share it to get my thoughts down somewhere and see if the idea caught anyone else's fancy.