Skip to content

Commit

Permalink
Charts&Stats: add tooltips to number charts
Browse files Browse the repository at this point in the history
Fixes #1151
  • Loading branch information
tom2drum committed Sep 18, 2023
1 parent 7b8bcdf commit 1e062a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
1 change: 1 addition & 0 deletions stubs/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ export const STATS_COUNTER: Counter = {
id: 'stub',
value: '9074405',
title: 'Placeholder Counter',
description: 'Placeholder description',
units: '',
};
1 change: 1 addition & 0 deletions types/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type Counter = {
id: string;
value: string;
title: string;
description?: string;
units: string;
}

Expand Down
54 changes: 36 additions & 18 deletions ui/stats/NumberWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
import { Box, Skeleton, useColorModeValue } from '@chakra-ui/react';
import { Box, Flex, Skeleton, useColorModeValue } from '@chakra-ui/react';
import React from 'react';

import Hint from 'ui/shared/Hint';

type Props = {
label: string;
description?: string;
value: string;
isLoading?: boolean;
}

const NumberWidget = ({ label, value, isLoading }: Props) => {
const NumberWidget = ({ label, value, isLoading, description }: Props) => {
const bgColor = useColorModeValue('blue.50', 'blue.800');
const skeletonBgColor = useColorModeValue('blackAlpha.50', 'whiteAlpha.50');
const hintColor = useColorModeValue('gray.600', 'gray.400');

return (
<Box
<Flex
alignItems="flex-start"
bg={ isLoading ? skeletonBgColor : bgColor }
px={ 3 }
py={{ base: 2, lg: 3 }}
borderRadius={ 12 }
justifyContent="space-between"
columnGap={ 3 }
>
<Skeleton
isLoaded={ !isLoading }
color="text_secondary"
fontSize="xs"
w="fit-content"
<Box
>
<span>{ label }</span>
</Skeleton>
<Skeleton
isLoaded={ !isLoading }
color="text_secondary"
fontSize="xs"
w="fit-content"
>
<span>{ label }</span>
</Skeleton>

<Skeleton
isLoaded={ !isLoading }
fontWeight={ 500 }
fontSize="lg"
w="fit-content"
>
{ value }
<Skeleton
isLoaded={ !isLoading }
fontWeight={ 500 }
fontSize="lg"
w="fit-content"
>
{ value }
</Skeleton>

</Box>
<Skeleton isLoaded={ !isLoading } alignSelf="center" borderRadius="base">
<Hint
label={ description }
boxSize={ 6 }
color={ hintColor }
/>
</Skeleton>
</Box>
</Flex>
);
};

Expand Down
3 changes: 2 additions & 1 deletion ui/stats/NumberWidgetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ const NumberWidgetsList = () => {
gridGap={ 4 }
>
{
data?.counters?.map(({ id, title, value, units }, index) => {
data?.counters?.map(({ id, title, value, units, description }, index) => {

return (
<NumberWidget
key={ id + (isPlaceholderData ? index : '') }
label={ title }
value={ `${ Number(value).toLocaleString(undefined, { maximumFractionDigits: 3, notation: 'compact' }) } ${ units ? units : '' }` }
isLoading={ isPlaceholderData }
description={ description }
/>
);
})
Expand Down

0 comments on commit 1e062a0

Please sign in to comment.