-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
[core] Support merging of className and style from theme #45975
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
base: master
Are you sure you want to change the base?
Conversation
Netlify deploy previewhttps://deploy-preview-45975--material-ui.netlify.app/ @mui/material/DefaultPropsProvider: parsed: +39.32% , gzip: +34.59% Bundle size reportDetails of bundle changes (Toolpad) |
@siriwatknp This PR merges What do you think about the logic? if you are fine with implementaion, i'll create documention for |
Let's wait for @DiegoAndai comment on this. I'm surprise that there are not request from the community about this both core and x repos. |
); | ||
} | ||
} | ||
} | ||
} else if (propName === 'className' && mergeClassNameAndStyle) { |
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.
Check props.className
so that clsx
does not run on every iteration.
} else if (propName === 'className' && mergeClassNameAndStyle) { | |
} else if (propName === 'className' && mergeClassNameAndStyle && props.className) { |
output[propName] = clsx( | ||
defaultProps?.[propName] as string, | ||
props?.[propName] as string, |
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.
I think this can be explicit.
output[propName] = clsx( | |
defaultProps?.[propName] as string, | |
props?.[propName] as string, | |
output.className = clsx( | |
defaultProps.className, | |
props.className, |
defaultProps?.[propName] as string, | ||
props?.[propName] as string, | ||
) as T[keyof T]; | ||
} else if (propName === 'style' && mergeClassNameAndStyle) { |
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.
} else if (propName === 'style' && mergeClassNameAndStyle) { | |
} else if (propName === 'style' && mergeClassNameAndStyle && props.style) { |
output[propName] = { | ||
...(defaultProps?.[propName] ?? ({} as React.CSSProperties)), | ||
...(props?.[propName] ?? ({} as React.CSSProperties)), |
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.
output[propName] = { | |
...(defaultProps?.[propName] ?? ({} as React.CSSProperties)), | |
...(props?.[propName] ?? ({} as React.CSSProperties)), | |
output.style = { | |
...defaultProps.style, | |
...props.style, |
b69362d
to
f566486
Compare
df47431
to
9ce9f84
Compare
@siriwatknp applied your suggestions, now |
closes: #45919