-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RFC: Compound Variants #8
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
This feature is nice but still makes the user account for all different component states and props. I think adding a way to make windstitches aware of TW classes like tailwind-merge does, would make this package so much better. Is that something that would align with the vision of the project? |
@wmonecke how do you imagine that coming to life? I'm not very familiar with |
Overview
After thinking about #2 issue of conflicting classNames, I started thinking of a solution. I came across Compound Variants concept, but at first, it didn't look like it could solve this specific problem. I didn't want to add more classNames, I wanted to connect variants and have no conflicts. But how?
Problem
Sometimes classNames conflicts. Here's an example:
In the above example we could never have a working
<Text theme="h1" weight="normal" />
as the evaluated className would be conflicting:text-8xl font-bold font-normal
. It would depend on how the CSS was structured to know which rule would be applied. That's no good.Solution
To solve that I'm adding
compoundVariants
, but a bit different from stiches' one.The compoundVariants map tells us what to select and what to apply. It takes a combination of variants keys and values and special
defaultTo
andclass
properties.Selection
Only 1 compound variant is selected at once. One case will override other if it is matched by more variants`
Example:
For props
{ theme: 'h1', color: 'yellow' }
the 2 will match, but onlycompoundVariant2
will be applied as it matches more variants.compoundVariant1
matches variant varianttheme
wherecompoundVariant2
matchestheme
andcolor
.The
defaultTo
updates the defaultVariantsFor
{ defaultVariants: { weight: 'normal' } }
a compoundedVariant containing{ defaultTo: { weight: 'bold' } }
, if matched, will override theweight
default variant. This means that we can still set it, but the default is now updated for that custom selection.The
class
appends classNamesA compounded variant with
{ class: 'xyz' }
will addxyz
to the evaluated classNames if matched.