Skip to content

Commit

Permalink
Stats: improve tooltips consistency (#97301)
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro authored Dec 11, 2024
1 parent ec05da9 commit 4823dde
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ function SubscriberHighlightsStandard( {
highlights,
isLoading,
}: SubscriberHighlightsRenderProps ) {
const translate = useTranslate();

return (
<div className="highlight-cards-list">
{ highlights.map( ( highlight ) => (
<CountCard
heading={ isLoading ? '-' : highlight.heading }
key={ highlight.heading }
showValueTooltip
label={ translate( 'subscribers' ) }
note={ highlight.note }
value={ isLoading ? null : highlight.count }
/>
Expand Down
10 changes: 10 additions & 0 deletions client/my-sites/stats/stats-subscribers-overview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CountCard } from '@automattic/components';
import { useTranslate } from 'i18n-calypso';
import React from 'react';
import useSubscribersOverview from 'calypso/my-sites/stats/hooks/use-subscribers-overview';

Expand All @@ -8,16 +9,25 @@ interface SubscribersOverviewProps {

const SubscribersOverview: React.FC< SubscribersOverviewProps > = ( { siteId } ) => {
const { isLoading, isError, overviewData } = useSubscribersOverview( siteId );
const translate = useTranslate();

return (
<div className="subscribers-overview highlight-cards">
<div className="highlight-cards-list">
{ overviewData.map( ( { count, heading }, index ) => {
let note = translate( 'As of today' );
if ( heading !== 'Today' ) {
const prefix = translate( 'Since' );
note = `${ prefix } ${ heading }`;
}

return (
// TODO: Communicate loading vs error state to the user.
<CountCard
key={ index }
heading={ heading }
label={ translate( 'subscribers' ) }
note={ note }
value={ isLoading || isError ? null : count }
showValueTooltip
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function AnnualHighlightsStandard( { counts }: AnnualHighlightsProps ) {
<CountCard
key={ index }
heading={ heading }
label={ heading.toLocaleLowerCase() }
value={ count }
icon={ <Icon icon={ icon } /> }
showValueTooltip
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/highlight-cards/count-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ import { formatNumber } from './lib/numbers';
interface CountCardProps {
heading?: React.ReactNode;
icon?: JSX.Element;
label?: string;
note?: string;
showValueTooltip?: boolean;
value: number | string | null;
}

function TooltipContent( { value }: CountCardProps ) {
function TooltipContent( { value, label, note }: CountCardProps ) {
return (
<div className="highlight-card-tooltip-content">
<span className="highlight-card-tooltip-counts">
{ formatNumber( value as number, false ) }
{ label && ` ${ label }` }
</span>
{ note && <div className="highlight-card-tooltip-note">{ note }</div> }
</div>
);
}

export default function CountCard( {
heading,
icon,
label,
note,
value,
showValueTooltip,
Expand Down Expand Up @@ -58,8 +62,7 @@ export default function CountCard( {
position="bottom right"
context={ textRef.current }
>
<TooltipContent value={ value } />
{ note && <div className="highlight-card-tooltip-note">{ note }</div> }
<TooltipContent value={ value } label={ label } note={ note } />
</Popover>
) }
</Card>
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/highlight-cards/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ $highlight-card-tooltip-font: Inter, $sans !default;
}

.highlight-card-tooltip-content {
display: flex;
display: block;
align-items: center;
justify-content: space-between;
font-size: $font-body-small;
Expand Down Expand Up @@ -397,8 +397,8 @@ $highlight-card-tooltip-font: Inter, $sans !default;
}

.highlight-card-tooltip-note {
font-size: $font-body-extra-small;
padding-top: 8px;
color: var(--studio-gray-30);
font-size: $font-body-small;
}
.highlight-card__settings-tooltip {
.highlight-card-tooltip-content {
Expand Down

0 comments on commit 4823dde

Please sign in to comment.