-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[system] Support sx on all primitive elements #23220
Comments
There’s no need for a pragma, you can release a Babel macro in a similar fashion to Styled Components’. |
How would Pragma work with the new automatic runtime? Has that been considered? |
Looking forward to this feature! |
Please note that Styled's Babel Macro is a "bad macro", what I mean is that it's actually a Babel Plugin which is triggered file-wide at macro import (they release both the plug-in and the macro). |
There were also discussions about changing the prefered API from: <Box component="footer" sx={{ display: "block" }}>
My footer
</Box> to <x.footer sx={{ display: "block" }}>
My footer
</x.footer> inspired by https://xstyled.dev/. This is superior when you have long children. The closing tag is more helpful in the latter option ( See #27207 (comment) for why it could be valuable for developers. |
@oliviertassinari @mnajdova I would like to push this forward in the upcoming v5-beta. I think that this could make migration to v5 a lot easier. Take this as an example from notistack repo // This is what normal v4 looks like
const styles = (theme: Theme) => createStyles({
root: {
// styles
}
});
const SnackbarContent = forwardRef<HTMLDivElement, Props>(({ classes, className, ...props }, ref) => (
<div ref={ref} className={clsx(classes.root, className)} {...props} />
))
export default withStyles(styles)(SnackbarContent); without primitivesimport { styled } from '@material-ui/core/styles';
const Div = styled('div')(({ theme }) => ({
// styles
}))
const SnackbarContent = forwardRef<HTMLDivElement, Props>(({ classes, className, ...props }, ref) => (
<Div ref={ref} className={clsx(classes.root, className)} {...props} />
))
export default SnackbarContent; the issue with this approach is it make the structure of the project completely change, the component ( Primitives// just an example of importing primitives
import { mui } from '@material-ui/core/primitives';
// remain the same
const styles = (theme: Theme) => createStyles({
root: {
// styles
}
});
const SnackbarContent = forwardRef<HTMLDivElement, Props>(({ classes, className, ...props }, ref) => (
<mui.div
ref={ref}
className={clsx(classes.root, className)}
sx={theme => styles(theme).root}
{...props}
/>
))
export default SnackbarContent; The styles should remain the same and the html tag is replaced with primitives which make the code looks easier to review. |
I was struggling to upgrade the version of mui stuff (material and date picker). I'm hoping getting rid of the deprecated stuff eases this a bit. I don't love that I can't just use sx on plain HTML stuff and have to wrap it in Box, but oh well. Looks like I'm not alone, fwiw. mui/material-ui#23220
@mnajdova Hi, do you know if supporting |
Hey @robphoenix we are not actively working on this at this moment. I believe we can kick off this effort again when we are closer to v6. |
Ok, grand, thanks for the update @mnajdova 🙇🏻 |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@mui/pigment-css It looks like there is movement on this: https://twitter.com/PigmentCSS/status/1784828168748011578. Can we systematically link PRs with issues? I can't find where this is happening, thanks. |
Summary 💡
It would be great if we can support the
sx
props on the primitives with jsx pragma. That would basically help us to replacewith
For instance https://xstyled.dev/docs/emotion/#use-css-prop or https://theme-ui.com/sx-prop. It seems that we could only support it with emotion, which is OK-ish as it's the default engine 🙃.
Motivation 🔦
This would help us to move away from templates that would use the
Box
component everywhere. On the other hand, we plan to support thesx
prop on all core components, so it may not be that bad, but still, I think this is something that will bring us in the right direction.Raised in #23053
The text was updated successfully, but these errors were encountered: