Replies: 1 comment 1 reply
-
The Tailwind way would be to have your Alert component handle the coloring. I don't code in Vue very often nowadays so please excuse the pseudo-code: <script setup>
const props = defineProps(['color'])
const COLORS = {
red: 'tw:bg-red-lighten6 tw:border-red-lighten5 tw:text-redtw:border-l-red',
green: 'tw:bg-green-lighten6 tw:border-green-lighten5 tw:text-green tw:border-l-green',
…
}
</script>
<div :class="`${COLORS[props.color]} …`"><!-- This would have been the old .alert--<color> element. --> |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
I roamed in this forum and in the issues section but I couldn't find exactly what I was looking for. Please let me know if you think the answer is somewhere else !
Context
I am trying to migrate a component library from TW3 to TW4 with:
Since I'm implementing a design system, I have components with color variations (
alert--red
,alert--green
, …).So far, with TW3, the previous devs were using SCSS to generate right classes:
And it worked just fine.
But from what I read, using pre-processors is not really tailwind-ish. So I read on how to replace SCSS.
I read here that inline style is the recommanded way but I was more attracted by using
@components
layer but the wildcard (as@utility
) seems to not be designed that way :So I considered using the layer
utilities
accepting that my components classes would be at the same level as TW utilities. Something so:--> This is "dynamic" enough to me and it actually works fine when the utility is defined in the global
style.css
. Nevertheless as soon as I move it to the style block of the SFC "Alert.vue" it seems it is not compiled anymore.Reproduction
Here I tried:
Questions
1/ Is it not really "tailwind-ish" to attempt to do so ? I liked the idea that my components implements their own color variation class though…
2/ What do you think about using SCSS to cover that case ?
Thanks for reading :)
Beta Was this translation helpful? Give feedback.
All reactions