-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Create new "empty" variant #3298
Conversation
this will generate classes like the following: ```css .empty\:hidden:empty { display: none } ```
Was actually looking for this yesterday. Great for situations where you want to hide an empty box that has padding and borders. |
Not opposed to adding but could you also add tests in |
confirm generated output
Codecov Report
@@ Coverage Diff @@
## master #3298 +/- ##
=======================================
Coverage 93.28% 93.28%
=======================================
Files 178 178
Lines 1831 1831
Branches 324 323 -1
=======================================
Hits 1708 1708
Misses 105 105
Partials 18 18
Continue to review full report at Codecov.
|
Test has been added. I'm assuming the top of the |
Hey! So the way to think about For example, in this situation:
On hover, should the element go to opacity-100? Or should the fact that it's empty be considered more important? |
In Twind we use the following precedence (https://github.com/tw-in-js/twind/blob/main/src/twind/presedence.ts#L139) in ascending order (later override former):
For your example |
@sastan Does Twind support combinations like that out of the box? I couldn't get it working with the shim at least. I think |
Twind has no restriction on variant combinations. Here is a example for the empty hover case.
I'm no style or CSS expert. I used the following resources to create the order as it is:
I'm happy to adjust the precedence... |
I've had some time to think about this, and understand it a little better, so here's my thought process on why I moved it where I did. I see 2 kind of groupings in the I placed "empty" at the highest priority of the "static" variants. "empty" would probably be applied to elements that are more edge case, so it should take priority over the others. It should not take precedence over any of the "interactive" variants, though, because they represent user intent, and thus have higher priority. I see 2 common use cases for "empty":
<div class="p-2 bg-red-500 hover:bg-green-500 empty:hidden">Test</div>
<div class="p-2 bg-red-500 hover:bg-green-500 empty:hidden"></div>
<div class="p-4">
<table class="min-w-full rounded overflow-hidden">
<tr class="odd:bg-gray-500">
<td class="p-2 empty:bg-red-500">Row 1</td>
<td class="p-2">Row 1</td>
</tr>
<tr class="odd:bg-gray-500">
<td class="p-2 empty:bg-red-500"></td>
<td class="p-2">Row 2</td>
</tr>
<tr class="odd:bg-gray-500">
<td class="p-2 empty:bg-red-500">Row 3</td>
<td class="p-2">Row 3</td>
</tr>
</table>
</div> |
The variant will allow users to apply specific styling if an element is empty (has no element nodes or text, including whitespace).
https://developer.mozilla.org/en-US/docs/Web/CSS/:empty
this will generate classes like the following:
and could be used like this: