Conversation
|
✅ Deploy Preview for compiled-css-in-js canceled.
|
| }, | ||
| }); | ||
|
|
||
| // // Second pass to replace all usages of `style`. |
There was a problem hiding this comment.
TODO, makes sense to hook the style prop up as well
There was a problem hiding this comment.
Does anything else ever use style in Babel? style={css(…)} isn't valid, right?
There was a problem hiding this comment.
I think the pass over the style element is intended for outputting CSS vars 🤔 or something of that nature.
There was a problem hiding this comment.
That's only when it's in runtime mode, but yeah, maybe right…really glad if you can learn this part of it because I have no clue how extraction or runtime actually work 🤣
There was a problem hiding this comment.
Neither hahah
kylorhall-atlassian
left a comment
There was a problem hiding this comment.
Without pulling it up locally, I'm not of much help reviewing the AST, but great like spike into Compiled, I hope it's not too far off and they'll like—it will drastically reduce some technical debt as the alternative is using <ClassNames>{({ css }) => cloneElement(…, { className: ax([css({…}), props.className]) })}</ClassNames> or something.
| import { css } from '@compiled/react'; | ||
|
|
||
| const MyDiv = ({ children }) => { | ||
| return cloneElement(children, { css: css({ fontSize: 12 }) }); |
There was a problem hiding this comment.
This is would be the full example of what we need this for—do you think it would work?
const styles = css({ fontSize: 12 });
const MyDiv = ({ children, className }) => {
return cloneElement(children, { css: cx(styles, props.className) });
}There was a problem hiding this comment.
The other question I've got, probably for Compiled, is should this be props.css or props.className exclusively?
There was a problem hiding this comment.
I had the same question.
I'll add a test case for the example you provided! It should just work because that part of the algorithm gets handed back to compiled
| }, | ||
| }); | ||
|
|
||
| // // Second pass to replace all usages of `style`. |
There was a problem hiding this comment.
Does anything else ever use style in Babel? style={css(…)} isn't valid, right?
| // TODO: This is a temporary fix to prevent the plugin from crashing when the second argument of cloneElement is not an object expression. | ||
| if (!t.isObjectExpression(props)) { | ||
| throw new Error('Second argument of cloneElement must be an object expression.'); | ||
| } |
There was a problem hiding this comment.
If someone is using a variable/spread/etc it'll probably be impossible to reliably fish out and modify the CSS prop.
Are there any standard approaches to this problem in use in the repo already? Do we throw/Log an err/try really hard to locate the variable?
| path: NodePath<t.TaggedTemplateExpression> | NodePath<t.CallExpression>, | ||
| state: State | ||
| ) { | ||
| if ( |
There was a problem hiding this comment.
should this check that cloneElement is imported from react too?
There was a problem hiding this comment.
Yes definitely and also should check for aliased imports
import { cloneElement as foo } from 'react';
There was a problem hiding this comment.
Edit: I added support for alias and member expressions in the latest commit
a0a9506 to
b6b9736
Compare
What is this change?
Compiled now treats
react.cloneElementas a stylable element.this can be extended to support
react.createElementfairly easily.Why are we making this change?
To allow cases where a CSS prop is used like so:
How are we making this change?
cloneElementCallExpressioncsspropclassNameThis might not be a direction the library wants to go in, which is understandable.
Alternatively, we could address this via
<ClassNames>however Compiled currently does not pick up non-jsx elements as children of the<ClassNames>API.PR checklist
Don't delete me!
I have...
website/