Overriding Tailwind CSS Classes in a Reusable VueJS Component #1951
Replies: 3 comments
-
|
I'm doing this for React and the approach I'm following is to provide an external theme config, and if people want to change any of the base styles, they can do it there. The components then get their styles from that file. like button-base-style: 'py-2 px-6 rounded-lg',
button-primary-color: 'bg-purple-600 text-white',In my case, I only provide one colored button, so there is not much change. If you think your component will have many styles, I would provide just a base style button, and then people add their styles. If the same custom component is then used frequently, it can be encapsulated like |
Beta Was this translation helpful? Give feedback.
-
|
@thecodeclimber I'm dealing with this same issue in React and published an experimental package yesterday to handle these overrides if you want to check it out: https://github.com/mariusmarais/tailwind-cascade |
Beta Was this translation helpful? Give feedback.
-
|
Proper fix for this issue: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have created a VueJS button component using TailwindCSS. My goal is to provide that button component with some base styles (using tailwindcss classes), with the option to override them when need be (again, using tailwind css classes).
For example, here is a simplified version of the
Buttoncomponent:And here is an example of my using that component in another file:
The problem is that this only half-works. That is to say,
bg-blue-600does override thebg-green-500that I set up as a default inButton.vue. Butbg-red-600does not override the background color (presumbably, becausebg-red-600comes earlier in the css source code.As such, I am wondering how can I properly set this up? That is to say, how can I give the
Buttoncomponent some base styles (again, using tailwind css classes) while also providing the option to override those styles using tailwind css classes.Thanks.
Beta Was this translation helpful? Give feedback.
All reactions