-
Notifications
You must be signed in to change notification settings - Fork 978
feat(module)!: use tailwind-merge for class merging
#509
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
Merged
Conversation
This file contains hidden or 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
Contributor
|
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 |
Contributor
|
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.
uipropThanks to tailwind-merge, the
uiprop is smartly merged with the config. This means you don't have to rewrite everything.For example, the default preset of the
FormGroupcomponent is:{ "label": { "base": "block font-medium text-gray-700 dark:text-gray-200" } }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
:uiprop, although it's unlikely as you'd rewrote the entire line anyway.classStill thanks to
tailwind-merge, when using theclassattribute on a component, those are now smartly merged with the classes computed from theuiprop and theapp.config.ts.When using for example a
Badgecomponent:<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
uiprop:<UBadge label="Badge" :ui="{ font: 'font-bold' }" />and this would work perfectly fine.But, in some complex cases you might need to use the
classattribute:<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-boldand wouldn't work as bothfont-mediumandfont-boldare present andfont-mediumhas higher priority in the CSS stylesheet.With this PR, the
classattribute is merged and onlyfont-boldwill 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:
Avatarcomponent aboutclassnot being applied to the wrapper element anymore but to theimgtag itself because ofv-bind="$attrs"andinheritAttrs: falseso 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
classattribute on a component, it should always apply to the wrapper HTML element and that overriding through:ui="{ wrapper: '...' }"can be a pain.As
classwill no longer apply to the child element forAvatar,Checkbox,Input,Radio,Range,Select,SelectMenuandTextarea, a new prop has been added in each of those components. It is named after the target HTML tag:img-classforAvatarinput-classforCheckbox,Input,RadioandRangeselect-classforSelectandSelectMenutextarea-classforTextarea