Skip to content

Commit

Permalink
Merge pull request #13 from jorendorff/grid-size
Browse files Browse the repository at this point in the history
Make the CSS adapt to grid size.
  • Loading branch information
skedwards88 committed Oct 17, 2023
2 parents ca0fa7d + 3c334e1 commit 8a4ddf5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
58 changes: 34 additions & 24 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* General */
html {
--box-size: min(8vw, 5.5vh);
--default-font-size: calc(var(--box-size) * 0.9);
--default-box-size: min(8vw, 5.5vh);
--default-font-size: calc(var(--default-box-size) * 0.9);
--dark-color: rgb(55 54 71);
--shadow-color: rgba(20 19 25 / 50%);
--drag-color: rgba(77 76 99);
Expand Down Expand Up @@ -176,7 +176,7 @@ input[type="range"]:focus::-ms-fill-upper {
align-items: center;
grid-area: controls;
width: 100vw;
height: calc(var(--box-size) * 1.2);
height: calc(var(--default-box-size) * 1.2);
border-bottom: 2px solid var(--light-color);
}

Expand Down Expand Up @@ -296,6 +296,10 @@ a {

#game {
display: grid;
--box-size: min(
calc(66vh / var(--grid-rows)),
calc(96vw / var(--grid-columns))
);
grid-area: game;
grid-template-areas:
"board"
Expand All @@ -305,16 +309,21 @@ a {
-webkit-user-select: none;
}

#board,
#drag-group,
.piece {
display: grid;
grid-template-columns: repeat(var(--grid-columns), var(--box-size));
grid-template-rows: repeat(var(--grid-rows), var(--box-size));
width: calc(var(--grid-columns) * var(--box-size));
height: calc(var(--grid-rows) * var(--box-size));
}

#board {
overflow: hidden;
grid-area: board;
display: grid;
touch-action: none;
justify-content: center;
grid-template-columns: repeat(12, var(--box-size));
grid-template-rows: repeat(12, var(--box-size));
width: fit-content;
height: fit-content;
justify-self: center;
color: var(--light-color);
border: 1px solid var(--light-color);
Expand All @@ -327,7 +336,7 @@ a {
touch-action: none;
align-items: center;
justify-content: center;
font-size: var(--default-font-size);
font-size: calc(0.9 * var(--box-size));
background-color: var(--dark-color);
color: var(--light-color);
}
Expand Down Expand Up @@ -361,8 +370,12 @@ a {
#pool {
grid-area: pool;
width: 100%;
height: calc(88vh - (var(--box-size) * 12) - (var(--box-size) * 1.2));
height: calc(98svh - (var(--box-size) * 12) - (var(--box-size) * 1.2));
height: calc(
88vh - (var(--box-size) * var(--grid-rows)) - (var(--box-size) * 1.2)
);
height: calc(
98svh - (var(--box-size) * var(--grid-rows)) - (var(--box-size) * 1.2)
);
display: flex;
overflow-x: hidden;
overflow-y: scroll;
Expand All @@ -373,15 +386,9 @@ a {
}

.piece {
display: grid;
touch-action: none;
pointer-events: none;
grid-template-columns: repeat(var(--numCols), var(--box-size));
grid-template-rows: repeat(var(--numRows), var(--box-size));
justify-content: center;
font-size: var(--default-font-size);
width: fit-content;
height: fit-content;
align-content: center;
}

Expand All @@ -395,12 +402,7 @@ a {
}

#drag-group {
display: grid;
touch-action: none;
grid-template-columns: repeat(var(--group-columns), var(--box-size));
grid-template-rows: repeat(var(--group-rows), var(--box-size));
width: fit-content;
height: fit-content;
}

#drag-group .letter {
Expand Down Expand Up @@ -571,7 +573,7 @@ body:has(#drag-group) {
border-width: 0 2px 0 0;
align-items: center;
height: 100%;
width: calc(var(--box-size) * 1.5);
width: calc(var(--default-box-size) * 1.5);
}

#exitDailyButton {
Expand All @@ -588,7 +590,15 @@ body:has(#drag-group) {
/* Large screen */
@media (min-height: 800px) and (min-width: 800px) {
html {
--box-size: min(4vh, 7vw, 1cm);
--default-box-size: min(4vh, 7vw, 1cm);
}

#game {
--box-size: min(
calc(48vh / var(--grid-rows)),
calc(84vw / var(--grid-columns)),
1cm
);
}

#controls {
Expand Down
4 changes: 2 additions & 2 deletions src/components/DragGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ export default function DragGroup({ dispatchGameState, gameState }) {
position: "absolute",
top,
left,
"--group-rows": groupRows,
"--group-columns": groupColumns,
"--grid-rows": groupRows,
"--grid-columns": groupColumns,
}}
onPointerMove={onPointerMove}
onLostPointerCapture={onLostPointerCapture}
Expand Down
4 changes: 2 additions & 2 deletions src/components/DragShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export default function DragShadow({ grid, top, left }) {
}

const styles = {
"--numRows": grid.length,
"--numCols": grid[0].length,
"--grid-rows": grid.length,
"--grid-columns": grid[0].length,
};
// For the drag shadow on the board, need to specify the position of shadow on the board
if (top !== undefined) {
Expand Down
8 changes: 7 additions & 1 deletion src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ function Game({ dispatchGameState, gameState, setDisplay }) {
/>
) : null;
return (
<div id="game">
<div
id="game"
style={{
"--grid-rows": gameState.gridSize,
"--grid-columns": gameState.gridSize,
}}
>
<Board
pieces={gameState.pieces}
gridSize={gameState.gridSize}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Piece.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ export default function Piece({
id={`piece-${piece.id}`}
className="piece"
style={{
"--numRows": `${letters.length}`,
"--numCols": `${letters[0].length}`,
"--grid-rows": `${letters.length}`,
"--grid-columns": `${letters[0].length}`,
...layoutStyle,
}}
>
Expand Down

0 comments on commit 8a4ddf5

Please sign in to comment.