Skip to content
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

Charts&Stats: add tooltips to number charts #1192

Merged
merged 1 commit into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading