app_totito_next/app/cuadros.js

57 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

2024-09-06 19:35:13 -06:00
import { useState } from "react";
2024-09-09 11:35:42 -06:00
const Cuadrado = ({ valor, alHacerClick }) => {
2024-09-06 19:35:13 -06:00
const [showMenu, setShowMenu] = useState(false);
const handleMouseEnter = () => {
setShowMenu(true);
};
const handleMouseLeave = () => {
setTimeout(() => {
if (!document.querySelector('.menu')?.contains(document.activeElement)) {
setShowMenu(false);
}
}, 100);
};
const handleSelect = (valor) => {
2024-09-09 11:35:42 -06:00
alHacerClick(valor);
2024-09-06 19:35:13 -06:00
setShowMenu(false);
};
return (
<div
className="relative w-16 h-16"
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
2024-09-06 12:19:33 -06:00
>
2024-09-06 19:35:13 -06:00
<button
2024-09-09 11:35:42 -06:00
className="shadow-xl w-full h-full text-black border border-gray-500 text-2xl font-extrabold flex items-center border-4 border-black justify-center bg-blue-900 rounded-xl"
2024-09-06 19:35:13 -06:00
onClick={() => setShowMenu(true)}
disabled={valor !== ''}
>
{valor}
</button>
{showMenu && (
<div className="menu absolute top-0 right-0 bg-white border border-gray-500 shadow-md p-2">
<button
className="block w-full text-center text-black p-1 hover:bg-gray-200"
onClick={() => handleSelect('X')}
>
X
</button>
<button
className="block w-full text-center text-black p-1 hover:bg-gray-200"
onClick={() => handleSelect('O')}
>
O
</button>
</div>
)}
</div>
);
};
2024-09-06 12:19:33 -06:00
2024-09-06 19:35:13 -06:00
export default Cuadrado;