-
Notifications
You must be signed in to change notification settings - Fork 2k
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
DevDocs: Auto Proptype Documentation for Components and Blocks #9289
Conversation
706105e
to
aeaaf46
Compare
a62d84f
to
0da96fa
Compare
0da96fa
to
b0e1d7a
Compare
Adding a design concept from @adambbecker that could be useful to you: |
Also, cc @MichaelArestad for some of the playground work that seems relevant to this as well. |
I did a quick test, and I agree we need some more complete design input here. As a first test, my feedback would be:
With the above, I think we'd have laid the foundations of a great playground functionality. :D |
Thanks! This is great feedback! |
Closing as a proof of concept |
Auto Proptype Documentation for Components and Blocks
Props are the way we configure child components. As a developer, it can be confusing sometimes as to what a simple change to a prop can do. It can change behavior and appearance. Wouldn't it be nice to tinker with the example in the Dev Docs?
Well, now you can.
Overview and Approach
In order to get prop types, the code has to be read, as there's no reliable way I could discover to read propTypes while the code is running. I used
react-docgen
to parse the component's source and figure out the propTypes. From there, I could have used a webpack loader or read it on the nodejs server. I chose to avoid the webpack loader for fear that I could have increased a production bundle size in some way. If my thinking is wrong in this, please let me know. ;)Once having the propTypes in the client, it's fairly straightforward to render a table. There's some internal bookkeeping and two copies of the props being passed about. The flow goes something like:
One copy is used for rendering the table, and is the raw form the user is editing along with metadata, the other, is passed to the "component under props" -- for lack of a better term -- called
computedProps
.computedProps
have been parsed and are sent to the child component.Currently, the example component must be modified to pass props it receives onto its children, and is responsible for wiring up global state, if needed. The prop is called
isShowingOff
, which seems like an apt name for a prop which makes the component show off everything it is capable of.The "editor" attempts to detect the presence of this prop, and will show a notification if it isn't present in the example component, alerting the user that their changes may not be propagated.
As a helpful tidbit, it also shows the
import
statement, in order to help developers save some time looking for where the shown component is located.Feel free to check it out: on calypso.live
Currently, the only components able to be edited via the props-editor are:
Still remaining
Alas, there's still a ways to go!