Spaces:
Sleeping
Sleeping
File size: 1,334 Bytes
3568151 |
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 |
import React from 'react'
import { Color, PieceSymbol } from 'chess.js'
import { ChessPiece } from './ChessPiece'
import '../styles/PromotionDialog.css'
export const PromotionDialog: React.FC<{
isVisible: boolean
color: Color
onSelect: (piece: 'q' | 'r' | 'b' | 'n') => void
}> = ({
isVisible,
color,
onSelect
}) => {
if (!isVisible) return null
const promotionPieces: Array<{ type: 'q' | 'r' | 'b' | 'n'; symbol: string }> = [
{ type: 'q', symbol: color === 'w' ? 'β' : 'β' },
{ type: 'r', symbol: color === 'w' ? 'β' : 'β' },
{ type: 'b', symbol: color === 'w' ? 'β' : 'β' },
{ type: 'n', symbol: color === 'w' ? 'β' : 'β' }
]
return (
<div className="promotion-dialog-overlay">
<div className="promotion-dialog">
<div className="promotion-dialog-title">
Choose Promotion Piece
</div>
<div className="promotion-buttons">
{promotionPieces.map(({ type, symbol }) => (
<button
key={type}
className="promotion-button"
onClick={() => onSelect(type)}
>
<ChessPiece
piece={{ type: type as PieceSymbol, color }}
size={48}
/>
</button>
))}
</div>
</div>
</div>
)
} |