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,52 +4,41 @@ import ActorPopover from './ActorPopover';
|
||||
|
||||
export default function GameGrid({ grid, width, middle }) {
|
||||
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">
|
||||
<table id="actors">
|
||||
<tbody>
|
||||
{grid.map((row, rowIndex) => {
|
||||
if (row.separator !== undefined) {
|
||||
return (
|
||||
<tr key={rowIndex} className="separator-row">
|
||||
{Array.from({ length: middle }, (_, i) => (
|
||||
<td key={i} />
|
||||
))}
|
||||
<td className="letter-static separator-char">
|
||||
{row.separator === ' ' ? '' : row.separator}
|
||||
</td>
|
||||
{Array.from({ length: width - middle }, (_, i) => (
|
||||
<td key={middle + 1 + i} />
|
||||
))}
|
||||
</tr>
|
||||
);
|
||||
}
|
||||
|
||||
<div className="game-grid-scroll">
|
||||
<table id="actors">
|
||||
<tbody>
|
||||
{grid.map((row, rowIndex) => {
|
||||
if (row.separator !== undefined) {
|
||||
return (
|
||||
<GameRow
|
||||
key={rowIndex}
|
||||
actorName={row.actorName}
|
||||
pos={row.pos}
|
||||
colStart={middle - row.pos}
|
||||
totalWidth={width}
|
||||
/>
|
||||
<tr key={rowIndex} className="separator-row">
|
||||
<td className="hint-cell" />
|
||||
{Array.from({ length: middle }, (_, i) => (
|
||||
<td key={i} />
|
||||
))}
|
||||
<td className="letter-static separator-char">
|
||||
{row.separator === ' ' ? '' : row.separator}
|
||||
</td>
|
||||
{Array.from({ length: width - middle }, (_, i) => (
|
||||
<td key={middle + 1 + i} />
|
||||
))}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<GameRow
|
||||
key={rowIndex}
|
||||
actorName={row.actorName}
|
||||
pos={row.pos}
|
||||
colStart={middle - row.pos}
|
||||
totalWidth={width}
|
||||
hintType={row.hintType}
|
||||
hintText={row.hintText}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import React, { useRef, useCallback, useMemo } from 'react';
|
||||
import LetterInput from './LetterInput';
|
||||
import ActorPopover from './ActorPopover';
|
||||
|
||||
function isLetter(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 letters = actorName.split('');
|
||||
|
||||
@@ -28,6 +29,9 @@ export default function GameRow({ actorName, pos, colStart, totalWidth }) {
|
||||
|
||||
return (
|
||||
<tr>
|
||||
<td className="hint-cell">
|
||||
<ActorPopover hintType={hintType} hintText={hintText} />
|
||||
</td>
|
||||
{Array.from({ length: totalWidth + 1 }, (_, colIndex) => {
|
||||
const charIndex = colIndex - colStart;
|
||||
const isInRange = charIndex >= 0 && charIndex < letters.length;
|
||||
|
||||
Reference in New Issue
Block a user