I have a component where I want Vue to ignore the class that was already there and use the inherited class instead. But only if the class is of the same type as the inherited class. Here is an example of what I mean:
I have a button component like this
MyButton.vue
<button class="text-sm font-roboto justify-center text-red-500">
<slot></slot>
</button>
Then in my project I would like to use MyButton
component but I want to override the justify-center
and text-red-500
classes with my own, for example like this:
<MyButton class="justify-start text-gray-100">click me</MyButton>
The result is this rendered button:
<button class="text-sm font-roboto justify-center text-red-500 justify-start text-gray-100">
click me
</button>
The problem is that HTML prioritizes the class justify-center
and justify-start
class is ignored. I would like Vue to be smart enough that it understands Tailwind classes and if it sees that there was justify-center
originally and now I pass in justify-start
then it should remove justify-center
and add justify-start
.
I also want it to do this for all Tailwind classes. If it sees that there was originally a text-....
class then it should remove that and replace it with the inherited class. Same for fonts
and colors
and shadows
etc.
So the result would be like this:
<button class="text-sm font-roboto justify-start text-gray-100">
click me
</button>