Skip to content

Commit d81cf54

Browse files
Support scores above ten in the match nav (#13818)
* Support scores above ten in the match nav
1 parent 9a4a35c commit d81cf54

File tree

3 files changed

+59
-80
lines changed

3 files changed

+59
-80
lines changed

dotcom-rendering/src/components/Score.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@ export const Default = () => {
2020
<Score score={9} />
2121
<Score score={10} />
2222
<Score score={11} />
23-
<p>^ We only go up to 10 at the moment 🤷‍♀</p>
23+
<Score score={12} />
24+
<Score score={13} />
25+
<Score score={14} />
26+
<Score score={15} />
27+
<Score score={16} />
28+
<Score score={17} />
29+
<Score score={18} />
30+
<Score score={31} />
31+
<Score score={0.5} />
32+
<Score score={NaN} />
2433
</>
2534
);
2635
};
Lines changed: 45 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/react';
2-
import { text } from '@guardian/source/foundations';
2+
import { palette } from '../palette';
33
import { Eight } from './numbers/Eight';
44
import { Five } from './numbers/Five';
55
import { Four } from './numbers/Four';
@@ -12,103 +12,69 @@ import { Three } from './numbers/Three';
1212
import { Two } from './numbers/Two';
1313
import { Zero } from './numbers/Zero';
1414

15+
const ScoreStyles = ({ children }: { children: React.ReactNode }) => (
16+
<div
17+
css={css`
18+
position: relative;
19+
width: 3.75rem;
20+
height: 3.75rem;
21+
border-radius: 1.875rem;
22+
border: 0.0625rem solid ${palette('--football-score-border')};
23+
display: flex;
24+
align-items: center;
25+
justify-content: center;
26+
`}
27+
>
28+
{children}
29+
</div>
30+
);
31+
1532
type Props = {
1633
score: number;
1734
};
1835

19-
export const Score = ({ score }: Props) => {
20-
const ScoreStyles = ({ children }: { children: React.ReactNode }) => (
21-
<div
22-
css={css`
23-
position: relative;
24-
width: 3.75rem;
25-
height: 3.75rem;
26-
border-radius: 1.875rem;
27-
border: 0.0625rem solid ${text.primary};
28-
29-
svg {
30-
position: absolute;
31-
top: 0;
32-
left: 0;
33-
right: 0;
34-
bottom: 0;
35-
margin: auto;
36-
}
37-
`}
38-
>
39-
{children}
40-
</div>
41-
);
42-
43-
if (Number.isNaN(score)) return <ScoreStyles> </ScoreStyles>;
36+
const ScoreNumber = ({ score }: Props) => {
37+
if (!Number.isInteger(score) || score < 0) {
38+
return null;
39+
}
4440

4541
switch (score) {
4642
case 0:
47-
return (
48-
<ScoreStyles>
49-
<Zero />
50-
</ScoreStyles>
51-
);
43+
return <Zero />;
5244
case 1:
53-
return (
54-
<ScoreStyles>
55-
<One />
56-
</ScoreStyles>
57-
);
45+
return <One />;
5846
case 2:
59-
return (
60-
<ScoreStyles>
61-
<Two />
62-
</ScoreStyles>
63-
);
47+
return <Two />;
6448
case 3:
65-
return (
66-
<ScoreStyles>
67-
<Three />
68-
</ScoreStyles>
69-
);
49+
return <Three />;
7050
case 4:
71-
return (
72-
<ScoreStyles>
73-
<Four />
74-
</ScoreStyles>
75-
);
51+
return <Four />;
7652
case 5:
77-
return (
78-
<ScoreStyles>
79-
<Five />
80-
</ScoreStyles>
81-
);
53+
return <Five />;
8254
case 6:
83-
return (
84-
<ScoreStyles>
85-
<Six />
86-
</ScoreStyles>
87-
);
55+
return <Six />;
8856
case 7:
89-
return (
90-
<ScoreStyles>
91-
<Seven />
92-
</ScoreStyles>
93-
);
57+
return <Seven />;
9458
case 8:
95-
return (
96-
<ScoreStyles>
97-
<Eight />
98-
</ScoreStyles>
99-
);
59+
return <Eight />;
10060
case 9:
101-
return (
102-
<ScoreStyles>
103-
<Nine />
104-
</ScoreStyles>
105-
);
61+
return <Nine />;
10662
case 10:
63+
return <Ten />;
10764
default:
10865
return (
109-
<ScoreStyles>
110-
<Ten />
111-
</ScoreStyles>
66+
<>
67+
<ScoreNumber score={Math.trunc(score / 10)} />
68+
<ScoreNumber score={score % 10} />
69+
</>
11270
);
11371
}
11472
};
73+
74+
export const Score = ({ score }: Props) => {
75+
return (
76+
<ScoreStyles>
77+
<ScoreNumber score={score} />
78+
</ScoreStyles>
79+
);
80+
};

dotcom-rendering/src/paletteDeclarations.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6595,6 +6595,10 @@ const paletteColours = {
65956595
light: () => sourcePalette.sport[500],
65966596
dark: () => sourcePalette.sport[500],
65976597
},
6598+
'--football-score-border': {
6599+
light: () => sourcePalette.neutral[7],
6600+
dark: () => sourcePalette.neutral[7],
6601+
},
65986602
'--football-sub-text': {
65996603
light: () => sourcePalette.neutral[46],
66006604
dark: () => sourcePalette.neutral[73],

0 commit comments

Comments
 (0)