Stat

One measurement: label, value and how it moved. Which direction counts as healthy is a prop, because a rise in incidents is not a rise in deployments.

src/components/ui/stat.tsx

About

From the component's own source, where it was written.

A single measurement: label, value, and how it moved.

The direction of a change and whether that change is *good* are different questions, which is why goodDirection exists. Deployments rising is healthy; open incidents rising is not, and a component that colours every increase green would say the opposite of what the number means.

Install

npx astralyx-ui add stat

Usage

import { Stat } from '@/components/ui/stat'

<Stat label="Deployments" value={1482} delta={12.4} />
<Stat label="Open incidents" value={3} delta={2} goodDirection="down" />

Composer

Change the props and the source below follows.

Deployments
1,48212.4%
Props
tsx
<Stat
  label="Deployments"
  value={1482}
  delta={12.4}
  goodDirection="up"
  size="default"
  chart={<Sparkline values={series} variant="area" />}
/>

Examples

A row of measures

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

Stat

A single measurement: label, value, and how it moved.

Extends Omit<ComponentProps<'div'>, 'title'>.

PropTypeDefaultDescription
labelReactNoderequiredWhat is measured, and the measurement.
valueReactNoderequiredWhat is measured, and the measurement.
deltanumber—Signed change. The sign picks the arrow; the absolute value is printed, since the arrow already carries direction.
deltaSuffixstring'%'Unit printed after the delta.
goodDirection'up' | 'down' | 'none''up'Which way is healthy. Colours the delta green or red accordingly; none keeps it neutral.
iconReactNode——
chartReactNode—Usually a Sparkline, rendered under the value.
hintReactNode——
size'sm' | 'default' | 'lg''default'Scales the value type and the card padding together.
borderedbooleantrueDraw the card. Turn off inside a container that already provides one.
animatebooleantrueCount to the value on mount and on every change. Only applies when value is a number — a preformatted string has nothing to count through.