[system] `styled` should accept sx syntax
See original GitHub issue- I have searched the issues of this repository and believe that this is not a duplicate.
Summary 💡
styled
and sx
should accept the same set of props.
Examples 🌈
const WrapperPaper = styled(Paper)({
my: 2,
mx: "auto",
padding: 2,
minWidth: "600px",
});
// is different from
<Paper sx={{ my: 2, mx: "auto", padding: 2, minWidth: "600px" }}>
The WrapperPaper
component doesn’t seem to apply the shortcuts
TypeScript accepts those mx
and my
props though in the styled
call, they are simply not translated afterward. The sx
version works fine, but leads to code duplication in my use case.
Motivation 🔦
I’d expect both to have the same API.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:10
- Comments:10 (10 by maintainers)
Top Results From Across the Web
[system] `styled` should accept sx syntax · Issue #28678 - GitHub
I think it seems possible to accept sx directly in styled but the only concern is about performance gain.
Read more >The sx prop - MUI System
The sx prop lets you work with a superset of CSS that packages all of the style functions exposed in @mui/system . You...
Read more >The `sx` Prop - Theme UI
The sx prop lets you add any valid CSS to an element, while using values from your theme to keep styles consistent. You...
Read more >The Ultimate Guide to the MUI 'sx' Prop - Smart Devpreneur
Superset of CSS – sx can accept all CSS attributes (using JSS syntax) and it can accept all values from the “MUI System“....
Read more >What is the purpose of sx prop in Material UI? - Stack Overflow
The sx props allows you to use all the mui system properties along with CSS properites. with style ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Will need to check to see how this could work.
I would try to keep the API to minimum, I would say the first and last APIs are enough.
Yes, but there would be the conflict between the
sx
prop and thesx
function, we would need to override it which can be surprising. What’s wrong with importing a module? Otherwise we need to again invent some new API. With the import is clear what is expected - I am preprocessing the input of thestyled()
utility.An
sx
function that behaves like a mix betweenstyled
andsx
prop could be defined like this:That’s very draftish and lacks typings, but I think this could be done already in user-land. I haven’t yet switched my main project to mui v5 but I might give this a shot later on.