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] Update buildAPI script to handle the "styled" components #23370

Merged

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Nov 2, 2020

This PR prepares necessary changes for generating the CSS and Component name sections in the docs file for the components that does not use withStyles and does not contain the classes prop. It extract this information based on the JSON data available at docs/data/component-name.json.

@mui-pr-bot
Copy link

mui-pr-bot commented Nov 2, 2020

Details of bundle changes

Generated by 🚫 dangerJS against 99bae46

@mnajdova mnajdova changed the title init [build] Update buildAPI script to generate the CSS section based on the ComponentClassKey type Nov 2, 2020
docs/scripts/buildApi.ts Outdated Show resolved Hide resolved
@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Nov 2, 2020
Copy link
Member

@oliviertassinari oliviertassinari left a comment

Choose a reason for hiding this comment

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

On a related note, the changes make me wonder if we need a section for the components prop, to describe what each component do, or maybe an interactive playground that change the color background could do the trict.

docs/scripts/buildApi.ts Outdated Show resolved Hide resolved
docs/scripts/buildApi.ts Outdated Show resolved Hide resolved
Comment on lines 52 to 53
/** Styles applied to the root element. */
| 'root'
Copy link
Member

Choose a reason for hiding this comment

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

This won't do anything. JSDOC for literals is ignored: microsoft/TypeScript#25499.

Copy link
Member Author

Choose a reason for hiding this comment

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

Aha, now I understand why I didn't have these on the node directly, so I had to iterate all leadingComments and see which one is right before the specific classKey - see #23370 (comment) I am open to other ideas of how to do this.

docs/scripts/buildApi.ts Outdated Show resolved Hide resolved
@mbrookes mbrookes added the on hold There is a blocker, we need to wait label Nov 2, 2020
@mbrookes
Copy link
Member

mbrookes commented Nov 2, 2020

On hold pending #23214

mnajdova and others added 2 commits November 3, 2020 08:25
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
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.

We should use a more approachable format for this documentation. Encoding it in types where it isn't useful at all is not helpful long-term.

It make sense to encode in types if it has a direct impact and a first-class API. Extracting it manually is too brittle.

@mnajdova
Copy link
Member Author

mnajdova commented Nov 5, 2020

We should use a more approachable format for this documentation. Encoding it in types where it isn't useful at all is not helpful long-term.

It make sense to encode in types if it has a direct impact and a first-class API. Extracting it manually is too brittle.

Do you have some suggestion for better alternative? We could do it manually, but I don't think that is a better alternative at this moment. I understand that adding comments on the union type is not he best option, but I don't have better ideas to be honest.

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.

I think we should just fork it entirely. The "CSS" section doesn't make much sense for the unstyled classnames:

  • rule name is irrelevant
  • classes object is not implemented
  • mention of implementation is not helpful since the definition of these rules is spread throughout the implementation.
    It might be impossible to extract statically without using actual types.

It seems to me a minimal approach at first is better suited i.e. don't abstract before we know there's an abstraction:

  • classnames with description in JSON
  • separate function for generating the CSS section

Over time we move more and more components to that new format and during that time we'll see what makes more sense. Abstracting it just for one component might not pay off long term.

@mnajdova
Copy link
Member Author

mnajdova commented Nov 5, 2020

@eps1lon what do you think of these changes - mnajdova#12

@mnajdova mnajdova requested a review from eps1lon November 5, 2020 12:32
@mnajdova
Copy link
Member Author

mnajdova commented Nov 6, 2020

It seems to me a minimal approach at first is better suited i.e. don't abstract before we know there's an abstraction:

  • classnames with description in JSON
  • separate function for generating the CSS section

Over time we move more and more components to that new format and during that time we'll see what makes more sense. Abstracting it just for one component might not pay off long term.

@eps1lon done let's do final round of reviews to unblock #23308

Note: You mention that we don't need the classes key as we do not have the classes prop, but we DO NEED them for the theme overrides, so we should keep them. Example:

const theme = createMuiTheme({
  components: { 
    MuiSlider: { 
      styleOverrides: { 
        colorPrimary: { // one key from the `classes`
          // some styles
        },
      },
    },
  },
});

@oliviertassinari oliviertassinari removed the on hold There is a blocker, we need to wait label Nov 6, 2020
@mbrookes
Copy link
Member

mbrookes commented Nov 6, 2020

What does the value under the class key add? It seems like redundant information that can be reconstructed.

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.

Coninuing mnajdova#12 (comment):

Where am I mentioning the classes prop?

The docs are mentioning it:

With a rule name of the classes object prop.

-- https://deploy-preview-23370--material-ui.netlify.app/api/slider-styled/#css

The docs also still mention the implementation which is no longer helpful (and never really was):

If that's not sufficient, you can check the implementation of the component for more detail.

I still recommend completely forking the approach. This advise has been ignored while no alternative has been provided. I don't care whether you follow my proposal or someone else's. But the problems mentioned in a review should be resolved in some shape or form.

@mnajdova
Copy link
Member Author

mnajdova commented Nov 8, 2020

The docs are mentioning it

Alright will change the generated markdown. I wanted to keep the PR focused on how the information is extracted, not the actual content, that’s why I couldn’t understand where I am mentioning the classes prop. Will change the markdown generated together with these changes so the changes are complete.

@mnajdova
Copy link
Member Author

mnajdova commented Nov 9, 2020

What does the value under the class key add? It seems like redundant information that can be reconstructed.

These keys are still used under the styleOverrides in the theme. We are not documenting them on any other place as far as I know, so I think we should keep that information.

const theme = createMuiTheme({
  components: { 
    MuiSlider: { 
      styleOverrides: { 
        colorPrimary: { // one key from the `classes`
          // some styles
        },
      },
    },
  },
});

@mnajdova mnajdova requested a review from eps1lon November 9, 2020 11:49
@mnajdova
Copy link
Member Author

mnajdova commented Nov 9, 2020

I've updated the description for the CSS section of the markdown, hopefully it is more clear now when it comes to "styled" components

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 need to clarify what the runtime change is for.

packages/material-ui-lab/src/SliderStyled/SliderStyled.js Outdated Show resolved Hide resolved
@mnajdova mnajdova merged commit 2c7a157 into mui:next Nov 10, 2020
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.

5 participants