Closed
Conversation
|
This pull request is being automatically deployed with ZEIT Now (learn more). |
Contributor
|
Excited about this 😸 |
8105b3e to
60ac392
Compare
Contributor
Author
|
Changed up the syntax slightly to make it more similar to creating regular SideNav.propTypes = PropTypes.doc({
system: [COMMON],
inherited: [BorderBox],
own: {
as: elementType.desc('Sets the HTML tag for the element'),
bordered: PropTypes.bool.desc('Renders the component with a border'),
children: PropTypes.node.hidden,
theme: PropTypes.object.hidden,
variant: PropTypes.oneOf(['normal', 'lightweight']).desc(
'Set to `lightweight` to render [in a lightweight style](#lightweight-variant)'style](#lightweight-variant)'
)
}
}) |
Contributor
Author
|
Going to close this for now since it's getting pretty stale! We might want to take another look at this approach when the TS migration is done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.