From e3234b6f835a4142cb9425095c88f7ef5ebf4dc5 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Sat, 25 Jul 2026 23:13:40 -0400 Subject: [PATCH] Enter to submit. --- web/src/components/CardView.tsx | 50 ++++++++------------------------- web/src/components/Home.tsx | 6 ++++ web/src/styles.css | 27 +++++++++--------- 3 files changed, 31 insertions(+), 52 deletions(-) diff --git a/web/src/components/CardView.tsx b/web/src/components/CardView.tsx index e4edfed..e5f3b69 100644 --- a/web/src/components/CardView.tsx +++ b/web/src/components/CardView.tsx @@ -3,38 +3,6 @@ import { createPortal } from 'react-dom' import type { Card } from '../types' import { artFor, artUrlFor } from '../petArt' -// The suit's "hat" — the trade-in symbol printed on the real cards, tinted to -// the suit's colour. Drawn as a tiny sun-hat SVG so it scales crisply. -const SUIT_HAT: Record = { - red: { fill: '#e5563f', band: '#b62c1f' }, - blue: { fill: '#4d8ce3', band: '#2b5fb0' }, - yellow: { fill: '#f2c24d', band: '#d9992f' }, -} - -function SuitHat({ suit }: { suit: string }) { - const c = SUIT_HAT[suit] ?? SUIT_HAT.yellow - return ( - - - - - - ) -} - // The tier shown as a die face (1–6 pips), like the real cards' corner marker. const DIE_PIPS: Record = { 1: [[15, 15]], @@ -57,21 +25,25 @@ function TierDie({ tier }: { tier: number }) { ) } -// useFitText shrinks the effect text until it fits its band, so long abilities -// (and the smaller battle cards) render in full instead of being clipped by -// the fixed card height. It never grows past the CSS size, only shrinks toward -// a small floor, and re-fits when the band resizes (breakpoints, battle mode). +// useFitText shrinks text until it fits its box, so long abilities (and the +// smaller battle cards) render in full instead of being clipped by the fixed +// card height, and long single-line names shrink instead of wrapping. It +// checks both axes — the effect band wraps and overflows vertically, the +// (nowrap) name row overflows horizontally. It never grows past the CSS size, +// only shrinks toward a small floor, and re-fits when the box resizes +// (breakpoints, battle mode). function useFitText(dep: unknown) { const ref = useRef(null) useLayoutEffect(() => { const el = ref.current if (!el) return + const overflows = () => el.scrollHeight > el.clientHeight || el.scrollWidth > el.clientWidth const fit = () => { el.style.fontSize = '' let size = parseFloat(getComputedStyle(el).fontSize) const min = 6 - // Guard the loop; each step is 0.5px so ~40 covers any realistic band. - for (let i = 0; i < 40 && el.scrollHeight > el.clientHeight && size > min; i++) { + // Guard the loop; each step is 0.5px so ~40 covers any realistic box. + for (let i = 0; i < 40 && overflows() && size > min; i++) { size = Math.max(min, size - 0.5) el.style.fontSize = `${size}px` } @@ -284,7 +256,7 @@ export function CardView({
{card.suit ? ( - + ) : ( )} diff --git a/web/src/components/Home.tsx b/web/src/components/Home.tsx index b4b4c74..1216a6f 100644 --- a/web/src/components/Home.tsx +++ b/web/src/components/Home.tsx @@ -39,6 +39,9 @@ export function Home({ onSession }: { onSession: (s: Session) => void }) { maxLength={20} placeholder="Enter your name" onChange={(e) => setName(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter' && !busy) run(() => createGame(name)) + }} /> @@ -65,6 +68,9 @@ export function Home({ onSession }: { onSession: (s: Session) => void }) { maxLength={5} placeholder="CODE" onChange={(e) => setCode(e.target.value.toUpperCase())} + onKeyDown={(e) => { + if (e.key === 'Enter' && !busy && code.length === 5) run(() => joinGame(code, name)) + }} />