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] Revise "Component theming" and "How to customize" guides #31997

Merged
merged 24 commits into from Apr 12, 2022

Conversation

danilo-leal
Copy link
Contributor

@danilo-leal danilo-leal commented Mar 26, 2022

Took the liberty to revise some of this content, which I think are some of the most important in the docs. There were some general reorganizing opportunities that I found and some content optimization (excluding something mentioned twice). All of it was inspired by this issue, given we weren't mentioned about sx prop higher than the theme's styles overrides specificity.

Initially, I was only going for the "How to customize" page but ended up thinking that the best place to tackle the issue above was in the "Component theming" page instead. So, since I was there already, took the opportunity to go through it as well.

Please revise the accuracy of the rewritten content!

Deploy previews:

@danilo-leal danilo-leal added the docs Improvements or additions to the documentation label Mar 26, 2022
@mui-bot
Copy link

mui-bot commented Mar 26, 2022

No bundle size changes

Generated by 🚫 dangerJS against ef3c447


`sx` is also compatible with theme style overrides if you prefer the shorthand notation.
Note that some components expose a `color` prop, which has a lower specificty than the theme's styles overrides. For example, say you have customized `Link`'s color.
Copy link
Member

Choose a reason for hiding this comment

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

@danilo-leal I was wrong. The Link is actually a bug. This should have the highest priority <Link color="highest-priority-color">...</Link>.

Copy link
Member

Choose a reason for hiding this comment

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

You can remove this part and I will create a fix in a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! I was just thinking it was weird for the component color prop to have lower specificity... I'll correct this sentence!

Copy link
Member

Choose a reason for hiding this comment

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

@siriwatknp are you going to bump the specificity for each prop combination? Should we create an RFC for this and make it work consistent with Material UI? In this case, when would you ever need the props callback?

Copy link
Member

Choose a reason for hiding this comment

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

@mnajdova I am not sure I follow you. From my understanding, this is a bug on the Link component.

Copy link
Member

Choose a reason for hiding this comment

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

I would say that the Typography (and Link) are basically the ones that work differently, in the other components that theme overrides take precedence, for example take a look at the button - https://codesandbox.io/s/shy-dust-sdylec?file=/src/App.tsx

Co-authored-by: Siriwat K <siriwatkunaporn@gmail.com>
Copy link
Member

@samuelsycamore samuelsycamore left a comment

Choose a reason for hiding this comment

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

Solid improvements! I've just gone through how-to-customize and will come back to theme-components in the morning!


Using the `styled()` utility offers a simple way for adding dynamic styles based on props.
> ⚠️ Note that if you are using TypeScript you will need to update the prop's types of the new component.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
> ⚠️ Note that if you are using TypeScript you will need to update the prop's types of the new component.
> ⚠️ Note that if you are using TypeScript you will need to update the prop types of the new component.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we should move this back right before the demo showing how it should be altered in TypeScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before or after? Haven't altered its position, its in the same spot as in the current version.


If you are not familiar with the `sx` prop, make sure you first check out [the concept around it](/system/the-sx-prop/) and [the difference with the `styled` utility](/system/styled/#difference-with-the-sx-prop).

To have a similar shorthand CSS notation to the `sx` prop but within the theme, you can use `sx` inside the `stylesOverrides`.
Copy link
Member

Choose a reason for hiding this comment

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

Rephrasing.

Suggested change
To have a similar shorthand CSS notation to the `sx` prop but within the theme, you can use `sx` inside the `stylesOverrides`.
You can use the `sx` prop inside the `styleOverrides` key to modify styles within the theme using shorthand CSS notation.

Copy link
Member

Choose a reason for hiding this comment

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

Can we elaborate on why a developer would want to do this? And this would also be a good place to explain why this is "experimental."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mnajdova anything you'd like to share about that?

Copy link
Member

Choose a reason for hiding this comment

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

Can we elaborate on why a developer would want to do this?

Mainly for conistency. If a developer is already used to the sx syntax and it's shorthands, it's limiting that it can be used on only one place (the sx prop). More over, if they want to convert from sx prop to styled(), or move the styles to the theme overrides, they would have to manually change the styles to comply with the other regular syntax. This utility helps them by doing it automatically and providing a better DX along the way.

It's experimental as it was added after the v5 stable release, and we usually export API like this as an experimental first, to see if there will be some unforeseen bugs and stabilize them later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me know what you think, tackled these aspects.

@danilo-leal danilo-leal requested review from samuelsycamore and mnajdova and removed request for mnajdova March 31, 2022 16:51
@danilo-leal
Copy link
Contributor Author

@siriwatknp & @mnajdova little bump in your notifications to get this one out!

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

👍 Thanks for improving these important pages!


Let's go back to the above demo. How can you override the slider's thumb?
<img src="/static/images/customization/dev-tools.png" alt="dev-tools" width="796" style="margin-bottom: 16px;" />
Copy link
Member

Choose a reason for hiding this comment

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

The change of docs/public/static/images/customization/dev-tools.png looks blurry on my screen. Am I the only one? I mean:

a. https://mui.com/customization/how-to-customize/#overriding-nested-component-styles
b. https://deploy-preview-31997--material-ui.netlify.app/customization/how-to-customize/#the-sx-prop

a. looks better on my end. I'm raising this because it's not the first time I see this problem. What do you think of limiting the resolution to x2, would it solve the problem? Otherwise, could we try a fixed integer increment? Currently, we are doing x3.28, maybe x3 or x4 would look crisp?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh... looks a bit blurry to me too, now that I'm looking at it again. But I did export at 2x (don't know where you got x3.28 from!). Though the blurriness could be because I increased the image size a bit. Let me see if I can tweak it properly.


⚠️ These class names can't be used as CSS selectors because they are unstable,
however, MUI applies global class names using a consistent convention: `Mui[Component name]-[name of the slot]`.
First, use your browser's dev tools to identify the class for the component slot you want to override:
Copy link
Member

Choose a reason for hiding this comment

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

I think that it was clearer before. We were explaining how to "identify the class" in logical order. How will people know that MuiSlider-thumb is the right selector when all they see is?

Screenshot 2022-04-07 at 12 55 19

We do no longer explain it in the flow, but at the bottom of the section. I think that it requires developers to do back and forth to understand the whole process, which is not ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. Revisited this one now, let me know your thoughts.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2022
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 8, 2022
@danilo-leal
Copy link
Contributor Author

Commenting to bump this one up in y'all notifications!

Copy link
Member

@siriwatknp siriwatknp left a comment

Choose a reason for hiding this comment

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

I thought I had already approved it 😂.

@danilo-leal danilo-leal merged commit de11911 into mui:master Apr 12, 2022
@danilo-leal danilo-leal deleted the how-to-customize-revision branch April 12, 2022 21:43
oliviertassinari added a commit that referenced this pull request Apr 24, 2023
This header was changed in #31997, but it doesn't seem to need to be a h3, h2 seems enough, and retain the anchor link

Signed-off-by: Olivier Tassinari <olivier.tassinari@gmail.com>
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.

None yet

6 participants