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] Add experimental_sx
utility
#29833
Conversation
It'd be nice if we could use the theme within unstable_sx without having to pass it in. Isn't the whole point of sx mapping styles directly to theme values? |
This comment has been minimized.
This comment has been minimized.
unstable_sx
utilityexperimental_sx
utility
packages/mui-system/src/sx/sx.js
Outdated
function sx(styles, theme) { | ||
return styleFunctionSx({ sx: styles, theme }); | ||
} |
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.
Can you try with:
const sx = (styles) => ({ theme }) => styleFunctionSx({ sx: styles, theme });
From what I check in emotion & styled-components, they support nested function.
I prefer this because I don't need to get the theme if we don't need it (mostly we don't need the theme if we want to use sx
).
const MyThemeComponent = styled('div')(
sx({
color: 'primary.contrastText',
backgroundColor: 'primary.main',
padding: 1,
borderRadius: 1,
})
);
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 was trying to create an API not tightly related to the styled()
, but maybe this is the only use-case, so yeah, let me update
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.
Updated. I've tested it using in the styled()
utility and in the variants in side the theme. I can't think of any other use-cases at this moment.
sx({ | ||
color: 'primary.contrastText', | ||
backgroundColor: 'primary.main', | ||
padding: 1, | ||
borderRadius: 1, | ||
}), |
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.
One question, does sx
work without ThemeProvider?
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.
Yes, it's just that I could not really test that the values are applied :) I will add test for it too, just to ensure it does not throw
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.
🎉🎉🎉
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 love this new utility :)
Co-authored-by: Benny Joo <sldisek783@gmail.com>
Co-authored-by: Benny Joo <sldisek783@gmail.com>
…aterial-ui into feat/sx-util-function
Fixes #28678
Related to #29816
The goal of this new API, is to allow users to use the
sx
syntax inside thestyled()
utility primerly.Why?
sx
and thestyled()
utility without having surprise as to why some styles are different/not workingHow?
I would like to start with minimal and most simple implementation, which would be defining the styles and propagating the
theme
. This should allow developers to use this syntax wherever they want, for example, in thestyled()
utility, when defining thevariants
for the component, when definingmixins
etc.Some alternatives proposed: #28678 (comment)