labyrinth-frontend/src/Cell.js

30 lines
970 B
JavaScript
Raw Normal View History

import React, {useState} from 'react';
2023-04-14 02:01:55 +02:00
export default function Cell({spec, rowIndex, cellIndex, showSolution}) {
const [mark, setMark] = useState(false);
2023-04-14 02:01:55 +02:00
let classes = "cell r" + rowIndex + " c" + cellIndex;
if (spec.top) classes += " top";
if (spec.right) classes += " right";
if (spec.bottom) classes += " bottom";
if (spec.left) classes += " left";
if (spec.solution && showSolution) classes += " solution";
if (mark) classes += " user";
2023-04-14 02:01:55 +02:00
return (
<div className={classes}
onMouseEnter={(e) => {
const leftPressed = e.buttons & 0x1;
if (leftPressed) {
setMark(!mark);
}
}}
onMouseLeave={(e) => {
const leftPressed = e.buttons & 0x1;
if (leftPressed) {
}
}}
onClick={(e) => {
setMark(!mark);
}}/>
2023-04-14 02:01:55 +02:00
);
}