This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/COR-1178: Change trend icons kpi tile (#4527)
* feat(theme-tiles): Adds a new field to select the intensity for the trend icon. * feat(theme-tiles): Adds a new field to the topical structure query and changes double quotes to single quotes. * feat(KPI-tiles): Adjusts the trend icon component to render out a new icon for the homepage which takes intensity level into consideration. Co-authored-by: VWSCoronaDashboard26 [email protected] * feat(KPI-tiles): Updates component name, adjusts styling, adds a comment. * feat(KPI-tiles): PR feedback: Added a comment, refactored styling, changed sanity labels. * feat(KPI-tiles): Remove no stroke comment and remove stroke property from intensity level 3.
- Loading branch information
Showing
9 changed files
with
120 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
"AlcoholVerkoop", | ||
"Archive", | ||
"Arrow", | ||
"ArrowWithIntensity", | ||
"Arts", | ||
"Avondklok", | ||
"BarChart", | ||
|
This file contains 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 |
---|---|---|
@@ -1,33 +1,82 @@ | ||
import { colors } from '@corona-dashboard/common'; | ||
import { Down, Dot, Up, ArrowWithIntensity } from '@corona-dashboard/icons'; | ||
import styled from 'styled-components'; | ||
import { useIntl } from '~/intl'; | ||
import { Down, Dot, Up } from '@corona-dashboard/icons'; | ||
import { space } from '~/style/theme'; | ||
|
||
export enum TrendDirection { | ||
UP, | ||
DOWN, | ||
NEUTRAL, | ||
} | ||
|
||
interface TrendIconProps { | ||
trendDirection: TrendDirection; | ||
intensity?: number | null; | ||
color?: string | null; | ||
ariaLabel?: string; | ||
} | ||
|
||
export const TrendIcon = ({ trendDirection, ariaLabel }: TrendIconProps) => { | ||
export const TrendIcon = ({ trendDirection, ariaLabel, intensity = null, color = null }: TrendIconProps) => { | ||
const { commonTexts } = useIntl(); | ||
|
||
const TrendLabelUp = ariaLabel || commonTexts.accessibility.visual_context_labels.up_trend_label; | ||
const TrendLabelDown = ariaLabel || commonTexts.accessibility.visual_context_labels.down_trend_label; | ||
const TrendLabelNeutral = ariaLabel || commonTexts.accessibility.visual_context_labels.neutral_trend_label; | ||
const trendLabels: { [key: string]: string } = { | ||
up: ariaLabel || commonTexts.accessibility.visual_context_labels.up_trend_label, | ||
down: ariaLabel || commonTexts.accessibility.visual_context_labels.down_trend_label, | ||
neutral: ariaLabel || commonTexts.accessibility.visual_context_labels.neutral_trend_label, | ||
}; | ||
|
||
const ariaLabelText = trendLabels[TrendDirection[trendDirection].toLowerCase()]; | ||
|
||
// Icon with intensity is used only on the homepage at the moment, for all other trend icons the default (below) are used. | ||
if (intensity && color && TrendDirection[trendDirection]) { | ||
return <TrendIconWithIntensity color={color} direction={trendDirection} intensity={intensity} />; | ||
} | ||
|
||
switch (trendDirection) { | ||
case TrendDirection.UP: | ||
return <Up aria-label={TrendLabelUp} />; | ||
return <Up aria-label={ariaLabelText} />; | ||
case TrendDirection.DOWN: | ||
return <Down aria-label={TrendLabelDown} />; | ||
return <Down aria-label={ariaLabelText} />; | ||
case TrendDirection.NEUTRAL: | ||
return <Dot aria-label={TrendLabelNeutral} />; | ||
return <Dot aria-label={ariaLabelText} />; | ||
default: { | ||
const exhaustiveCheck: never = trendDirection; | ||
throw new Error(`Unhandled TrendDirection case: ${exhaustiveCheck}`); | ||
} | ||
} | ||
}; | ||
|
||
const intensitySelectors: { [key: number]: { fill: string; stroke?: string } } = { | ||
1: { | ||
fill: '.one-arrow', | ||
stroke: '.two-stroke, .three-stroke', | ||
}, | ||
2: { | ||
fill: '.one-arrow, .two-arrows', | ||
stroke: '.three-stroke', | ||
}, | ||
3: { | ||
fill: '.one-arrow, .two-arrows, .three-arrows', | ||
}, | ||
}; | ||
|
||
interface TrendIconWithIntensityProps { | ||
color: string; | ||
direction: TrendDirection; | ||
intensity: number; | ||
} | ||
|
||
const TrendIconWithIntensity = styled(ArrowWithIntensity)<TrendIconWithIntensityProps>` | ||
flex-shrink: 0; | ||
margin-left: ${space[2]}; | ||
transform: ${({ direction }) => (direction === TrendDirection.DOWN ? 'scaleY(-1)' : undefined)}; | ||
${({ intensity, color }): string => | ||
`${intensitySelectors[intensity].fill} { | ||
fill: ${color}; | ||
} | ||
${intensitySelectors[intensity].stroke} { | ||
stroke: ${colors.gray7}; | ||
}`} | ||
`; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.