Delta
How much a number moved: an arrow, the change, and whether that is good, in colour and in words.
import { Delta, DeltaSkeleton } from '@sypnia/ui/react'
Under the numbers of a dashboard
Visitors12,480Up 12%vs last week
Errors38Down 31%vs last week
p95 response412msUp 8%
Storage2.1GBNo change
Code
import { Delta, Stat, StatGroup } from '@sypnia/ui/react';
// The colour says whether the move is good: fewer errors are good, so that Delta says goodWhen="down".
export default function Stats() {
return (
<StatGroup>
<Stat label="Visitors" value="12,480" delta={<Delta value={0.12} suffix="vs last week" />} />
<Stat label="Errors" value="38" delta={<Delta value={-0.31} goodWhen="down" suffix="vs last week" />} />
<Stat label="p95 response" value="412" unit="ms" delta={<Delta value={0.08} goodWhen="down" />} />
<Stat label="Storage" value="2.1" unit="GB" delta={<Delta value={0.002} flatWithin={0.005} />} />
</StatGroup>
);
} Percent, number and neutral
Up 5%Down 240rowsUp 3members
Code
import { Delta, DeltaSkeleton } from '@sypnia/ui/react';
// A percent (a fraction: 0.05 is 5 %), a plain number, a change with no good or bad, and the skeleton.
export default function Kinds() {
return (
<div className="sy-row">
<Delta value={0.05} />
<Delta value={-240} as="number" suffix="rows" />
<Delta value={3} as="number" goodWhen="none" suffix="members" />
<DeltaSkeleton />
</div>
);
} In Astro
Up 12% vs last week Down 31% fewer errors
Code
---
// The Astro twin: the same words and colours, written when the page is built.
import Delta from '@sypnia/ui/astro/Delta.astro';
---
<div class="sy-row">
<Delta value={0.12} suffix="vs last week" />
<Delta value={-0.31} goodWhen="down" suffix="fewer errors" />
</div> Skeleton
Up 12%vs last week
Code
import { Delta, DeltaSkeleton } from '@sypnia/ui/react';
// The change and its skeleton.
export default function Skeleton() {
return (
<div className="sy-cols sy-cols--stack">
<Delta value={0.12} suffix="vs last week" />
<DeltaSkeleton />
</div>
);
} When to use it
Use it when
- Under a Stat, in a table of metrics.
goodWhen="down"for errors, response times and costs.
Do not use it when
- Numbers with no earlier value to compare with.
For everyone
- Screen readers hear «Up 12%» or «Down 31%»; the colour is never the only sign.
Props
| Delta | Type | Default |
|---|---|---|
valuerequiredThe change. As a percent it is a fraction: 0.12 is 12 %. | number | |
as | "number" | "percent" | percent |
digits | number | |
flatWithinChanges this small or smaller are «No change». | number | 0 |
formatValue | ((v: number) => string) | |
goodWhen | "up" | "down" | "none" | up |
suffixWords after the change: «since last week». | ReactNode |