Skip to content

Commit 07be145

Browse files
committed
Support layout variations for use in different contexts
1 parent 430e440 commit 07be145

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,17 @@ export const ShownAsPercentage = {
6060
showPercentage: true,
6161
},
6262
} satisfies Story;
63+
64+
export const RaisedLabelOnDesktop = {
65+
args: {
66+
...Default.args,
67+
raiseLabelOnDesktop: true,
68+
},
69+
} satisfies Story;
70+
71+
export const LargeNumbersOnDesktop = {
72+
args: {
73+
...Default.args,
74+
largeNumbersOnDesktop: true,
75+
},
76+
} satisfies Story;

dotcom-rendering/src/components/FootballMatchStat.tsx

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { css } from '@emotion/react';
22
import {
3+
from,
34
palette,
45
textSansBold14,
6+
textSansBold15,
57
textSansBold20,
8+
textSansBold28,
69
visuallyHidden,
710
} from '@guardian/source/foundations';
811

@@ -23,18 +26,44 @@ const containerCss = css`
2326
`;
2427

2528
const headerCss = css`
26-
display: flex;
27-
justify-content: space-between;
29+
display: grid;
30+
grid-template-columns: auto 1fr auto;
31+
grid-template-areas: 'home-stat label away-stat';
2832
`;
2933

30-
const statCss = css`
31-
${textSansBold20};
32-
color: var(--match-stat-team-colour);
34+
const raiseLabelCss = css`
35+
${from.desktop} {
36+
grid-template-areas:
37+
'label label label'
38+
'home-stat . away-stat';
39+
}
3340
`;
3441

3542
const labelCss = css`
3643
${textSansBold14};
44+
grid-area: label;
45+
justify-self: center;
3746
color: ${palette.neutral[7]};
47+
${from.desktop} {
48+
${textSansBold15};
49+
}
50+
`;
51+
52+
const numberCss = css`
53+
${textSansBold20};
54+
grid-area: home-stat;
55+
color: var(--match-stat-team-colour);
56+
`;
57+
58+
const largeNumberCss = css`
59+
${from.desktop} {
60+
${textSansBold28}
61+
}
62+
`;
63+
64+
const awayStatCss = css`
65+
grid-area: away-stat;
66+
justify-self: end;
3867
`;
3968

4069
const chartCss = css`
@@ -61,6 +90,8 @@ type Props = {
6190
home: MatchStatistic;
6291
away: MatchStatistic;
6392
showPercentage?: boolean;
93+
raiseLabelOnDesktop?: boolean;
94+
largeNumbersOnDesktop?: boolean;
6495
};
6596

6697
const formatValue = (value: number, showPercentage: boolean) =>
@@ -71,15 +102,18 @@ export const FootballMatchStat = ({
71102
home,
72103
away,
73104
showPercentage = false,
105+
raiseLabelOnDesktop = false,
106+
largeNumbersOnDesktop = false,
74107
}: Props) => {
75108
const homePercentage = (home.value / (home.value + away.value)) * 100;
76109
const awayPercentage = (away.value / (home.value + away.value)) * 100;
77110

78111
return (
79112
<div css={containerCss}>
80-
<div css={headerCss}>
113+
<div css={[headerCss, raiseLabelOnDesktop && raiseLabelCss]}>
114+
<span css={labelCss}>{label}</span>
81115
<span
82-
css={statCss}
116+
css={[numberCss, largeNumbersOnDesktop && largeNumberCss]}
83117
style={{ '--match-stat-team-colour': home.teamColour }}
84118
>
85119
<span
@@ -91,9 +125,12 @@ export const FootballMatchStat = ({
91125
</span>
92126
{formatValue(home.value, showPercentage)}
93127
</span>
94-
<span css={labelCss}>{label}</span>
95128
<span
96-
css={statCss}
129+
css={[
130+
numberCss,
131+
awayStatCss,
132+
largeNumbersOnDesktop && largeNumberCss,
133+
]}
97134
style={{ '--match-stat-team-colour': away.teamColour }}
98135
>
99136
<span

dotcom-rendering/src/components/FootballMiniMatchStats.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const FootballMiniMatchStats = ({
6666
value: stat.awayValue,
6767
}}
6868
showPercentage={stat.showPercentage}
69+
raiseLabelOnDesktop={true}
6970
/>
7071
))}
7172
<LinkButton

0 commit comments

Comments
 (0)