Closed jstcki closed 6 years ago
I like this idea on the surface, but I really need to think about it. I'm also curious what @mitchellhamilton thinks.
+1
This is one of my bigger frustrations with various different css-in-js solutions. I'm using lerna
and am building out a large react component library where each component has it's own build step and as a result I need different instances to play nice.
This bit me pretty hard with styled-components 2.x (weirdly it works fine w/ 1.2.X so I've downgraded to that).. I've also ran into this exact issue with https://github.com/zeit/styled-jsx/issues/309
anyways, I'd like to switch to emotion as it seems superior to styled-components, and I'm really digging a lot of the newer additions like facepaint.
@hanford Would it work if you created a sheet
package in your lerna packages that was required but the other packages?
Potentially, though decoupling styles from the given components is obviously not ideal
What I mean is creating a package in your packages
that imports emotion. It would then export that instance of emotion tied to a sheet. You could then import this instance of emotion in your individual components.
@tkh44 π€ that's an interesting idea, I'll give it a try in a few days!
Sorry to appear out of nowhere ππ¨
I've been looking for this feature in oss css-in-js libs for awhile, and would be happy to help out any way I can!
I anticipate that exposing this would require the babel plugin to accept further configuration. It could, for example, be given a set of alternative css
signatures to look for? This becomes more important when multiple output static css files are expected.
My reason for caring is in the collapsable at the bottom of this comment. It could be a broad-enough problem to warrant exposing an Emotion class & adding extra functionality to the babel-plugin.
Thoughts? I'm keen to jump on this if you're willing to accept it in to emotion! :)
emotion
version: 8react
version: n/aI'm currently evaluating different CSS-in-JS solutions and one thing that seems missing from most is a mode where you create an instance of the sheet/registry and manage styles using this instance instead of relying on a global singleton.
Why do I need this? Aside from "global shared mutable state is bad" etc. I maintain Catalog, a style guide builder that can render components from your codebase (similar to Storybook). Catalog itself is a React app and currently uses Radium which I want to replace for several reasons. Because users can include any code, I need to make sure that the replacement styling library doesn't conflict with anything else, including other versions of the same library.
Something like this could work, probably even without breaking existing API:
The
Emotion
instance basically would expose the same methods like the emotion/index module does.Alternatively,
css
et al. could take the instance as an additional argument.The
key
option has two purposes:<style data-emotion="my-key">
instead of<style data-emotion>
)css-
(although this could be a distinct option)Other aspects:
destroy
method which would clean up styles managed by it.For reference, styletron and fela already work like this.