Improving variants
#140
Closed
hbriese
started this conversation in
Feature Requests
Replies: 1 comment
-
Hello, and thank you for opening this discussion. I'm open to extending the API, but only if we can achieve additional benefits, such as supporting compound variants. The issue with the API you proposed is that it allows you to select only a single property. You have 13 lines of code per style, but with a more verbose API, you can actually save some lines. It may not work for a single property, but for a larger group, it's a different story. I don't want to enforce tools like ts-pattern, as they are opinionated. It's challenging to create a small API that fits all. |
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
-
Unistyles has been a great addition to the ecosystem, and I thought I'd provide my observations on the
variants
api after using them for a bit. It'd be great for this to be a richer discussion beyond my proposalvariants
are too verboseVariants were a great addition to v2, but are quite verbose & cumbersome.
To me, their primary benefit seems to be injecting variables into the whole stylesheet, instead of per-style with dynamic style functions.
Proposed api
Variables are provided to
createStyleSheet
directly, resembling dynamic styles functions but at stylesheet level+ Less code (13 LOC vs 35)
+ More composable.
ts-pattern
is shown here+ No need to repeat all variants in all styles
- Explicit typing required when declaring stylesheet
Note that this doesn't necessarily have to be a breaking change
An object could be used instead of `ts-pattern`, or whatever may be appropriate
Beta Was this translation helpful? Give feedback.
All reactions