Delta
Cuánto se movió un número: una flecha, el cambio y si eso es bueno, en color y en palabras.
import { Delta, DeltaSkeleton } from '@sypnia/ui/react'
Bajo los números de un tablero
Visitors12,480Subió 12 %vs last week
Errors38Bajó 31 %vs last week
p95 response412msSubió 8 %
Storage2.1GBSin cambio
Código
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>
);
} Porcentaje, número y neutro
Subió 5 %Bajó 240rowsSubió 3members
Código
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>
);
} En Astro
Subió 12 % vs last week Bajó 31 % fewer errors
Código
---
// 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
Subió 12 %vs last week
Código
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>
);
} Cuándo usarlo
Úsalo cuando
- Bajo un Stat, en una tabla de métricas.
goodWhen="down"para errores, tiempos de respuesta y costos.
No lo uses cuando
- Números sin un valor anterior con qué comparar.
Para todos
- Los lectores de pantalla oyen «Subió 12 %» o «Bajó 31 %»; el color nunca es la única señal.
Props
| Delta | Tipo | Por defecto |
|---|---|---|
valueobligatorioThe 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 |