I have a situation in my component where I need Vue to disregard the existing class and instead use the inherited class, but only if it is of the same type as the inherited class. Let me illustrate with an example:
Consider a button component like this
MyButton.vue
<button class="text-sm font-roboto justify-center text-red-500">
<slot></slot>
</button>
In my project, I want to use the MyButton
component but override the classes justify-center
and text-red-500
with my own, like so:
<MyButton class="justify-start text-gray-100">click me</MyButton>
This should result in the following button being rendered:
<button class="text-sm font-roboto justify-center text-red-500 justify-start text-gray-100">
click me
</button>
The issue arises when HTML prioritizes the class justify-center
over justify-start
. I wish for Vue to intelligently handle Tailwind classes, recognizing that if it originally had justify-center
and now I provide justify-start
, it should replace rather than add them both.
This behavior should extend to all Tailwind classes – replacing rather than adding original text-....
, font
, color
, shadow
, etc., classes with the new ones.
Therefore, the desired output would be:
<button class="text-sm font-roboto justify-start text-gray-100">
click me
</button>