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

Feature/COR-1263-table-consistency-implementations #4614

Merged
merged 24 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e034fc9
feat(consistency-improvements): Implement changes for vaccinations pe…
Jan 9, 2023
e870068
feat(consistency-improvements): Implement changes for variants table.
Jan 9, 2023
deb11e6
feat: WIP and behavior table improvements
Jan 11, 2023
01b6e42
feat(table adjustments): Created generic component for mobile tables.…
Jan 11, 2023
6991f7b
feat(table improvements): Finalize mobile table design.
Jan 16, 2023
66d9195
feat(table improvements): Implement mobile tables for autumn vaccine …
Jan 16, 2023
9e87d32
feat(table improvements): Implement mobile tables for all tables.
Jan 18, 2023
5c939e0
feat(table-improvements): Create and implement WideTable for behavior…
Jan 19, 2023
257dd0c
feat(table-improvements): Use WideTable for all vaccine coverage tables.
Jan 19, 2023
e026756
feat(table-improvements): Implement narrow and wide table for behavio…
Jan 20, 2023
59f353b
feat(table-improvements): Add new footers to behaviour page tables.
Jan 20, 2023
204522e
feat(table-improvements): Delete now unused duplicated components
Jan 20, 2023
60475b5
feat(table-improvements): Final touches - creating sanity keys, typin…
Jan 20, 2023
969306e
feat(table-improvements): Make optimizations based on discussions - C…
Jan 23, 2023
55be689
feat(table-improvements): Moves some files around.
Jan 23, 2023
689a52f
feat(table-consistency): Optimisations and PR feedback about dropdown…
Jan 26, 2023
9611cc2
feat(table-improvements): Convert all functions to arrow functions.
Jan 26, 2023
9c0f482
feat(table-improvements): PR feedback - adding comments, sorting type…
Jan 26, 2023
987fd9b
feat(table-improvements): PR feedback.
Jan 26, 2023
0426790
feat(table-improvements): Changes in design - added a column header f…
Jan 26, 2023
9935a38
feat(table-improvements): PR feedback part 78.
Jan 26, 2023
b104c73
Merge branch "develop" into feature/COR-1263-table-consistency-implem…
Jan 31, 2023
5f1ba02
feat(table-consistency): PR feedback.
Jan 31, 2023
3ba8f17
feat(table-consistency):Remove props again.
Jan 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/app/src/components/age-groups/age-group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Box } from '~/components/base';
import { BoldText, InlineText } from '~/components/typography';
import { useIntl } from '~/intl';
import { formatAgeGroupString } from '~/utils/format-age-group-string';
import { formatBirthyearRangeString } from '~/utils/format-birthyear-range-string';
import { replaceVariablesInText } from '~/utils/replace-variables-in-text';

interface AgeGroupProps {
range: string;
peopleInAgeGroup?: number;
birthYearRange: string;
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved
}

export function AgeGroup({ range, peopleInAgeGroup, birthYearRange }: AgeGroupProps) {
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved
const { commonTexts, formatNumber } = useIntl();
const ageRange = formatAgeGroupString(range, commonTexts.common.agegroup);
const yearOfBirthRange = formatBirthyearRangeString(birthYearRange, commonTexts.common.birthyears);

const totalText = replaceVariablesInText(commonTexts.common.agegroup.total_people, {
total: formatNumber(peopleInAgeGroup),
});

return (
<Box display="flex" flexDirection="column">
<BoldText>{ageRange}</BoldText>
<InlineText variant="label1">{`${yearOfBirthRange}${peopleInAgeGroup ? `: ${totalText}` : ''}`}</InlineText>
APW26 marked this conversation as resolved.
Show resolved Hide resolved
</Box>
);
}
92 changes: 34 additions & 58 deletions packages/app/src/components/percentage-bar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { css } from '@styled-system/css';
import styled from 'styled-components';
import { Box } from '~/components/base';
import { colors } from '@corona-dashboard/common';
import styled from 'styled-components';
import { space } from '~/style/theme';

