πΆοΈ Tailwind v4 & Writing classes instead of CSS-in-JS for addComponent
+ Aliasing classes
#12962
jd-solanki
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi ππ»
I love to use UnoCSS and Tailwind. However while using tailwind I miss some of the features of the UnoCSS which I would like to highlight which will me working with Tailwind breeze.
Before reading this, I want you to think that Tailwind is not just for Landing pages, It can be used everywhere and even for the sites which highly reuse the components. More accurate example will be using Tailwind for building UI library and what v4 can help improving existing API.
Shortcuts + unocss-transformer-alias
We can replace tailwind's
addComponent
feature with shortcuts which allows us to write classes rather than writing CSS-in-JS syntax.Talking about
unocss-transformer-alias
(coupled withaddComponents
), It allows use to write semantic classes (e.g.btn
,alert
) in source code that will get transformed into utility classes.Another question may arise why not use
@apply
. Let me ask you, Wouldn't be it much convinient to write shortcuts with classes rather than creating seperate CSS file and using @apply there. If you ask lib authors, Using shortcuts will be much easier to integrate in their plugin.Why
Shortcuts are better than addComponent, Here's proof.
Daisy UI uses
@apply
classes to style components rather than usingaddComponent
and CSS-in-JS.Shortcuts are faster to write understand and squzee last drop of convinience from tailwind
Regarding
unocss-transformer-alias
, when you just useaddComponent
it will generate CSS which won't be reusable however when you useunocss-transformer-alias
like thing this will reuse the existing utilities and won't impact performance if you are using lots ofaddComponent
.Beta Was this translation helpful? Give feedback.
All reactions