Skip to content
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

Unable to compose themed css in emotion10 #997

Closed
piotrblasiak opened this issue Nov 6, 2018 · 7 comments
Closed

Unable to compose themed css in emotion10 #997

piotrblasiak opened this issue Nov 6, 2018 · 7 comments
Milestone

Comments

@piotrblasiak
Copy link

  • emotion version: 10.0.0-beta.8
  • react version: 16.6.0

Relevant code.

const css1 = theme => ({background: "black"});
const css2 = {color: "white"};

return <div css={[css1, css2]}/>

What you did:

Tried to compose with one of the parts being a function/themed css.

What happened:

"Functions that are interpolated in css calls will be stringified..."

Is this by design or a bug? The workaround I found is to use the spread operator and call on the css function:

<div css={theme => ({...css1(theme), ...css2})/>
```

But this forces me to know if css1 is a function or not.
@Loque-
Copy link

Loque- commented Nov 6, 2018

I think this is by design, as you are using object notation (styled), but trying to merge the two styles as if they were defined as strings (css).

I can see the documentation saying you can merge styles in an array here: https://next.emotion.sh/docs/composition (but it uses css, and the content of which is strings)

And here are the docs for object notation: https://next.emotion.sh/docs/object-styles (which are not strings, but objects), there is a note on composition there which might be helpful.

Your solution looks fine to me! Hope that helps! : )

@piotrblasiak
Copy link
Author

It doesn´t say in the docs that it needs to be a string - and IMO it would make a lot of sense to be able to put a function or an object in there as well.

@defusioner
Copy link

defusioner commented Oct 11, 2019

Would be nice to have this feature. Actually the workaround is to make:
css={theme => [css.class1(theme), css.class2]}

@gordonmleigh

This comment has been minimized.

@Andarist

This comment has been minimized.

@gordonmleigh

This comment has been minimized.

@Andarist Andarist added this to the v11 milestone Nov 4, 2019
@Andarist
Copy link
Member

Andarist commented Dec 2, 2019

This will be possible in upcoming v11, we’ve just merged in #1130 which Implements this

@Andarist Andarist closed this as completed Dec 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants