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

[docs] Generate default values for docs from the unstyled components #23614

Merged
merged 5 commits into from
Nov 20, 2020

Conversation

mnajdova
Copy link
Member

This PR generates the default values on the docs from the unstyled component if available. Resolves #23308 (comment)

@mui-pr-bot
Copy link

mui-pr-bot commented Nov 19, 2020

Details of bundle changes

Generated by 🚫 dangerJS against e0e5bb5

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Nov 19, 2020
Copy link
Member

@eps1lon eps1lon left a comment

Choose a reason for hiding this comment

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

Looks good. Just some questions about the implementation


Object.keys(unstyledReactAPI.props).forEach((prop) => {
if (unstyledReactAPI.props[prop].defaultValue) {
reactAPI.props[prop] = unstyledReactAPI.props[prop];
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you just add the defaultValue? Sounds confusing if description, types etc. mismatch that we use the prop API from unstyled only if it has a default value.

Copy link
Member Author

Choose a reason for hiding this comment

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

If the prop has a default value, then we have a bunch of checks related to validity like:
Checking JSDOC - JSDOC @default annotation not found for '${propName}'. for example.
That's why I decided to copy all info.

Copy link
Member

@oliviertassinari oliviertassinari Nov 20, 2020

Choose a reason for hiding this comment

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

I had the same question that Sebastian, I came with this rationale: the current logic could help us enforce that unstyled and styled have the same API. If the implement diverges, a developer might open an issue to mention how the documentation is wrong, this could be a signal for us to "realign" the implementation. I don't know if that works in practice but it seems to have potential.

Maybe we could shorten the feedback loop (skip the developer part) by testing for differences in the object and fail if something is wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

My first thouht was that it should look something like this:

reactAPI.props = { ...reactAPI.props, ...unstyledReactAPI.props };

so that the unstyled override and be consistent. The main reason why I didn't just override the main component props definition with unstyled is that sometimes the styled component could add default, that the unstyled didn't have so this seemed wrong. That's why I decided it's probably safer if the unstyled override some props only if it needs to, the only case we know so far is if it has defaults..

Not sure if it is the best way forward, but I think is safest at this moment as we don't know if there will be other use-cases we will find with the next components...

Copy link
Member

Choose a reason for hiding this comment

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

the current logic could help us enforce that unstyled and styled have the same API.

That would not make sense for many APIs. For example, some components have props that are related to styling only. So these props should not propagate to the unstyled version or vice versa.

Same for the description. In the styled version we might want to add more information or even remove information that we handled internally.

In any case, unstyled and styled do not have the same interface. Therefore their documentation will not be equal. We will encounter this once we split more components. Though it's not a problem at the moment.

Copy link
Member

@oliviertassinari oliviertassinari Nov 20, 2020

Choose a reason for hiding this comment

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

We will encounter this once we split more components. Though it's not a problem at the moment.

Agree, it's probably what will happen, I guess our best option it to try the path that leads to the maximum consistency and to diverge anytime it's no longer possible to hold :).

Copy link
Member Author

Choose a reason for hiding this comment

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

Should we then for the moment keep this as is?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, just wanted some clarification whether this "works for now"-code or "correct"-code.

docs/scripts/helpers.js Outdated Show resolved Hide resolved
@mnajdova mnajdova merged commit c634ac5 into mui:next Nov 20, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants