2022-08-31 04:35:46 +00:00
|
|
|
import { Callout, Indicator, Intent, Tooltip } from '@vegaprotocol/ui-toolkit';
|
2022-03-30 09:49:48 +00:00
|
|
|
import type { StatFields } from '../../config/types';
|
2022-03-23 17:40:15 +00:00
|
|
|
import { defaultFieldFormatter } from '../table-row';
|
2022-03-31 16:28:54 +00:00
|
|
|
import { useMemo } from 'react';
|
2022-03-23 17:40:15 +00:00
|
|
|
|
|
|
|
export const PromotedStatsItem = ({
|
|
|
|
title,
|
|
|
|
formatter,
|
|
|
|
goodThreshold,
|
|
|
|
value,
|
|
|
|
description,
|
2022-04-13 08:31:23 +00:00
|
|
|
...props
|
2022-03-23 17:40:15 +00:00
|
|
|
}: StatFields) => {
|
2022-03-31 16:28:54 +00:00
|
|
|
const variant = useMemo(
|
|
|
|
() =>
|
|
|
|
goodThreshold
|
|
|
|
? goodThreshold(value)
|
2022-06-10 15:07:44 +00:00
|
|
|
? Intent.Success
|
|
|
|
: Intent.Danger
|
|
|
|
: Intent.Primary,
|
2022-03-31 16:28:54 +00:00
|
|
|
[goodThreshold, value]
|
|
|
|
);
|
2022-03-23 17:40:15 +00:00
|
|
|
return (
|
2022-03-31 17:16:30 +00:00
|
|
|
<Tooltip description={description} align="start">
|
2022-08-31 04:35:46 +00:00
|
|
|
<Callout>
|
|
|
|
<div className="uppercase text-sm">
|
2022-03-31 16:28:54 +00:00
|
|
|
<Indicator variant={variant} />
|
2022-04-13 08:31:23 +00:00
|
|
|
<span data-testid="stats-title">{title}</span>
|
2022-03-23 17:40:15 +00:00
|
|
|
</div>
|
2022-08-31 04:35:46 +00:00
|
|
|
<div data-testid="stats-value" className="mt-2 text-2xl">
|
2022-03-23 17:40:15 +00:00
|
|
|
{formatter ? formatter(value) : defaultFieldFormatter(value)}
|
|
|
|
</div>
|
2022-08-31 04:35:46 +00:00
|
|
|
</Callout>
|
2022-03-23 17:40:15 +00:00
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|