-
Notifications
You must be signed in to change notification settings - Fork 609
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
feat(module)!: use tailwind-merge
for class merging
#509
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
✅ Live Preview ready!
|
This was referenced Aug 14, 2023
benjamincanac
added a commit
that referenced
this pull request
Sep 7, 2023
very appreciated change, thank you so much |
Maybe worth noting this doesn't work in the app.config.ts (yet): see #628 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The goal of this PR is to improve the DX when overriding components classes.
ui
propThanks to tailwind-merge, the
ui
prop is smartly merged with the config. This means you don't have to rewrite everything.For example, the default preset of the
FormGroup
component is:If I want to change the font of the label, I would have to do this:
Now with the
tailwind-merge
, classes will be smartly merged so I can just write:Some breaking changes might occur where you've overridden the
:ui
prop, although it's unlikely as you'd rewrote the entire line anyway.class
Still thanks to
tailwind-merge
, when using theclass
attribute on a component, those are now smartly merged with the classes computed from theui
prop and theapp.config.ts
.When using for example a
Badge
component:<UBadge label="Badge" />
, the classes generated looks like this:inline-flex items-center font-medium rounded-md text-xs px-2 py-1 bg-primary-500 dark:bg-primary-400 text-white dark:text-gray-900
.Let's say you want to change the font, you can do so through the
ui
prop:<UBadge label="Badge" :ui="{ font: 'font-bold' }" />
and this would work perfectly fine.But, in some complex cases you might need to use the
class
attribute:<UBadge label="Badge" class="font-bold" />
. This would result in those classes:inline-flex items-center font-medium rounded-md text-xs px-2 py-1 bg-primary-500 dark:bg-primary-400 text-white dark:text-gray-900 font-bold
and wouldn't work as bothfont-medium
andfont-bold
are present andfont-medium
has higher priority in the CSS stylesheet.With this PR, the
class
attribute is merged and onlyfont-bold
will be present:inline-flex items-center rounded-md text-xs px-2 py-1 bg-primary-500 dark:bg-primary-400 text-white dark:text-gray-900 font-bold
.I apologize in advance as this might introduce a few breaking changes and is a bit of a step back from the previous versions:
Avatar
component aboutclass
not being applied to the wrapper element anymore but to theimg
tag itself because ofv-bind="$attrs"
andinheritAttrs: false
so you'd have to use:ui="{ wrapper: '...' }"
.input
,radio
, etc. tags. And if you look at the<input>
documentation for example, there are plenty.But after considerations I believe that when using the
class
attribute on a component, it should always apply to the wrapper HTML element and that overriding through:ui="{ wrapper: '...' }"
can be a pain.As
class
will no longer apply to the child element forAvatar
,Checkbox
,Input
,Radio
,Range
,Select
,SelectMenu
andTextarea
, a new prop has been added in each of those components. It is named after the target HTML tag:img-class
forAvatar
input-class
forCheckbox
,Input
,Radio
andRange
select-class
forSelect
andSelectMenu
textarea-class
forTextarea