-
Notifications
You must be signed in to change notification settings - Fork 30
Football mini match stats component #14947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
4b46eb5
Basic layout and styling for match stat
jamesmockett c6485d6
Add divider to chart
jamesmockett 3ed08d7
Move hardcoded values to props
jamesmockett fea9e47
Calculate bar width
jamesmockett 7e717c2
Include team name for accessibility
jamesmockett 84bd29d
Add FootballMiniMatchStats components
jamesmockett 2d351d0
Update match stat stories
jamesmockett 473ae25
Simplified live grid layout for stories
jamesmockett 7cedda5
Rename stories
jamesmockett cc8b882
Support layout variations for use in different contexts
jamesmockett b14252b
Hide chart from assistive technology
jamesmockett 9fb48ed
Add football stat colours to palette
jamesmockett 82f550b
Update dark mode palette based on latest designs
jamesmockett 2e12445
Add button hover colours to palette
jamesmockett d191ad7
Remove console log
jamesmockett 3cf1ac5
Use spacing from Source where possible
jamesmockett 94f2852
Incorrect team name being used for home stat
jamesmockett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
dotcom-rendering/src/components/FootballMatchStat.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { space } from '@guardian/source/foundations'; | ||
| import type { Meta, StoryObj } from '@storybook/react-webpack5'; | ||
| import { palette } from '../palette'; | ||
| import { FootballMatchStat } from './FootballMatchStat'; | ||
|
|
||
| const meta = { | ||
| title: 'Components/Football Match Stat', | ||
| component: FootballMatchStat, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div | ||
| css={css` | ||
| padding: ${space[4]}px; | ||
| background-color: ${palette( | ||
| '--football-live-blog-background', | ||
| )}; | ||
| `} | ||
| > | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| viewport: { | ||
| defaultViewport: 'mobileMedium', | ||
| }, | ||
| }, | ||
| } satisfies Meta<typeof FootballMatchStat>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const Default = { | ||
| args: { | ||
| label: 'Goal Attempts', | ||
| home: { | ||
| teamName: 'Manchester United', | ||
| teamColour: '#da020e', | ||
| value: 7, | ||
| }, | ||
| away: { | ||
| teamName: 'Arsenal', | ||
| teamColour: '#023474', | ||
| value: 4, | ||
| }, | ||
| }, | ||
| } satisfies Story; | ||
|
|
||
| export const ShownAsPercentage = { | ||
| args: { | ||
| label: 'Possession', | ||
| home: { | ||
| teamName: 'West Ham', | ||
| teamColour: '#722642', | ||
| value: 39, | ||
| }, | ||
| away: { | ||
| teamName: 'Newcastle', | ||
| teamColour: '#383838', | ||
| value: 61, | ||
| }, | ||
| showPercentage: true, | ||
| }, | ||
| } satisfies Story; | ||
|
|
||
| export const RaisedLabelOnDesktop = { | ||
| args: { | ||
| ...Default.args, | ||
| raiseLabelOnDesktop: true, | ||
| }, | ||
| } satisfies Story; | ||
|
|
||
| export const LargeNumbersOnDesktop = { | ||
| args: { | ||
| ...Default.args, | ||
| largeNumbersOnDesktop: true, | ||
| }, | ||
| } satisfies Story; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { | ||
| from, | ||
| space, | ||
| textSansBold14, | ||
| textSansBold15, | ||
| textSansBold20, | ||
| textSansBold28, | ||
| visuallyHidden, | ||
| } from '@guardian/source/foundations'; | ||
| import { palette } from '../palette'; | ||
|
|
||
| const containerCss = css` | ||
| position: relative; | ||
| padding: 5px 10px 10px; | ||
| border: 1px solid ${palette('--football-match-stat-border')}; | ||
| border-radius: 6px; | ||
| &::before { | ||
| position: absolute; | ||
| content: ''; | ||
| left: 50%; | ||
| bottom: 0; | ||
| width: 1px; | ||
| height: ${space[6]}px; | ||
| background-color: ${palette('--football-match-stat-border')}; | ||
| } | ||
| `; | ||
|
|
||
| const headerCss = css` | ||
| display: grid; | ||
| grid-template-columns: auto 1fr auto; | ||
| grid-template-areas: 'home-stat label away-stat'; | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `; | ||
|
|
||
| const raiseLabelCss = css` | ||
| ${from.desktop} { | ||
| grid-template-areas: | ||
| 'label label label' | ||
| 'home-stat . away-stat'; | ||
| } | ||
| `; | ||
|
|
||
| const labelCss = css` | ||
| ${textSansBold14}; | ||
| grid-area: label; | ||
| justify-self: center; | ||
| color: ${palette('--football-match-stat-name')}; | ||
| ${from.desktop} { | ||
| ${textSansBold15}; | ||
| } | ||
| `; | ||
|
|
||
| const numberCss = css` | ||
| ${textSansBold20}; | ||
| grid-area: home-stat; | ||
| color: var(--match-stat-team-colour); | ||
| `; | ||
|
|
||
| const largeNumberCss = css` | ||
| ${from.desktop} { | ||
| ${textSansBold28} | ||
| } | ||
| `; | ||
|
|
||
| const awayStatCss = css` | ||
| grid-area: away-stat; | ||
| justify-self: end; | ||
| `; | ||
|
|
||
| const chartCss = css` | ||
| position: relative; | ||
| display: flex; | ||
| gap: 10px; | ||
| `; | ||
|
|
||
| const barCss = css` | ||
| height: ${space[2]}px; | ||
| width: var(--match-stat-percentage); | ||
| background-color: var(--match-stat-team-colour); | ||
| border-radius: 8px; | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `; | ||
|
|
||
| type MatchStatistic = { | ||
| teamName: string; | ||
| teamColour: string; | ||
| value: number; | ||
| }; | ||
|
|
||
| type Props = { | ||
| label: string; | ||
| home: MatchStatistic; | ||
| away: MatchStatistic; | ||
| showPercentage?: boolean; | ||
| raiseLabelOnDesktop?: boolean; | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| largeNumbersOnDesktop?: boolean; | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const formatValue = (value: number, showPercentage: boolean) => | ||
| `${value}${showPercentage ? '%' : ''}`; | ||
|
|
||
| export const FootballMatchStat = ({ | ||
| label, | ||
| home, | ||
| away, | ||
| showPercentage = false, | ||
| raiseLabelOnDesktop = false, | ||
| largeNumbersOnDesktop = false, | ||
| }: Props) => { | ||
| const homePercentage = (home.value / (home.value + away.value)) * 100; | ||
| const awayPercentage = (away.value / (home.value + away.value)) * 100; | ||
|
|
||
| return ( | ||
| <div css={containerCss}> | ||
| <div css={[headerCss, raiseLabelOnDesktop && raiseLabelCss]}> | ||
| <span css={labelCss}>{label}</span> | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <span | ||
| css={[numberCss, largeNumbersOnDesktop && largeNumberCss]} | ||
| style={{ '--match-stat-team-colour': home.teamColour }} | ||
| > | ||
| <span | ||
| css={css` | ||
| ${visuallyHidden} | ||
jamesmockett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `} | ||
| > | ||
| {home.teamName} | ||
| </span> | ||
| {formatValue(home.value, showPercentage)} | ||
| </span> | ||
| <span | ||
| css={[ | ||
| numberCss, | ||
| awayStatCss, | ||
| largeNumbersOnDesktop && largeNumberCss, | ||
| ]} | ||
| style={{ '--match-stat-team-colour': away.teamColour }} | ||
| > | ||
| <span | ||
| css={css` | ||
| ${visuallyHidden} | ||
| `} | ||
| > | ||
| {away.teamName} | ||
| </span> | ||
| {formatValue(away.value, showPercentage)} | ||
| </span> | ||
| </div> | ||
| <div aria-hidden="true" css={chartCss}> | ||
| <div | ||
| css={barCss} | ||
| style={{ | ||
| '--match-stat-percentage': `${homePercentage}%`, | ||
| '--match-stat-team-colour': home.teamColour, | ||
| }} | ||
| ></div> | ||
| <div | ||
| css={barCss} | ||
| style={{ | ||
| '--match-stat-percentage': `${awayPercentage}%`, | ||
| '--match-stat-team-colour': away.teamColour, | ||
| }} | ||
| ></div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
75 changes: 75 additions & 0 deletions
75
dotcom-rendering/src/components/FootballMiniMatchStats.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { css } from '@emotion/react'; | ||
| import { breakpoints, from } from '@guardian/source/foundations'; | ||
| import type { Meta, StoryObj } from '@storybook/react-webpack5'; | ||
| import { palette } from '../palette'; | ||
| import { FootballMiniMatchStats as FootballMiniMatchStatsComponent } from './FootballMiniMatchStats'; | ||
|
|
||
| const gridCss = css` | ||
| background-color: ${palette('--football-live-blog-background')}; | ||
| /** | ||
| * Extremely simplified live blog grid layout as we're only interested in | ||
| * the 240px wide left column added at the desktop breakpoint. | ||
| * dotcom-rendering/src/layouts/LiveLayout.tsx | ||
| */ | ||
| ${from.desktop} { | ||
| display: grid; | ||
| grid-column-gap: 20px; | ||
| grid-template-columns: 240px 1fr; | ||
| } | ||
| `; | ||
|
|
||
| const containerCss = css` | ||
| padding: 10px; | ||
| ${from.desktop} { | ||
| padding-left: 20px; | ||
| padding-right: 0; | ||
| } | ||
| `; | ||
|
|
||
| const meta = { | ||
| title: 'Components/Football Mini Match Stats', | ||
| component: FootballMiniMatchStatsComponent, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <div css={gridCss}> | ||
| <div css={containerCss}> | ||
| <Story /> | ||
| </div> | ||
| </div> | ||
| ), | ||
| ], | ||
| parameters: { | ||
| chromatic: { | ||
| viewports: [ | ||
| breakpoints.mobileMedium, | ||
| breakpoints.tablet, | ||
| breakpoints.wide, | ||
| ], | ||
| }, | ||
| }, | ||
| } satisfies Meta<typeof FootballMiniMatchStatsComponent>; | ||
|
|
||
| export default meta; | ||
| type Story = StoryObj<typeof meta>; | ||
|
|
||
| export const FootballMiniMatchStats = { | ||
| args: { | ||
| homeTeam: { | ||
| name: 'Manchester United', | ||
| colour: '#da020e', | ||
| }, | ||
| awayTeam: { | ||
| name: 'Arsenal', | ||
| colour: '#023474', | ||
| }, | ||
| stats: [ | ||
| { | ||
| label: 'Possession', | ||
| homeValue: 39, | ||
| awayValue: 61, | ||
| showPercentage: true, | ||
| }, | ||
| { label: 'Goal Attempts', homeValue: 7, awayValue: 4 }, | ||
| ], | ||
| }, | ||
| } satisfies Story; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.