-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Enable sx
prop on any components
#37
Conversation
"import/no-unresolved": "off" | ||
} | ||
"import/no-unresolved": "off", | ||
"react/no-unknown-property": ["error", { "ignore": ["sx"] }], |
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.
Ignore sx
prop on JSX html tag.
interface HTMLAttributes<T> { | ||
sx?: any; | ||
} |
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.
Just to test that we can modify the types of JSX elements.
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.
Nice, we can use the SxProps
tough, no? :) I would recommend adding a documentation about this in the README.md too, so we can test everything, including typings and make sure we haven't forgot something.
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.
It's for POC at this point. There is one issue to fix from Pigment side which is delegating sx
logic to the theme. Currently, Pigment is using styleFunctionSx
from MUI System which is impossible to customize.
Once that's done, I will add docs for it.
/** | ||
* For JSX calls, replace the sx prop with runtime sx | ||
*/ | ||
this.replacer((_tagPath) => { |
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.
Casting type like this will fail this.replacer((_tagPath: NodePath<CallExpression>) => {
because Type 'Node' is not assignable to type 'CallExpression'.
So I have to create a new variable instead.
}, | ||
}} | ||
> | ||
<p sx={{ boxShadow: '0 0 4px 0 rgba(0 0 0 / 0.12)' }}> |
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 ❤️ this!
I haven't tested this but how would conditional sx work here -> <div sx={props.isPrimary ? {color: 'red', background: 'blue'} : {fontWeight: '400'}} /> |
It will be: <div {…props.isPrimary ? sx(…) : sx(…) } /> The logic that you had implemented remains the same. What I added is the conversion of The runtime |
closes #35
sx
prop using runtime{…sx()}
spread (see the test cases)ForwardSx
allowTransformSx
check (to transform any component)styled
(I like this so much becausesx
is not independent ofstyled
)Tested in next-app, it works with HTML tags and Material UI components.