# components/Stat (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/Stat.tsx](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx).

## Components

### `Delta`

Component.

Renders a signed change with an arrow, toned by whether the change is good. Its accessible name
says the direction in words (Up 12%, Down 5%, No change).

```ts
function Delta(props: DeltaProps): Element
```

**Parameters**

- `props` (`DeltaProps`): [`DeltaProps`](https://zidane.si/docs/reference/ui-components-stat.md#DeltaProps).

**Returns** `Element`

**Props**

- `className?` (`string`): Extra classes on the root element.
- `format?` (`(abs: number) => string`): Formats the size of the change (no sign). Default: up to one decimal, in the labels' `numberLocale`.
- `good?` (`'up' | 'down' | 'none'`, default `'up'`): Which way is good. `up`: a rise is positive. `down`: a drop is positive (cost, latency).
  `none`: always neutral.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `tone?` (`DeltaTone`): Sets the tone, whatever the sign.
- `unit?` (`string`): Text after the number, for example `%` or ` tokens`.
- `value` (`number`): The signed change, for example `-52` for a drop of 52.

Source: [ui/src/components/Stat.tsx:62](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L62)

### `Stat`

Component.

Renders one number: its label, the value large, then the optional line. The label comes first,
so a screen reader says what the number is before it.

```ts
function Stat(props: StatProps): Element
```

**Parameters**

- `props` (`StatProps`): [`StatProps`](https://zidane.si/docs/reference/ui-components-stat.md#StatProps).

**Returns** `Element`

**Props**

- `className?` (`string`): Extra classes on the root element.
- `delta?` (`ReactNode`): A change beside the value, usually a [`Delta`](https://zidane.si/docs/reference/ui-components-stat.md#Delta).
- `label` (`ReactNode`): What the number is, for example "Cost".
- `size?` (`StatSize`, default `'stat'`): `stat`: the value at the title step (20 px). `headline`: the figure step (28 px), for the one
  number that answers a view or a page. At most one per surface.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `sub?` (`ReactNode`): A line under the value, for example "40.6k to 19.7k tokens".
- `title?` (`string`): A native tooltip on the value.
- `tone?` (`StatTone`, default `'neutral'`): Colors the value with a status tone.
- `value` (`ReactNode`): The number, formatted.

Source: [ui/src/components/Stat.tsx:129](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L129)

### `StatRow`

Component.

Renders stats side by side as a list, each one an item.

```ts
function StatRow(props: StatRowProps): Element
```

**Parameters**

- `props` (`StatRowProps`): [`StatRowProps`](https://zidane.si/docs/reference/ui-components-stat.md#StatRowProps).

**Returns** `Element`

**Props**

- `children` (`ReactNode`): The stats, usually [`Stat`](https://zidane.si/docs/reference/ui-components-stat.md#Stat)s.
- `className?` (`string`): Extra classes on the root element.
- `columns?` (`2 | 1 | 3 | 4 | 5 | 6`): A fixed number of columns. Default: as many as fit, each at least 8rem wide, so a few stats stay in one row and wrap only when narrow.
- `framed?` (`boolean`): Set the row in a tray. Off inside a surface that is already a tray.
- `label?` (`string`): Accessible name of the list.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `tiles?` (`boolean`): Set each stat in its own tile (`.zg-tile`): a bed one step into the tray it sits on, for the
  figures of a dashboard. Use it inside a tray, never with `framed`.

Source: [ui/src/components/Stat.tsx:199](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L199)

## Functions

### `deltaTone`

Function.

The tone a change reads in: a rise is positive when up is good, a drop when down is good.

```ts
function deltaTone(value: number, good?: 'up' | 'down' | 'none'): DeltaTone
```

**Parameters**

- `value` (`number`): The signed change.
- `good?` (`'up' | 'down' | 'none'`, default `'up'`): Which way is good.

**Returns** `DeltaTone`

Source: [ui/src/components/Stat.tsx:50](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L50)

## Constants

### `STAT_ROW_COLUMNS`

Constant.

The default columns: as many as fit, each at least 8rem wide (or the whole row when narrower).

```ts
const STAT_ROW_COLUMNS = 'repeat(auto-fit, minmax(min(100%, 8rem), 1fr))'
```

Source: [ui/src/components/Stat.tsx:183](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L183)

## Interfaces

### `DeltaProps`

Interface.

Props for [`Delta`](https://zidane.si/docs/reference/ui-components-stat.md#Delta).

```ts
interface DeltaProps
```

**Properties**

- `className?` (`string`): Extra classes on the root element.
- `format?` (`(abs: number) => string`): Formats the size of the change (no sign). Default: up to one decimal, in the labels' `numberLocale`.
- `good?` (`'up' | 'down' | 'none'`, default `'up'`): Which way is good. `up`: a rise is positive. `down`: a drop is positive (cost, latency).
  `none`: always neutral.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `tone?` (`DeltaTone`): Sets the tone, whatever the sign.
- `unit?` (`string`): Text after the number, for example `%` or ` tokens`.
- `value` (`number`): The signed change, for example `-52` for a drop of 52.

Source: [ui/src/components/Stat.tsx:17](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L17)

### `StatProps`

Interface.

Props for [`Stat`](https://zidane.si/docs/reference/ui-components-stat.md#Stat).

```ts
interface StatProps
```

**Properties**

- `className?` (`string`): Extra classes on the root element.
- `delta?` (`ReactNode`): A change beside the value, usually a [`Delta`](https://zidane.si/docs/reference/ui-components-stat.md#Delta).
- `label` (`ReactNode`): What the number is, for example "Cost".
- `size?` (`StatSize`, default `'stat'`): `stat`: the value at the title step (20 px). `headline`: the figure step (28 px), for the one
  number that answers a view or a page. At most one per surface.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `sub?` (`ReactNode`): A line under the value, for example "40.6k to 19.7k tokens".
- `title?` (`string`): A native tooltip on the value.
- `tone?` (`StatTone`, default `'neutral'`): Colors the value with a status tone.
- `value` (`ReactNode`): The number, formatted.

Source: [ui/src/components/Stat.tsx:87](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L87)

### `StatRowProps`

Interface.

Props for [`StatRow`](https://zidane.si/docs/reference/ui-components-stat.md#StatRow).

```ts
interface StatRowProps
```

**Properties**

- `children` (`ReactNode`): The stats, usually [`Stat`](https://zidane.si/docs/reference/ui-components-stat.md#Stat)s.
- `className?` (`string`): Extra classes on the root element.
- `columns?` (`2 | 1 | 3 | 4 | 5 | 6`): A fixed number of columns. Default: as many as fit, each at least 8rem wide, so a few stats stay in one row and wrap only when narrow.
- `framed?` (`boolean`): Set the row in a tray. Off inside a surface that is already a tray.
- `label?` (`string`): Accessible name of the list.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `tiles?` (`boolean`): Set each stat in its own tile (`.zg-tile`): a bed one step into the tray it sits on, for the
  figures of a dashboard. Use it inside a tray, never with `framed`.

Source: [ui/src/components/Stat.tsx:162](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L162)

## Types

### `DeltaTone`

Type.

How a [`Delta`](https://zidane.si/docs/reference/ui-components-stat.md#Delta) reads: good news, bad news, or neither.

```ts
type DeltaTone = 'positive' | 'negative' | 'neutral'
```

Source: [ui/src/components/Stat.tsx:14](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L14)

### `StatSize`

Type.

How large a [`Stat`](https://zidane.si/docs/reference/ui-components-stat.md#Stat)'s value draws.

```ts
type StatSize = 'stat' | 'headline'
```

Source: [ui/src/components/Stat.tsx:113](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L113)

### `StatTone`

Type.

The status tone of a [`Stat`](https://zidane.si/docs/reference/ui-components-stat.md#Stat)'s value.

```ts
type StatTone = 'neutral' | 'info' | 'success' | 'warning' | 'danger'
```

Source: [ui/src/components/Stat.tsx:121](https://github.com/Tahul/zidane/blob/main/ui/src/components/Stat.tsx#L121)
