-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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] Use icon inside a Button #30803
Conversation
@mui/joy: parsed: +1.33% , gzip: +1.03% |
The change detected in Argos is due to the reduction of the height for the |
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.
Nice, great work as usual Jun!
Not to get too lost in the naming discussion now, but I think that the proposed square
prop would be better if it was icon
. Instead of thinking of it as something that changes the styles of the Button, I think it's more that changes the type of Button used.
Good point, I experience a downside when testing the // By doing this, the `square` or `icon` does not work because the style overrides has more priority
styleOverrides: {
MuiButton: {
root: ({ ownerState }) => ({
'--Button-gutter': '1rem',
})
}
}
// So I have to do this instead
styleOverrides: {
MuiButton: {
root: ({ ownerState }) => ({
// takes a while to figure out why the prop `square` does not work.
...(!ownerState.square && {
'--Button-gutter': '1rem',
}),
})
}
} However, if we expose styleOverrides: {
MuiButton: {
root: ({ ownerState }) => ({
'--Button-gutter': '1rem', // adjust the left, right padding
})
},
MuiIconButton: {
root: ({ }) => ({
'--IconButton-padding': '0.25rem', // adjust all padding sides
})
}
} |
@danilo-leal I have removed the |
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.
Nice, it's making sense so far. We might as well stress test this a bit more with example UIs, but so far so good!
Preview:
Playground: https://deploy-preview-30803--material-ui.netlify.app/experiments/joy/components/
Demo: https://deploy-preview-30803--material-ui.netlify.app/experiments/joy/button/
Design highlights:
add Button CSS variables (naming can be discussed later). The great benefit about using CSS variables is that we don't need to use pseudo selectors like in
@mui/material/Button
. Also, the customization experience is a lot better because developers only need to change the value without writing the whole stylesheet for every size.--Button-minHeight
: to make the button's height explicit and predictable for different sizes.--Button-gutter
: represents the padding-left & right of the button to be used to calculate icon margin.--Button-iconOffsetStep
: the negative margin of the start/end icon--Button-gap
: the space between start/end icon and the textadd
startIcon
&endIcon
prop to the Button(it makes theming harder)
addsquare
prop to the Button (to create IconButton). I think this is a lot easier than creating another component, akaIconButton
, and maintaining both of these buttons. Here is my thought process.I want a button with an icon inside, so I write this<Button><PlusIcon /></Button>
I see it on the screen that the button is a rectangle but I want the shape to be a square.I expect to add one more prop like<Button square><PlusIcon /></Button>
to make the width & height equally and if I want it to be rounded, I would addsx
or style overrides depending on the whole design look & feel.You might ask, why notshape="square | circular"
. I have tried that out and it did not work well becauseshape: square
andshape: circular
target different CSS properties or more than 1 property depending on how you interpreted them.square
: target the width to equal to the heightcircular
: target the border-radiusIt is hard to predict the UI when 1 prop targets different CSS properties. However, this is just from my experience of using it and I might be wrong. We will be able to test this out with the UI examples and revisit it again.What's next?
IconButton
component--MuiButton-minHeight
or--joy-Button-minHeight
or--Button-minHeight
loading
prop to Button