Spaces:
Sleeping
Sleeping
File size: 1,865 Bytes
100a6dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import * as React from 'react';
import { playSound } from '../services/soundService';
interface PromotionDialogProps {
isOpen: boolean;
position: { x: number; y: number };
color: 'white' | 'black';
onSelect: (piece: string) => void;
onCancel: () => void;
}
const PromotionDialog: React.FC<PromotionDialogProps> = ({
isOpen,
position,
color,
onSelect,
onCancel
}) => {
if (!isOpen) return null;
const pieces = ['queen', 'rook', 'bishop', 'knight'];
const handleSelect = (piece: string) => {
playSound('promote');
onSelect(piece);
};
// Position the dialog near the promotion square
const style: React.CSSProperties = {
position: 'absolute',
left: `${position.x}px`,
top: `${position.y}px`,
transform: 'translate(-50%, -50%)',
zIndex: 1000
};
return (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50" onClick={onCancel}>
<div
className="bg-white rounded-lg shadow-lg p-4 flex flex-col items-center"
style={style}
onClick={(e) => e.stopPropagation()}
>
<h3 className="text-lg font-medium mb-3">Promote to</h3>
<div className="grid grid-cols-2 gap-2">
{pieces.map((piece) => (
<div
key={piece}
className="w-16 h-16 flex items-center justify-center border rounded cursor-pointer hover:bg-gray-100"
onClick={() => handleSelect(piece)}
>
<div
className="w-12 h-12 bg-contain bg-center bg-no-repeat"
style={{ backgroundImage: `url(/assets/pieces/${color[0]}_${piece}_1x.png)` }}
/>
</div>
))}
</div>
</div>
</div>
);
};
export default PromotionDialog; |