Skip to Content

Metric Headline

One metric answered in a plain sentence, with its number and trend.

1,240

Signups up 18% this week ↑ 18%

import { MetricHeadline } from "@dapplelight/signet-ui/components/metric-headline"

export function Demo() {
  return <MetricHeadline label="Signups" result={{ current: 1240, previous: 1050 }} />
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  MetricHeadline,
  metricSentence,
  metricTrend,
} from "@dapplelight/signet-ui/components/metric-headline"

<MetricHeadline label="Signups" result={{ current: 1240, previous: 1050 }} />

Examples

Which way is good

38,200

Revenue down 8% this month ↓ 8%

12

Failed payments down 60% this month ↓ 60%

import { MetricHeadline } from "@dapplelight/signet-ui/components/metric-headline"

<MetricHeadline label="Revenue" period="this month" result={{ current: 38200, previous: 41500 }} />

<MetricHeadline
  label="Failed payments"
  period="this month"
  goodWhen="down"
  result={{ current: 12, previous: 30 }}
/>

Steady and new

820

Active users steady this week →

64

New trials this week

import { MetricHeadline } from "@dapplelight/signet-ui/components/metric-headline"

<MetricHeadline label="Active users" result={{ current: 820, previous: 818 }} />
<MetricHeadline label="New trials" result={{ current: 64, previous: null }} />

Custom copy and children

212 orders

212 orders, 18% more than yesterday ↑ 18%

import { MetricHeadline } from "@dapplelight/signet-ui/components/metric-headline"
import { Button } from "@dapplelight/signet-ui/components/button"

<MetricHeadline
  label="Orders"
  period="today"
  format={(n) => `${n} orders`}
  copy={{ up: (c) => `${c.value}, ${c.percent} more than yesterday` }}
  result={{ current: 212, previous: 180 }}
>
  <Button variant="link" size="sm" className="self-start px-0">View orders</Button>
</MetricHeadline>

Privacy mask

••••••

Revenue up ••% this month ↑ ••%

import { MaskToggle, PrivacyMaskProvider } from "@dapplelight/signet-ui/components/privacy-mask"
import { MetricHeadline } from "@dapplelight/signet-ui/components/metric-headline"

<PrivacyMaskProvider>
  <MaskToggle />
  <MetricHeadline label="Revenue" period="this month" result={{ current: 38200, previous: 31000 }} />
</PrivacyMaskProvider>

API Reference

MetricHeadline

PropTypeDefaultDescription
result{ current: number; previous: number | null }-This period and the one before it.
labelstring-The metric's name as the sentence starts it.
periodstring"this week"Appended to the sentence.
flatWithinnumber1Changes under this percent read as flat.
goodWhen"up" | "down""up"Which direction is good news.
copyPartial<MetricHeadlineCopy>-Override the up, down, flat, new and trend strings.
format(n: number) => stringlocale number formatFormats the value.
classNames{ value?; sentence?; trend? }-Class per part.
childrenReactNode-Extra content under the sentence.

metricTrend(result, options)

PropTypeDefaultDescription
returns{ direction; tone; percent }-The rule behind the headline, for an app that renders its own.

metricSentence(result, options)

PropTypeDefaultDescription
returnsstring-The plain sentence, for aria-labels, notifications and agents.