@@ -3,12 +3,7 @@ import { Fragment } from 'react';
33import { useChessboardContext } from './ChessboardProvider' ;
44import { getRelativeCoords } from './utils' ;
55
6- type Props = {
7- boardWidth : number | undefined ;
8- boardHeight : number | undefined ;
9- } ;
10-
11- export function Arrows ( { boardWidth, boardHeight } : Props ) {
6+ export function Arrows ( ) {
127 const {
138 id,
149 arrows,
@@ -21,9 +16,8 @@ export function Arrows({ boardWidth, boardHeight }: Props) {
2116 newArrowOverSquare,
2217 } = useChessboardContext ( ) ;
2318
24- if ( ! boardWidth ) {
25- return null ;
26- }
19+ const viewBoxWidth = 2048 ;
20+ const viewBoxHeight = viewBoxWidth * ( chessboardRows / chessboardColumns ) ;
2721
2822 const currentlyDrawingArrow =
2923 newArrowStartSquare &&
@@ -42,11 +36,12 @@ export function Arrows({ boardWidth, boardHeight }: Props) {
4236
4337 return (
4438 < svg
45- width = { boardWidth }
46- height = { boardHeight }
39+ viewBox = { `0 0 ${ viewBoxWidth } ${ viewBoxHeight } ` }
4740 style = { {
4841 position : 'absolute' ,
4942 top : '0' ,
43+ right : '0' ,
44+ bottom : '0' ,
5045 left : '0' ,
5146 pointerEvents : 'none' ,
5247 zIndex : '20' , // place above pieces
@@ -55,21 +50,21 @@ export function Arrows({ boardWidth, boardHeight }: Props) {
5550 { arrowsToDraw . map ( ( arrow , i ) => {
5651 const from = getRelativeCoords (
5752 boardOrientation ,
58- boardWidth ,
53+ viewBoxWidth ,
5954 chessboardColumns ,
6055 chessboardRows ,
6156 arrow . startSquare ,
6257 ) ;
6358 const to = getRelativeCoords (
6459 boardOrientation ,
65- boardWidth ,
60+ viewBoxWidth ,
6661 chessboardColumns ,
6762 chessboardRows ,
6863 arrow . endSquare ,
6964 ) ;
7065
7166 // we want to shorten the arrow length so the tip of the arrow is more central to the target square instead of running over the center
72- const squareWidth = boardWidth / chessboardColumns ;
67+ const squareWidth = viewBoxWidth / chessboardColumns ;
7368 let ARROW_LENGTH_REDUCER =
7469 squareWidth / arrowOptions . arrowLengthReducerDenominator ;
7570
0 commit comments