Whenever my state in navbar changes, I would like to have the background of NavItems to be transparent when it's false, and add a gradient background when it's true.
I know that if it is normal CSS, I can just put 'NavItems active'
as my className
with ?
operator for if statement, but how do I do this with CSS module?
index.module.css
.NavItems{
background: transparent !important;
height: 100px;
display:flex;
justify-content:center;
align-items:center;
font-size: 1.5rem;
font-weight: bold;
position: sticky;
top:0;
z-index:300;
}
.NavItems.active{
background: linear-gradient(90deg, rgb(61,49,49) 0%, rgba(49,49,49,1)100%) !important;
}
index.jsx
return (
<nav className={navbar ? styles.active : styles.NavItems}>
<div>
<Link to='/'>
<img className={styles.NavLogo} src={logo} alt='LaoMa Logo'/>
</Link>
</div>
<div className={styles.menu_icon} onClick={handleClick}>
<i className={click ? 'fas fa-times' : 'fas fa-bars'}>
</i>
</div>
<ul className={click ? styles.nav_menu.active : styles.nav_menu}>
{NavItems.map((item, index)=> {
return (
<li key={index}>
<Link onClick={closeMobileMenu} className={styles[item.cName]} to={item.url}>
{item.title}
</Link>
</li>
)
})}
</ul>
</nav>
);