diff --git a/assets/react/controllers/GameRow.jsx b/assets/react/controllers/GameRow.jsx new file mode 100644 index 0000000..463780a --- /dev/null +++ b/assets/react/controllers/GameRow.jsx @@ -0,0 +1,43 @@ +import React, { useRef, useCallback } from 'react'; +import LetterInput from './LetterInput'; +import ActorPopover from './ActorPopover'; + +export default function GameRow({ actorName, pos, colStart, totalWidth }) { + const inputRefs = useRef([]); + + const setInputRef = useCallback((index) => (el) => { + inputRefs.current[index] = el; + }, []); + + const focusInput = useCallback((index) => { + inputRefs.current[index]?.focus(); + }, []); + + const letters = actorName.split(''); + + return ( + + {Array.from({ length: totalWidth + 1 }, (_, colIndex) => { + const charIndex = colIndex - colStart; + const isInRange = charIndex >= 0 && charIndex < letters.length; + + if (!isInRange) { + return ; + } + + return ( + focusInput(charIndex + 1)} + onPrev={() => focusInput(charIndex - 1)} + /> + ); + })} + + + + + ); +}