diff --git a/apps/frontend/src/components/board/BoardView.tsx b/apps/frontend/src/components/board/BoardView.tsx index 630d05e..bd8566e 100644 --- a/apps/frontend/src/components/board/BoardView.tsx +++ b/apps/frontend/src/components/board/BoardView.tsx @@ -14,12 +14,19 @@ const BoardView: FunctionComponent<{ boardViewModel: BoardViewModel; revert: boolean; onPitSelect: (index: number, pit: Pit) => void; -}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect }) => { + // Width in px, e.g. for previews; by default the board is as wide as the viewport. + width?: number; +}> = ({ game, context, boardId, boardViewModel, revert, onPitSelect, width }) => { const mancalaGame = game?.mancalaGame; const theme = context.themeManager.theme; - // Compute pit width based on viewport (each column is 11vw) - const pitWidth = typeof window !== "undefined" ? window.innerWidth * 0.11 : 100; + // The board is 92 units wide (8 columns of 11 plus padding); all board parts are sized in units. + const unit = width !== undefined ? width / 92 : (typeof window !== "undefined" ? window.innerWidth / 100 : 10); + const pitWidth = unit * 11; + const sizeVariables = { + "--board-unit": width !== undefined ? `${unit}px` : "1vw", + "--board-spacing": width !== undefined ? `${unit * 0.3}px` : "5px", + } as React.CSSProperties; const createPitView = (key: any, pit: Pit, pitViewModel: PitViewModel) => ( +
{` .board { - padding: 2vw; + padding: calc(2 * var(--board-unit)); display: grid; - grid-template-columns: repeat(8, 11vw); - grid-template-rows: repeat(2, 11vw); - border-radius: 3vw; + grid-template-columns: repeat(8, calc(11 * var(--board-unit))); + grid-template-rows: repeat(2, calc(11 * var(--board-unit))); + border-radius: calc(3 * var(--board-unit)); transition: background-color 0.5s; } `} diff --git a/apps/frontend/src/components/board/PitView.tsx b/apps/frontend/src/components/board/PitView.tsx index 052e9c4..1029084 100644 --- a/apps/frontend/src/components/board/PitView.tsx +++ b/apps/frontend/src/components/board/PitView.tsx @@ -53,9 +53,9 @@ const PitView: FunctionComponent = ({ pitViewModel, context, onCli )} diff --git a/apps/frontend/src/components/board/StoreView.tsx b/apps/frontend/src/components/board/StoreView.tsx index 850f3ef..358be1a 100644 --- a/apps/frontend/src/components/board/StoreView.tsx +++ b/apps/frontend/src/components/board/StoreView.tsx @@ -34,8 +34,8 @@ const StoreView: FunctionComponent<{
diff --git a/docs/specs/game-history/design.md b/docs/specs/game-history/design.md index 3dc88b7..4c78fd1 100644 --- a/docs/specs/game-history/design.md +++ b/docs/specs/game-history/design.md @@ -166,7 +166,7 @@ not spectators (R4.5). ### Board size `BoardView` gets an optional `width` (px). All board components size themselves from a CSS variable -`--board-unit` (default `1vw`, else `width / 100` px) instead of `vw`, so the same board renders at full width in a +`--board-unit` (default `1vw`, else `width / 92` px, the board being 92 units wide) instead of `vw`, so the same board renders at full width in a game and small in previews. ### Home page (`routes/Home.tsx`) diff --git a/docs/specs/game-history/tasks.md b/docs/specs/game-history/tasks.md index 7ded402..8e4cff9 100644 --- a/docs/specs/game-history/tasks.md +++ b/docs/specs/game-history/tasks.md @@ -17,7 +17,7 @@ Work through the tasks in order; each ends with its tests passing and a commit. unit tests. - [x] 7. **API**: public ids, Bearer auth middleware, `/games/me/active`, `/games/me`, `/games/popular`, `/game/:id` for finished games, live games channel with throttled push; tests. -- [ ] 8. **Board size**: `--board-unit` in `BoardView`, `PitView`, `StoreView`, `StoneView`; `width` prop. +- [x] 8. **Board size**: `--board-unit` in `BoardView`, `PitView`, `StoreView`, `StoneView`; `width` prop. - [ ] 9. **Home page**: `ActiveGameBanner`, `LiveGamesSection` with live updates, `RecentGamesSection`; lobby rejection message. - [ ] 10. **Live game history**: `MoveList`, review mode with `ReviewBanner` and keyboard, timeout countdown.