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.
Ignore sx prop on JSX html tag.
| interface HTMLAttributes<T> { | ||
| sx?: any; | ||
| } |
There was a problem hiding this comment.
Just to test that we can modify the types of JSX elements.
There was a problem hiding this comment.
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.
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.
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)' }}> |
|
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
sxprop using runtime{…sx()}spread (see the test cases)ForwardSxallowTransformSxcheck (to transform any component)styled(I like this so much becausesxis not independent ofstyled)Tested in next-app, it works with HTML tags and Material UI components.