feature/add-user-interaction #3

Merged
manuel merged 4 commits from feature/add-user-interaction into main 2023-04-17 01:25:58 +02:00
Showing only changes of commit 4a4ff7522f - Show all commits

View file

@ -1,14 +1,29 @@
import React from 'react'; import React, {useState} from 'react';
export default function Cell({spec, rowIndex, cellIndex, showSolution}) { export default function Cell({spec, rowIndex, cellIndex, showSolution}) {
const [mark, setMark] = useState(false);
let classes = "cell r" + rowIndex + " c" + cellIndex; let classes = "cell r" + rowIndex + " c" + cellIndex;
if (spec.top) classes += " top"; if (spec.top) classes += " top";
if (spec.right) classes += " right"; if (spec.right) classes += " right";
if (spec.bottom) classes += " bottom"; if (spec.bottom) classes += " bottom";
if (spec.left) classes += " left"; if (spec.left) classes += " left";
if (spec.solution && showSolution) classes += " solution"; if (spec.solution && showSolution) classes += " solution";
if (spec.user) classes += " user"; if (mark) classes += " user";
return ( return (
<div className={classes}/> <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);
}}/>
); );
} }