interface PercentageProps {
percentage: number;
Expand All @@ -11,69 +11,45 @@ interface PercentageProps {
backgroundColor?: string;
}

export function PercentageBar({
percentage,
height,
color,
backgroundColor = colors.gray2,
backgroundStyle = 'normal',
}: PercentageProps) {
export function PercentageBar({ percentage, height, color, backgroundColor = colors.gray2, backgroundStyle = 'normal' }: PercentageProps) {
const minWidth = percentage > 0 ? '2px' : undefined;

backgroundColor =
backgroundStyle === 'normal'
? backgroundColor
? backgroundColor
: 'gray2'
: backgroundColor;
backgroundColor = backgroundStyle === 'normal' ? backgroundColor ? backgroundColor : 'gray2' : backgroundColor;
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved

return (
<Wrapper>
<Bar
style={{ width: `${percentage}%` }}
height={height}
minWidth={minWidth}
color={color}
/>

<Box
// Created by https://stripesgenerator.com/
css={css(
backgroundStyle === 'hatched'
? {
backgroundImage: `linear-gradient(45deg, ${backgroundColor} 30%, #ffffff 30%, #ffffff 50%, ${backgroundColor} 50%, ${backgroundColor} 80%, #ffffff 80%, #ffffff 100%)`,
backgroundSize: '7.07px 7.07px',
}
: {
backgroundColor,
}
)}
flex={1}
height={height}
top={0}
left={0}
/>
</Wrapper>
<Box display="flex" position="relative" width="100%">
<Bar style={{ width: `${percentage}%` }} height={height} minWidth={minWidth} color={color} />
<StyledDiv backgroundStyle={backgroundStyle} backgroundColor={backgroundColor} height={height} />
</Box>
);
}

const Wrapper = styled.div(
css({
display: 'flex',
position: 'relative',
width: '100%',
})
);
interface StyledDivProps {
backgroundStyle: string;
backgroundColor: string;
height?: string | number;
}

const StyledDiv = styled.div<StyledDivProps>`
/* Created by https://stripesgenerator.com/ */
background-color: ${({backgroundStyle, backgroundColor}) => backgroundStyle !== 'hatched' ? backgroundColor : undefined };
background-image: ${({backgroundStyle, backgroundColor}) => backgroundStyle === 'hatched' ? `linear-gradient(45deg, ${backgroundColor} 30%, #ffffff 30%, #ffffff 50%, ${backgroundColor} 50%, ${backgroundColor} 80%, #ffffff 80%, #ffffff 100%)` : undefined };
background-size: ${({backgroundStyle}) => backgroundStyle === 'hatched' ? '7.07px 7.07px' : undefined };
flex: 1;
height: ${({height}) => height ? height : undefined};
left: ${space[0]};
top: ${space[0]};
`;

const Bar = styled.div<{
interface BarProps {
height?: number | string;
minWidth?: string;
color?: string;
}>((x) =>
css({
backgroundColor: x.color ? x.color : 'currentcolor',
height: x.height ?? '0.8em',
minWidth: x.minWidth,
zIndex: 3,
})
);
}

const Bar = styled.div<BarProps>`
background-color: ${({color}) => color ? color : 'currentcolor'};
height: ${({height}) => height ?? '0.8em'};
min-width: ${({minWidth}) => minWidth};
transition: width .3s;
z-index: 3;
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Box } from '~/components/base';
import { BehaviorTrend } from '~/domain/behavior/components/behavior-trend';
import { NarrowPercentage } from '~/components/tables/components/narrow-percentage';
import { space } from '~/style/theme';
import { PercentageDataPoint } from '../types';
import { PercentageBarWithoutNumber } from './percentage-bar-without-number';

interface PercentageDataProps {
percentageDataPoints: PercentageDataPoint[];
}

// Component used to show percentage data on narrow screens.
export const PercentageData = ({ percentageDataPoints }: PercentageDataProps) => {
return (
<>
{percentageDataPoints.map((percentageDataPoint, index) => (
<Box display="flex" flexDirection="column" marginBottom={index === 0 ? space[2] : undefined} key={index}>
<Box display="flex" marginBottom={space[1]}>
<NarrowPercentage
value={
percentageDataPoint.trendDirection ? (
<BehaviorTrend trend={percentageDataPoint.trendDirection} text={`${percentageDataPoint.percentage.value}%`} />
) : (
percentageDataPoint.percentage.value
)
}
color={percentageDataPoint.percentage.color}
textLabel={percentageDataPoint.title}
/>
</Box>

{/* In some cases, the percentage value is a string so it needs to be parsed for the progress bar to be filled properly. */}
<PercentageBarWithoutNumber
percentage={typeof percentageDataPoint.percentage.value === 'number' ? percentageDataPoint.percentage.value : parseFloat(percentageDataPoint.percentage.value)}
color={percentageDataPoint.percentage.color}
/>
</Box>
))}
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Box } from '~/components/base';
import { InlineText } from '~/components/typography';
import { space } from '~/style/theme';

interface NarrowPercentageProps {
value: number | React.ReactNode;
color: string;
textLabel: string;
}

export function NarrowPercentage({ value, color, textLabel }: NarrowPercentageProps) {
return (
<Box display="grid" gridTemplateColumns="auto 2fr" width="100%">
<Box paddingRight={space[3]} minWidth="190px" textAlign="left">
<InlineText>{textLabel}:</InlineText>
</Box>

<Box display="flex" alignItems="center">
<Box width="10px" height="10px" backgroundColor={color} borderRadius="50%" marginRight={space[2]} />
{value}
</Box>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Box } from '~/components/base';
import { PercentageBar } from '~/components/percentage-bar';

interface PercentageBarWithoutNumberProps {
color: string;
percentage: number;
marginBottom?: string;
}

export const PercentageBarWithoutNumber = ({ color, percentage, marginBottom }: PercentageBarWithoutNumberProps) => {
return (
<Box display="flex" alignItems="center" spacingHorizontal={2} marginBottom={marginBottom}>
<Box color={color} flexGrow={1}>
<PercentageBar percentage={isNaN(percentage) ? 0 : percentage} height="8px" />
Amber-Taal-Work marked this conversation as resolved.
Show resolved Hide resolved
</Box>
</Box>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { colors } from '@corona-dashboard/common';
import styled from 'styled-components';
import { border, BorderProps, compose, display, DisplayProps, minWidth, MinWidthProps, width, WidthProps } from 'styled-system';
import { fontWeights, mediaQueries, space } from '~/style/theme';

export const Table = styled.table`
border-collapse: collapse;
width: 100%;
`;

export const TableHead = styled.thead`
border-bottom: 1px solid ${colors.gray2};
`;

type RowProps = DisplayProps;

export const Row = styled.tr<RowProps>`
flex-wrap: wrap;
justify-content: space-between;
${compose(display)};
`;

type HeaderCellProps = WidthProps & DisplayProps & MinWidthProps;

export const HeaderCell = styled.th<HeaderCellProps>`
border-bottom: 1px solid ${colors.gray2};
font-weight: ${fontWeights.bold};
padding-bottom: ${space[2]};
text-align: left;
vertical-align: middle;
${compose(display, width, minWidth)};

@media ${mediaQueries.lg} {
padding-right: ${space[2]};
}
`;

type CellProps = MinWidthProps & BorderProps;

export const Cell = styled.td<CellProps>`
border-bottom: 1px solid ${colors.gray2};
padding-block: ${space[3]};
vertical-align: middle;
${compose(border, minWidth)};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Box } from '~/components/base';
import { BehaviorTrend } from '~/domain/behavior/components/behavior-trend';
import { WidePercentage } from '~/components/tables/components/wide-percentage';
import { space } from '~/style/theme';
import { PercentageDataPoint } from '../types';
import { tableColumnWidths } from '../wide-table';
import { PercentageBarWithoutNumber } from './percentage-bar-without-number';
import { Cell } from './shared-styled-components';

interface PercentageDataProps {
percentageDataPoints: PercentageDataPoint[];
}

// Component used to show percentages on wide screens.
export const PercentageData = ({ percentageDataPoints }: PercentageDataProps) => {
return (
<>
{percentageDataPoints.map((percentageDataPoint, index) => (
<Cell minWidth={tableColumnWidths.percentageColumn} border="0" key={index}>
<WidePercentage
value={
percentageDataPoint.trendDirection ? (
<BehaviorTrend trend={percentageDataPoint.trendDirection} text={`${percentageDataPoint.percentage.value}%`} />
) : (
percentageDataPoint.percentage.value
)
}
color={percentageDataPoint.percentage.color}
justifyContent="flex-start"
/>
</Cell>
))}

<Cell minWidth={tableColumnWidths.percentageBarColumn} border="0">
<Box display="flex" flexDirection="column">
{percentageDataPoints.map((percentageDataPoint, index) => (
<PercentageBarWithoutNumber
key={index}
percentage={typeof percentageDataPoint.percentage.value === 'number' ? percentageDataPoint.percentage.value : parseFloat(percentageDataPoint.percentage.value)}
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved
color={percentageDataPoint.percentage.color}
marginBottom={index === 0 ? space[2] : undefined}
/>
))}
</Box>
</Cell>
</>
);
};
33 changes: 33 additions & 0 deletions packages/app/src/components/tables/components/wide-percentage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import styled from 'styled-components';
import { Box } from '~/components/base';
import { InlineText } from '~/components/typography';
import { fontSizes, lineHeights, space } from '~/style/theme';

interface PercentageWideNumberProps {
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved
value: string | React.ReactNode;
color: string;
justifyContent: string;
}

export function WidePercentage({ value, color, justifyContent }: PercentageWideNumberProps) {
return (
<StyledInlineText justifyContent={justifyContent}>
<Box minWidth="10px" width="10px" height="10px" backgroundColor={color} borderRadius="50%" mr={2} />
VWSCoronaDashboard26 marked this conversation as resolved.
Show resolved Hide resolved
<span>{value}</span>
</StyledInlineText>
);
}

interface StyledInlineTextProps {
justifyContent: string;
}

const StyledInlineText = styled(InlineText)<StyledInlineTextProps>`
align-items: center;
display: flex;
font-size: ${fontSizes[2]};
justify-content: ${({ justifyContent }) => justifyContent};
line-height: ${lineHeights[2]};
padding-right: ${space[4]};
text-align: left;
`;
Loading