Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Feature/COR-1178: Change trend icons kpi tile (#4527)
Browse files Browse the repository at this point in the history
* 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
APW26 authored Dec 7, 2022
1 parent 855e52c commit ba45ba2
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/app/schema/topical/icon.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"AlcoholVerkoop",
"Archive",
"Arrow",
"ArrowWithIntensity",
"Arts",
"Avondklok",
"BarChart",
Expand Down
65 changes: 57 additions & 8 deletions packages/app/src/components/trend-icon.tsx
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};
}`}
`;
15 changes: 2 additions & 13 deletions packages/app/src/domain/topical/components/topical-tile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,14 @@ export function TopicalTile({ title, tileIcon, trendIcon, description, kpiValue,
>
{title}
{!formattedKpiValue && trendIcon.direction && trendIcon.color && (
<TrendIconWrapper color={mapStringToColors(trendIcon.color)}>
<TrendIcon trendDirection={getTrendDirection(trendIcon)} />
</TrendIconWrapper>
<TrendIcon trendDirection={getTrendDirection(trendIcon)} color={mapStringToColors(trendIcon.color)} intensity={trendIcon.intensity} />
)}
</Heading>
{formattedKpiValue && (
<Box display="flex" justifyContent="start" alignItems="center" marginTop={space[2]}>
<KpiValue color={colors.black} text={formattedKpiValue} />
{trendIcon.direction && trendIcon.color && (
<TrendIconWrapper color={mapStringToColors(trendIcon.color)}>
<TrendIcon trendDirection={getTrendDirection(trendIcon)} />
</TrendIconWrapper>
<TrendIcon trendDirection={getTrendDirection(trendIcon)} color={mapStringToColors(trendIcon.color)} intensity={trendIcon.intensity} />
)}
</Box>
)}
Expand Down Expand Up @@ -135,13 +131,6 @@ export function TopicalTile({ title, tileIcon, trendIcon, description, kpiValue,
);
}

const TrendIconWrapper = styled.span`
color: ${({ color }) => color};
flex-shrink: 0;
margin-left: ${space[2]};
width: 20px;
`;

const TileIcon = styled.span`
background-color: ${colors.blue8};
border-bottom-left-radius: ${space[1]};
Expand Down
1 change: 1 addition & 0 deletions packages/app/src/domain/topical/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export type TrendIconDirection = typeof ICON_DIRECTION_UP | typeof ICON_DIRECTIO
export type TrendIcon = {
direction: TrendIconDirection | null;
color: TrendIconColor | null;
intensity: 1 | 2 | 3 | null;
};
27 changes: 14 additions & 13 deletions packages/app/src/queries/get-topical-structure-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export function getTopicalStructureQuery(locale: string) {
const query = `// groq
{
'topicalConfig': *[
_type == 'topicalPageConfig' && !(_id in path("drafts.**"))
_type == 'topicalPageConfig' && !(_id in path('drafts.**'))
][0]{
'title': title.${locale},
'description': description.${locale}
},
'weeklySummary': *[
_type == 'weeklySummary' && !(_id in path("drafts.**"))
_type == 'weeklySummary' && !(_id in path('drafts.**'))
][0]{
'title': title.${locale},
'items': items[]->{
Expand All @@ -21,30 +21,31 @@ export function getTopicalStructureQuery(locale: string) {
},
},
'kpiThemes': *[
_type == 'themeCollection' && !(_id in path("drafts.**"))
_type == 'themeCollection' && !(_id in path('drafts.**'))
][0]{
'themes': themes[]->{
"title":title.${locale},
"subTitle":subTitle.${locale},
'title':title.${locale},
'subTitle':subTitle.${locale},
themeIcon,
'linksLabelMobile': labelMobile.${locale},
'linksLabelDesktop': labelDesktop.${locale},
"links":links[]->{
'links':links[]->{
'cta': {
'title': cta.title.${locale},
'href': cta.href
},
},
"tiles":tiles[]->{
"description":description.${locale},
'tiles':tiles[]->{
'description':description.${locale},
tileIcon,
"title":title.${locale},
"sourceLabel":sourceLabel.${locale},
'title':title.${locale},
'sourceLabel':sourceLabel.${locale},
'kpiValue': kpiValue.${locale},
'trendIcon': {
'color': trendIcon.color,
'direction': trendIcon.direction,
'intensity': trendIcon.intensity,
},
'cta': {
'title': cta.title.${locale},
Expand All @@ -54,7 +55,7 @@ export function getTopicalStructureQuery(locale: string) {
},
},
'measureTheme': *[
_type == 'measureTheme' && !(_id in path("drafts.**"))
_type == 'measureTheme' && !(_id in path('drafts.**'))
][0]{
'title': title.${locale},
themeIcon,
Expand All @@ -65,12 +66,12 @@ export function getTopicalStructureQuery(locale: string) {
},
},
'thermometer': *[
_type == 'thermometer' && !(_id in path("drafts.**"))
_type == 'thermometer' && !(_id in path('drafts.**'))
][0]{
icon,
'title': title.${locale},
'subTitle': subTitle.${locale},
"tileTitle":tileTitle.${locale},
'tileTitle':tileTitle.${locale},
currentLevel,
'thermometerLevels': thermometerLevels[]->{
'level': level,
Expand Down
15 changes: 15 additions & 0 deletions packages/cms/src/schemas/topical/trend-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,20 @@ export const trendIcon = {
},
validation: REQUIRED,
},
{
title: 'Intensiteit',
name: 'intensity',
description: 'Beschrijft de intensiteit van relatieve verandering ten opzichte van de vorige meeting.',
type: 'number',
options: {
list: [
{ value: 1, title: '1 pijltje gekleurd' },
{ value: 2, title: '2 pijltjes gekleurd' },
{ value: 3, title: '3 pijltjes gekleurd' },
],
layout: 'dropdown',
},
validation: REQUIRED,
},
],
};
1 change: 1 addition & 0 deletions packages/icons/icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ See below an overview of all the available icons in this package. This file is g
| AlcoholVerkoop | <div style="background-color: white;"><img src="./src/svg/alcohol_verkoop.svg" alt="AlcoholVerkoop" /></div> |
| Archive | <div style="background-color: white;"><img src="./src/svg/archive.svg" alt="Archive" /></div> |
| Arrow | <div style="background-color: white;"><img src="./src/svg/arrow.svg" alt="Arrow" /></div> |
| ArrowWithIntensity | <div style="background-color: white;"><img src="./src/svg/arrow_with_intensity.svg" alt="ArrowWithIntensity" /></div> |
| Arts | <div style="background-color: white;"><img src="./src/svg/arts.svg" alt="Arts" /></div> |
| Avondklok | <div style="background-color: white;"><img src="./src/svg/avondklok.svg" alt="Avondklok" /></div> |
| BarChart | <div style="background-color: white;"><img src="./src/svg/bar_chart.svg" alt="BarChart" /></div> |
Expand Down
2 changes: 2 additions & 0 deletions packages/icons/src/icon-name2filename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type IconName =
| 'AlcoholVerkoop'
| 'Archive'
| 'Arrow'
| 'ArrowWithIntensity'
| 'Arts'
| 'Avondklok'
| 'BarChart'
Expand Down Expand Up @@ -135,6 +136,7 @@ export const iconName2filename: Record<IconName, string> = {
AlcoholVerkoop: 'alcohol_verkoop.svg',
Archive: 'archive.svg',
Arrow: 'arrow.svg',
ArrowWithIntensity: 'arrow_with_intensity.svg',
Arts: 'arts.svg',
Avondklok: 'avondklok.svg',
BarChart: 'bar_chart.svg',
Expand Down
27 changes: 27 additions & 0 deletions packages/icons/src/svg/arrow_with_intensity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ba45ba2

Please sign in to comment.