overridesResolver
Initial implementation example:
const overridesResolver = (props, styles) => {
const { styleProps } = props;
return deepmerge(styles.root || {}, {
...styles[styleProps.variant],
[`& .${buttonClasses.label}`]: styles.label,
[`& .${buttonClasses.startIcon}`]: {
...styles.startIcon,
...styles[`iconSize${capitalize(styleProps.size)}`],
},
});
};
Problems:
Line 6 results in
[`& .MuiButton-label`]: undefined,
which overrides any definition inside the root:
const themeOverrides = createMuiTheme({
components: {
MuiButton: {
styleOverrides: {
root: {
'& .MuiButton-label': {
// some overrides
}
}
}
}
}
})
Issue - https://github.com/mui-org/material-ui/issues/25075 cannot override using & .MuiButton-label
. Proposed fix https://github.com/mui-org/material-ui/issues/25075#issuecomment-787495208
This creates another problem:
Currently if we do:
const theme = createMuiTheme({
components: {
MuiButton: {
styleOverrides: {
root: {
border: "2px dashed grey"
},
contained: {
// shouldn't this win?
border: "none"
}
}
}
}
});
The styles defined under root win which is not intuitive at all. I know we came again to this multiple time, but it's important to get it right. Proposed fix:
const overridesResolver = (props, styles) => {
const { styleProps } = props;
return ({
// Apply first overrides, then root
[`& .${buttonClasses.label}`]: styles.label,
[`& .${buttonClasses.startIcon}`]: {
...styles.startIcon,
...styles[`iconSize${capitalize(styleProps.size)}`],
},
...styles.root,
...styles[styleProps.variant],
});
};
Alternative solution (not sure what the perf cost would be):
const overridesResolver = (props, styles) => {
const { styleProps } = props;
return ({
// Apply first overrides, then root
- [`& .${buttonClasses.label}`]: styles.label,
- [`& .${buttonClasses.startIcon}`]: {
- ...styles.startIcon,
- ...styles[`iconSize${capitalize(styleProps.size)}`],
- },
...styles.root,
...styles[styleProps.variant],
});
};
const ButtonLabel = experimentalStyled(
'span',
{},
{
name: 'MuiButton',
slot: 'Label',
+ overridesResolver: (props, styles) => styles.label,
},
)(({ theme }) => ({
// label styles
}));
const ButtonStartIcon = experimentalStyled(
'svg',
{},
{
name: 'MuiButton',
slot: 'StartIcon',
+ overridesResolver: (props, styles) => ({
+ ...styles.startIcon,
+ ...styles[`iconSize${capitalize(styleProps.size)}`],
+ }),
+ },
)(({ theme }) => ({
// label styles
}));
Discussion bring withStyles and makeStyles back https://github.com/mui-org/material-ui/issues/24109#issuecomment-780805118 When to us sx vs. flat props? https://github.com/mui-org/material-ui/issues/20012#issuecomment-782821025 Agree, sx whenever possible, flat props in my opinion are good for prototyping purposes... normalize supported colors use https://github.com/mui-org/material-ui/issues/24778 Agree, no objections, just we should be carefull on documenting the changes performance aren't great https://github.com/mui-org/material-ui/pull/24663#issuecomment-778492717 - is it still an issue? Last comment says it's fine, should we anyway investigate further? see where is the bottleneck and then consider performance flag Postponed scoped css with emotion https://github.com/mui-org/material-ui/issues/20461#issuecomment-809248743 POSTPONED after v5
Apr 23, 2021Positive feedback: Good looking docs Accessibility notes & When to use sections on each component's page Nice separation between unstyled (component page) and styled examples Support for React & Vue Negative feedback: Small set of components supported
Apr 15, 2021Converting styles from JSS to emotion Things to consider when migrating component's styles to emotion. In v4 we were defining the styles like: export const styles = (theme) => ({ /* Styles applied to the root element. */ root: {}, /* Styles applied to the root element if `container={true}`. */ container: {
Jan 13, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up