Skip to content

Commit

Permalink
make promotion preview adjustable to board size
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Oct 15, 2023
1 parent 3c853fa commit e40dea8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/components/boards/PromotionModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Stack, ActionIcon } from "@mantine/core";
import { ActionIcon, SimpleGrid } from "@mantine/core";
import { useClickOutside } from "@mantine/hooks";
import { BISHOP, KNIGHT, PieceSymbol, QUEEN, ROOK, Square } from "chess.js";
import { memo } from "react";
Expand Down Expand Up @@ -62,32 +62,33 @@ const PromotionModal = memo(function PromotionModal({
style={{
position: "absolute",
zIndex: 100,
width: "12.5%",
height: "50%",
left: `${(file - 1) * 12.5}%`,
top: rank === 1 ? "50%" : "0%",
background: "rgba(255,255,255,0.8)",
}}
>
<Stack spacing={0}>
<SimpleGrid cols={1} spacing={0} verticalSpacing={0} h={"100%"}>
{promotionPieces.map((p) => (
<ActionIcon
key={p}
w="100%"
h="100%"
pos="relative"
// pos="relative"
onClick={() => {
confirmMove(p);
}}
>
<Piece
size={75}
piece={{
type: p,
color: turn === "white" ? "w" : "b",
}}
/>
</ActionIcon>
))}
</Stack>
</SimpleGrid>
</div>
</>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/components/common/Piece.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ export default function PieceComponent({
piece: Piece;
boardRef?: React.RefObject<HTMLDivElement>;
putPiece?: (square: Square, piece: Piece) => void;
size: number;
size?: number | string;
}) {
size = size ?? "100%";
const pieceRef = useRef<HTMLDivElement>(null);
if (!boardRef || !putPiece) {
return (
Expand Down

0 comments on commit e40dea8

Please sign in to comment.