I want to reuse a component in react with tailwind but some presentation aspect of it is different in two places. I want to use similar things to dark:{class}. so I want to have something like variant_a:{class} in some places while variant_b:{class} on others. and when I call the component I want to specify which variant I’ll be using for that component such as class="variant_a".
I could create two components but I think this will be a more elegant solution. any ideas on how to achieve this?
2
Answers
You could register some static variants via a Tailwind plugin, like:
These could then be used like:
If you are following PostCSS installation, you can add a
@layer
in yourglobal.css
file where you have imported the tailwind base classes.@layer components
lets you extend the component layer to define your component classes to be used in the project.