Skip to content

Commit 3e40dfd

Browse files
committed
Add match info component
1 parent 7bf9655 commit 3e40dfd

File tree

3 files changed

+134
-35
lines changed

3 files changed

+134
-35
lines changed

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import { css } from '@emotion/react';
12
import type { Meta, StoryObj } from '@storybook/react-webpack5';
23
import { allModes } from '../../.storybook/modes';
4+
import { table } from '../../fixtures/manual/footballTable';
35
import { matchStats } from '../../fixtures/manual/matchStats';
6+
import { grid } from '../grid';
7+
import { palette } from '../palette';
48
import { FootballMatchInfo as FootballMatchInfoComponent } from './FootballMatchInfo';
59

610
const meta = {
@@ -13,13 +17,36 @@ const meta = {
1317
},
1418
},
1519
},
20+
decorators: [
21+
(Story) => (
22+
<div
23+
css={css`
24+
background-color: ${palette(
25+
'--football-match-info-background',
26+
)};
27+
${grid.paddedContainer}
28+
`}
29+
>
30+
<div
31+
css={css`
32+
${grid.column.centre}
33+
padding-top: 10px;
34+
padding-bottom: 10px;
35+
`}
36+
>
37+
<Story />
38+
</div>
39+
</div>
40+
),
41+
],
1642
} satisfies Meta<typeof FootballMatchInfoComponent>;
1743

1844
export default meta;
1945
type Story = StoryObj<typeof meta>;
2046

21-
export const FootballMatchSummary = {
47+
export const FootballMatchInfo = {
2248
args: {
2349
match: matchStats,
50+
table,
2451
},
2552
} satisfies Story;
Lines changed: 106 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,115 @@
11
import { css } from '@emotion/react';
2-
import { from } from '@guardian/source/foundations';
3-
import { type FootballMatchStats } from '../footballMatchStats';
2+
import type {
3+
FootballMatchStats,
4+
FootballMatchTeamWithStats,
5+
} from '../footballMatchStats';
6+
import type { FootballTable as FootballTableData } from '../footballTables';
47
import { grid } from '../grid';
5-
import { palette } from '../palette';
8+
import { FootballMatchStat } from './FootballMatchStat';
9+
import { LeagueTable } from './LeagueTable';
610
import { Lineups } from './Lineups';
711

8-
const gridStyles = css`
9-
${grid.paddedContainer}
10-
position: relative;
11-
${from.tablet} {
12-
&::before,
13-
&::after {
14-
content: '';
15-
position: absolute;
16-
border-left: 1px solid ${palette('--article-border')};
17-
z-index: 1;
18-
top: 0;
19-
bottom: 0;
20-
}
21-
22-
&::after {
23-
right: 0;
24-
}
25-
}
26-
`;
27-
2812
type Props = {
2913
match: FootballMatchStats;
14+
table?: FootballTableData;
3015
};
3116

32-
export const FootballMatchInfo = ({ match }: Props) => (
33-
<main id="maincontent" css={gridStyles}>
34-
<div
35-
css={css`
36-
${grid.column.centre}
37-
`}
38-
>
39-
<Lineups matchStats={match} />
40-
</div>
41-
</main>
17+
function teamHasStats({
18+
shotsOffTarget,
19+
shotsOnTarget,
20+
fouls,
21+
corners,
22+
}: FootballMatchTeamWithStats) {
23+
return !(
24+
shotsOffTarget === 0 &&
25+
shotsOnTarget === 0 &&
26+
fouls === 0 &&
27+
corners === 0
28+
);
29+
}
30+
31+
export const FootballMatchInfo = ({ match, table }: Props) => {
32+
const showStats =
33+
teamHasStats(match.homeTeam) && teamHasStats(match.awayTeam);
34+
const showLineups =
35+
match.homeTeam.players.length > 0 && match.awayTeam.players.length > 0;
36+
return (
37+
<section aria-label={'match-info'}>
38+
{showStats && (
39+
<>
40+
<StatsContainer
41+
label="Possession"
42+
match={match}
43+
homeValue={match.homeTeam.possession}
44+
awayValue={match.awayTeam.possession}
45+
/>
46+
{/* Add Goal Attempts here */}
47+
<StatsContainer
48+
label="Corrners"
49+
match={match}
50+
homeValue={match.homeTeam.corners}
51+
awayValue={match.awayTeam.corners}
52+
/>
53+
<StatsContainer
54+
label="Fouls"
55+
match={match}
56+
homeValue={match.homeTeam.fouls}
57+
awayValue={match.awayTeam.fouls}
58+
/>
59+
</>
60+
)}
61+
62+
{showLineups && (
63+
<div
64+
css={css`
65+
padding-bottom: 10px;
66+
`}
67+
>
68+
<Lineups matchStats={match} />
69+
</div>
70+
)}
71+
{table && (
72+
<div
73+
css={css`
74+
padding-bottom: 10px;
75+
`}
76+
>
77+
<LeagueTable table={table} />
78+
</div>
79+
)}
80+
</section>
81+
);
82+
};
83+
84+
const StatsContainer = ({
85+
label,
86+
match,
87+
homeValue,
88+
awayValue,
89+
}: {
90+
label: string;
91+
match: FootballMatchStats;
92+
homeValue: number;
93+
awayValue: number;
94+
}) => (
95+
<div
96+
css={css`
97+
${grid.column.centre}
98+
padding-bottom: 10px;
99+
`}
100+
>
101+
<FootballMatchStat
102+
label={label}
103+
home={{
104+
teamName: match.homeTeam.name,
105+
teamColour: match.homeTeam.statsColour,
106+
value: homeValue,
107+
}}
108+
away={{
109+
teamName: match.awayTeam.name,
110+
teamColour: match.awayTeam.statsColour,
111+
value: awayValue,
112+
}}
113+
/>
114+
</div>
42115
);

dotcom-rendering/src/components/Lineups.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ const PlayerList = ({
150150

151151
const sectionStyles = css`
152152
border: 1px solid ${palette('--football-match-stat-border')};
153-
margin: ${space[2]}px;
154153
border-radius: 6px;
155154
156155
padding-top: 6px;

0 commit comments

Comments
 (0)