vega-frontend-monorepo/libs/network-stats/src/components/promoted-stats-item/promoted-stats-item.tsx

38 lines
1.0 KiB
TypeScript
Raw Normal View History

import { Tooltip } from '@vegaprotocol/ui-toolkit';
import type { StatFields } from '../../config/types';
import { defaultFieldFormatter } from '../table-row';
import { Card, Indicator, Intent } from '@vegaprotocol/ui-toolkit';
2022-03-31 16:28:54 +00:00
import { useMemo } from 'react';
export const PromotedStatsItem = ({
title,
formatter,
goodThreshold,
value,
description,
...props
}: StatFields) => {
2022-03-31 16:28:54 +00:00
const variant = useMemo(
() =>
goodThreshold
? goodThreshold(value)
? Intent.Success
: Intent.Danger
: Intent.Primary,
2022-03-31 16:28:54 +00:00
[goodThreshold, value]
);
return (
<Tooltip description={description} align="start">
2022-03-31 16:28:54 +00:00
<Card>
<div className="uppercase text-[0.9375rem]">
2022-03-31 16:28:54 +00:00
<Indicator variant={variant} />
<span data-testid="stats-title">{title}</span>
</div>
<div data-testid="stats-value" className="mt-4 text-h4 leading-none">
{formatter ? formatter(value) : defaultFieldFormatter(value)}
</div>
2022-03-31 16:28:54 +00:00
</Card>
</Tooltip>
);
};