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
[Joy] Make Icon fontSize
adaptable to its parent
#31268
Conversation
@mui/joy: parsed: +0.44% , gzip: +0.43% |
What are the downsides of using this API? Some I could think of:
What would be the recommended approach when using custom icons? |
You can (check my last commit). The reason I didn't add it before is that it touches
Partially right. At this point, we don't even need to document that we are using CSS variables because you can do this without the knowledge of CSS variables: <Button size="sm" startIcon={<Icon />}> // works
<Button size="sm" startIcon={<Icon fontSize="sm" />}> // works
<Button size="sm" startIcon={<Icon sx={{ fontSize: '20px' }} />}> // works
Let's use font icon for example: <Button size="sm" startIcon={<i className="font-awesome ..." />}> .font-awesome {
font-size: var(--Icon-fontSize, 20px);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, let's try this and see how it will scale.
Important thing to think about for the API is how do we document the css variables available in the component. We should also make sure we use them consistently after the stable release, as they are basically a public API.
This is an experimental feature called "Adaptive component".
It gives the parent component the ability to control the children without hurting customization experience.
The problem
In Material UI, it is using CSS selector to control the children which leads to bad customization experience. #28917
The solution
create CSS variable with a default value, so by default
<Icon />
renders this:This allows any component to control this icon via
--Icon-fontSize
, for example a Button:Customization
When developer defines a fontSize prop to the instance, it creates the variable at the icon, so the value has the highest priority.
Meaning, the variable from the parent has no effect 😲. I think this is the best experience so far.
A plus of using CSS variables is that developers do not need to use our theme (in js) to set the default props, they can use any CSS solution without any setup 😲