Given the div structure
<div className={
`${style.cell}
${cell === Player.Black ? "black" : cell === Player.White ? "white" : ""}`}key={colIndex}/>
And the related CSS
.cell {
width: 30px;
height: 30px;
border: 1px solid #000;
background-color: burlywood;
cursor: pointer;
}
.black {
background-color: #000;
color: white;
text-align: center;
font-weight: bolder;
}
.white {
background-color: #fff;
color: black;
text-align: center;
font-weight: bolder;
}
How can I refer to the .cell.black
and .cell.white
class within the conditional using style...
similar to how I would if className
was
{`cell ${cell === Player.Black ? "black" : cell === Player.White ? "white" : ""}`}
and not located inside a module (ie import style from './Game.module.css'
)?
3
Answers
This accomplished what I needed and still inherited the properties of
.cell
You can refer to the .cell.black and .cell.white classes within the conditional using the following syntax:
You can refer to the following:
or you can make a function and return a CSS string like the one below:
const getCellStyle = () => {
return
cell ${cell === Player.Black ? " black" : cell === Player.White ? " white" : ""}
}