I am new to Qwik and trying to conditionally add/remove classes from items in my navbar component. The complication is that I'm using tailwind and I want to conditionally add/remove the tailwind class (using custom animations), but it seems to have no effect. I have read about doing something like this in React using clsx, but this doesn't appear to be available in Qwik. Is there any way to dynamically add the tailwind class or how else can I achieve the same result?
Component
import { $, component$, useStore } from '@builder.io/qwik';
import { Link } from '@builder.io/qwik-city';
export const Navigation = component$(() => {
const baseClass = "py-2 bg-white text-black w-[100px]";
const menuItems = useStore([
{ label: "Home", value: "/", class: baseClass },
{ label: "About", value: "/about", class: baseClass },
{ label: "Contact Us", value: "/contact", class: baseClass },
]);
const fadeout = $((num: number) => {
menuItems.forEach((ele, i) => {
if(i < num && !ele.class.includes("animate-fadeout")) {
ele.class = baseClass + " animate-fadeout";
}
})
});
const fadein = $((num: number) => {
menuItems.forEach((ele, i) => {
if(i < num && ele.class.includes("animate-fadeout")) {
ele.class = baseClass + " animate-fadein";
}
})
});
return (
<div class="flex flex-col space-y-2 py-2 bg-slate-500">
{menuItems.map((item, index) => (
<Link className={item.class} key={index} onMouseOver$={() => fadeout(index)} onMouseOut$={() => fadein(index)} href={item.value}>{item.label}</Link>
))}
</div>
)
});
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ['./src/**/*.{js,ts,jsx,tsx,mdx}'],
theme: {
extend: {
keyframes: {
fadein: {
'0%': { transform: 'translateY(-175%)', opacity: '0'},
'10%': { transform: 'translateY(-150%)', opacity: '1'},
'50%': { transform: 'translateY(0)'}
},
fadeout: {
'50%': { transform: 'translateY(-175%)', opacity: '0'},
'40%': { transform: 'translateY(-150%)', opacity: '1'},
'0%': { transform: 'translateY(0)'}
}
},
animation: {
fadeout: 'fadeout 1s ease-in-out 1',
fadein: 'fadein 1s ease-in-out 1',
}
},
},
plugins: [],
};