Skip to content

Commit 34b393d

Browse files
Fix Yahtzee dice overflowing the box on narrow mobile screens
Dice were sized with a single fixed breakpoint that didn't account for all phone widths, and the click wrapper div wasn't a real flex item so the dice couldn't shrink at all. Dice now flex to fit the row at any width, with percentage-based padding/pips that scale with die size. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent b743407 commit 34b393d

1 file changed

Lines changed: 19 additions & 27 deletions

File tree

src/client/pages/Yahtzee.tsx

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,9 @@ const Panel = styled.div`
155155

156156
const DiceRow = styled.div`
157157
display: flex;
158-
gap: 12px;
158+
gap: 8px;
159159
justify-content: center;
160160
margin-bottom: 16px;
161-
@media (max-width: 420px) {
162-
gap: 8px;
163-
}
164161
`;
165162

166163
const shake = keyframes`
@@ -170,15 +167,17 @@ const shake = keyframes`
170167
`;
171168

172169
const DieWrap = styled.div<{ $held: boolean; $clickable: boolean; $shaking: boolean; $blank: boolean }>`
173-
width: 70px;
174-
height: 70px;
170+
flex: 1 1 0;
171+
min-width: 0;
172+
max-width: 70px;
173+
aspect-ratio: 1 / 1;
175174
border: 2px solid ${(p) => (p.$blank ? "#eee" : p.$held ? "#337ab7" : "#ccc")};
176175
border-radius: 10px;
177176
background: ${(p) => (p.$blank ? "#fafafa" : p.$held ? "#eff5ff" : "#fff")};
178177
display: grid;
179178
grid-template-columns: repeat(3, 1fr);
180179
grid-template-rows: repeat(3, 1fr);
181-
padding: 9px;
180+
padding: 12%;
182181
cursor: ${(p) => (p.$clickable ? "pointer" : "default")};
183182
transition:
184183
border-color 0.15s,
@@ -205,25 +204,16 @@ const DieWrap = styled.div<{ $held: boolean; $clickable: boolean; $shaking: bool
205204
background: #dbe9ff;
206205
`}
207206
}
208-
@media (max-width: 420px) {
209-
width: 56px;
210-
height: 56px;
211-
padding: 7px;
212-
}
213207
`;
214208

215209
const Pip = styled.div<{ $on: boolean }>`
216210
width: 100%;
217211
height: 100%;
218-
max-width: 14px;
219-
max-height: 14px;
212+
max-width: 30%;
213+
max-height: 30%;
220214
border-radius: 50%;
221215
background: ${(p) => (p.$on ? "#222" : "transparent")};
222216
margin: auto;
223-
@media (max-width: 420px) {
224-
max-width: 11px;
225-
max-height: 11px;
226-
}
227217
`;
228218

229219
const Controls = styled.div`
@@ -376,15 +366,17 @@ function Die({
376366
held,
377367
clickable,
378368
shaking,
369+
onClick,
379370
}: {
380371
value: number;
381372
held: boolean;
382373
clickable: boolean;
383374
shaking: boolean;
375+
onClick: () => void;
384376
}) {
385377
const pips = PIPS[value] ?? [];
386378
return (
387-
<DieWrap $held={held} $clickable={clickable} $shaking={shaking} $blank={value === 0}>
379+
<DieWrap $held={held} $clickable={clickable} $shaking={shaking} $blank={value === 0} onClick={onClick}>
388380
{Array.from({ length: 9 }, (_, i) => (
389381
<Pip key={i} $on={pips.includes(i)} />
390382
))}
@@ -507,14 +499,14 @@ export default function Yahtzee() {
507499
<Panel>
508500
<DiceRow>
509501
{dice.map((d, i) => (
510-
<div key={i} onClick={() => toggleHold(i)}>
511-
<Die
512-
value={d}
513-
held={held[i]}
514-
clickable={hasRolled && !isRolling && rollsLeft > 0}
515-
shaking={isRolling && !held[i]}
516-
/>
517-
</div>
502+
<Die
503+
key={i}
504+
value={d}
505+
held={held[i]}
506+
clickable={hasRolled && !isRolling && rollsLeft > 0}
507+
shaking={isRolling && !held[i]}
508+
onClick={() => toggleHold(i)}
509+
/>
518510
))}
519511
</DiceRow>
520512
<Controls>

0 commit comments

Comments
 (0)