Linaria vs Vanilla-Extract #139
Closed
silviogutierrez
announced in
RFC
Replies: 2 comments
-
Latest update, unless something drastically changes with Linaria's babel usage: I've settled on vanilla-extract and will explore also integrating Tailwind. Lack of colocation is a problem, but the sprinkles API helps a lot. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Removed support for linaria in #311 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently Reactivated supports two zero-runtime CSS-in-JS solutions. Because these require tooling, they are built-in to the compilation process and require special plugins.
The goal is to support only one.
Some good background reading: https://github.com/andreipfeiffer/css-in-js#linaria and https://github.com/andreipfeiffer/css-in-js#vanilla-extract
Background
Below is some background and high level overview of each library. Afterwards there's more open-ended thoughts on both.
Linaria
Linaria is basically styled-components but statically compiled to a plain CSS files.
Pros
css
tag insideclassName
and style things.styled
API allows creating components easily.Cons
This last point is a major concern for Reactivated, as we promote type-safety everywhere. Though there are workarounds.
Vanilla-Extract
Vanilla Extract is a newer library with similar principles to Linaria, but a different approach.
Pros
Cons
styled.div
or similar API for quickly creating components.Thoughts
Basically, what we want is a mix of these two libraries. Obviously, it doesn't exist. I cannot stress enough how pleasant colocation is. Being able to apply styles directly on elements without having to name things is a dream come true. Of course, for often-enough used components you can abstract them away and give them proper names. But a separate file is a pain.
The best example of this is spacing around a element, using the
gap
property.That's with Linaria. With Vanilla Extract we would need two files:
It's nicely typed. But we also had to come up with the name
features
. This is very annoying. Doesn't seem like a big deal, right? You're listing features after all, just name it features. Imagine we need to create a second row, for more features, with a differentgap
.With colocation and linaria just add another div,
css
call, and you're done.With Vanilla Extract, you now need to think for a synonym. Is it...
highlights
? Is it...moreFeatures
?Not all is rosy with Linaria
Conversely, trying to type Linaria code is ugly. Real ugly.
On my projects, I have a helper defined as such:
Which lets me call a "typed" version of linaria using this hack:
It's even uglier if you need conditional classes, due to sibling
css
calls:And of course, it's a convention. Other than writing a linter rule, there's no way to enforce it.
Our options
It seems near impossible to make Vanilla Extract support colocation. The tailwind-like approach they recommend is interesting though.
On the other hand, Linaria will probably always need Babel. However, extending Linaria to support calling
style()
directly seems realtively easy to do. If you know how do this, contact me directly. I'll happily pay for for your contributions.Then again, maybe it's best to encourage Vanilla Extract and utility classes in a single, global file. For very specific styles, yes, create a
HomePage.css
and have to deal with naming things. The speed and first-class typing should help lessen the pain.Beta Was this translation helpful? Give feedback.
All reactions