fix: integrate hint buttons into table for perfect row alignment and sticky scroll
Move hint buttons from a separate flex column into the table as the first <td> of each row, ensuring pixel-perfect alignment with grid rows. Use position:sticky with box-shadow to keep hints fixed on the left while scrolling horizontally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,19 +4,6 @@ import ActorPopover from './ActorPopover';
|
|||||||
|
|
||||||
export default function GameGrid({ grid, width, middle }) {
|
export default function GameGrid({ grid, width, middle }) {
|
||||||
return (
|
return (
|
||||||
<div className="game-grid-area">
|
|
||||||
<div className="hint-col">
|
|
||||||
{grid.map((row, rowIndex) => {
|
|
||||||
if (row.separator !== undefined) {
|
|
||||||
return <div key={rowIndex} className="hint-separator" />;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<div key={rowIndex} className="hint-cell">
|
|
||||||
<ActorPopover hintType={row.hintType} hintText={row.hintText} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<div className="game-grid-scroll">
|
<div className="game-grid-scroll">
|
||||||
<table id="actors">
|
<table id="actors">
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -24,6 +11,7 @@ export default function GameGrid({ grid, width, middle }) {
|
|||||||
if (row.separator !== undefined) {
|
if (row.separator !== undefined) {
|
||||||
return (
|
return (
|
||||||
<tr key={rowIndex} className="separator-row">
|
<tr key={rowIndex} className="separator-row">
|
||||||
|
<td className="hint-cell" />
|
||||||
{Array.from({ length: middle }, (_, i) => (
|
{Array.from({ length: middle }, (_, i) => (
|
||||||
<td key={i} />
|
<td key={i} />
|
||||||
))}
|
))}
|
||||||
@@ -44,12 +32,13 @@ export default function GameGrid({ grid, width, middle }) {
|
|||||||
pos={row.pos}
|
pos={row.pos}
|
||||||
colStart={middle - row.pos}
|
colStart={middle - row.pos}
|
||||||
totalWidth={width}
|
totalWidth={width}
|
||||||
|
hintType={row.hintType}
|
||||||
|
hintText={row.hintText}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import React, { useRef, useCallback, useMemo } from 'react';
|
import React, { useRef, useCallback, useMemo } from 'react';
|
||||||
import LetterInput from './LetterInput';
|
import LetterInput from './LetterInput';
|
||||||
|
import ActorPopover from './ActorPopover';
|
||||||
|
|
||||||
function isLetter(ch) {
|
function isLetter(ch) {
|
||||||
return /[a-zA-Z]/.test(ch);
|
return /[a-zA-Z]/.test(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GameRow({ actorName, pos, colStart, totalWidth }) {
|
export default function GameRow({ actorName, pos, colStart, totalWidth, hintType, hintText }) {
|
||||||
const inputRefs = useRef([]);
|
const inputRefs = useRef([]);
|
||||||
const letters = actorName.split('');
|
const letters = actorName.split('');
|
||||||
|
|
||||||
@@ -28,6 +29,9 @@ export default function GameRow({ actorName, pos, colStart, totalWidth }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<tr>
|
<tr>
|
||||||
|
<td className="hint-cell">
|
||||||
|
<ActorPopover hintType={hintType} hintText={hintText} />
|
||||||
|
</td>
|
||||||
{Array.from({ length: totalWidth + 1 }, (_, colIndex) => {
|
{Array.from({ length: totalWidth + 1 }, (_, colIndex) => {
|
||||||
const charIndex = colIndex - colStart;
|
const charIndex = colIndex - colStart;
|
||||||
const isInRange = charIndex >= 0 && charIndex < letters.length;
|
const isInRange = charIndex >= 0 && charIndex < letters.length;
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ body {
|
|||||||
#actors td {
|
#actors td {
|
||||||
width: var(--cell);
|
width: var(--cell);
|
||||||
height: var(--cell);
|
height: var(--cell);
|
||||||
|
padding: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
}
|
||||||
@@ -534,33 +535,26 @@ body {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.game-grid-area {
|
|
||||||
display: flex;
|
|
||||||
align-items: flex-start;
|
|
||||||
margin-top: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hint-col {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
padding-top: 5px;
|
|
||||||
gap: 5px;
|
|
||||||
flex-shrink: 0;
|
|
||||||
padding-right: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hint-cell {
|
.hint-cell {
|
||||||
height: var(--cell);
|
padding: 0;
|
||||||
display: flex;
|
position: sticky;
|
||||||
align-items: center;
|
left: 5px;
|
||||||
}
|
z-index: 1;
|
||||||
|
background: var(--surface);
|
||||||
.hint-separator {
|
box-shadow:
|
||||||
height: 12px;
|
-5px 0 0 var(--surface),
|
||||||
|
5px 0 0 var(--surface),
|
||||||
|
0 -5px 0 var(--surface),
|
||||||
|
0 5px 0 var(--surface),
|
||||||
|
-5px -5px 0 var(--surface),
|
||||||
|
5px -5px 0 var(--surface),
|
||||||
|
-5px 5px 0 var(--surface),
|
||||||
|
5px 5px 0 var(--surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
.game-grid-scroll {
|
.game-grid-scroll {
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
|
margin-top: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Game actions ── */
|
/* ── Game actions ── */
|
||||||
|
|||||||
Reference in New Issue
Block a user