diff --git a/client/my-sites/stats/stats-tabs/tab.jsx b/client/my-sites/stats/stats-tabs/tab.jsx index 9ba84b2f095f6..5295b7a71a92c 100644 --- a/client/my-sites/stats/stats-tabs/tab.jsx +++ b/client/my-sites/stats/stats-tabs/tab.jsx @@ -1,7 +1,5 @@ -import { - TooltipContent, - TrendComparison, -} from '@automattic/components/src/highlight-cards/count-comparison-card'; +import { TooltipContent } from '@automattic/components/src/highlight-cards/count-card'; +import { TrendComparison } from '@automattic/components/src/highlight-cards/count-comparison-card'; import formatNumber from '@automattic/components/src/number-formatters/lib/format-number'; import Popover from '@automattic/components/src/popover'; import clsx from 'clsx'; @@ -111,7 +109,11 @@ class StatsTabsTab extends Component { position="bottom right" context={ this.tooltipRef.current } > - + ) } diff --git a/packages/components/src/highlight-cards/count-card.tsx b/packages/components/src/highlight-cards/count-card.tsx index 61ebb28fe0e06..0a5934ced3d88 100644 --- a/packages/components/src/highlight-cards/count-card.tsx +++ b/packages/components/src/highlight-cards/count-card.tsx @@ -1,8 +1,9 @@ +import { arrowDown, arrowUp, Icon } from '@wordpress/icons'; import clsx from 'clsx'; import { useRef, useState } from 'react'; import { Card } from '../'; import Popover from '../popover'; -import { formatNumber } from './lib/numbers'; +import { formatNumber, subtract } from './lib/numbers'; interface CountCardProps { heading?: React.ReactNode; @@ -10,16 +11,32 @@ interface CountCardProps { label?: string; note?: string; showValueTooltip?: boolean; - value: number | string | null; + value: number | null; + previousValue?: number | null; } -function TooltipContent( { value, label, note }: CountCardProps ) { +export function TooltipContent( { value, label, note, previousValue }: CountCardProps ) { + const difference = subtract( value, previousValue ); + + let trendClass = 'highlight-card-tooltip-count-difference-positive'; + let trendIcon = arrowUp; + if ( difference !== null && difference < 0 ) { + trendClass = 'highlight-card-tooltip-count-difference-negative'; + trendIcon = arrowDown; + } + return (
- { formatNumber( value as number, false ) } + { formatNumber( value, false ) } { label && ` ${ label }` } + { difference !== null && difference !== 0 && ( + + + { formatNumber( Math.abs( difference ), false ) } + + ) } { note &&
{ note }
}
); diff --git a/packages/components/src/highlight-cards/style.scss b/packages/components/src/highlight-cards/style.scss index da51f42497c82..a4bcdb437b217 100644 --- a/packages/components/src/highlight-cards/style.scss +++ b/packages/components/src/highlight-cards/style.scss @@ -396,6 +396,21 @@ $highlight-card-tooltip-font: Inter, $sans !default; color: var(--studio-gray-10); } +.highlight-card-tooltip-count-difference-positive { + color: var(--studio-green-10); +} + +.highlight-card-tooltip-count-difference-negative { + color: var(--studio-red-10); +} + +.highlight-card-tooltip-count-difference-positive svg, +.highlight-card-tooltip-count-difference-negative svg { + fill: currentColor; + margin-left: 16px; + vertical-align: text-bottom; +} + .highlight-card-tooltip-note { color: var(--studio-gray-30); font-size: $font-body-small;