# components/Compare (zidane-ui)

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

## Components

### `Compare`

Component.

Renders before and after values with their change, and a summary on top.

```ts
function Compare(props: CompareProps): Element
```

**Parameters**

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

**Returns** `Element`

**Props**

- `after?` (`string`): The name of the second column. Default: the `compareAfter` label.
- `before?` (`string`): The name of the first column. Default: the `compareBefore` label.
- `className?` (`string`): Extra classes on the root element.
- `format?` (`(value: number) => string`): Formats a value. Default: the number in full, up to two decimals.
- `goodWhen?` (`'up' | 'down'`, default `'down'`): Which way is good, for the color of a change. `down`: a drop is better (time, cost). `up`: a rise is better.
- `mode?` (`'bars' | 'table'`, default `'bars'`): `bars`: a bar per row for its change, either side of a zero line. `table`: numbers only.
- `rows` (`readonly CompareRow[]`): The rows, in order.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `title?` (`ReactNode`): A title above the summary.
- `unit?` (`string`): The values' unit, for example `ms` (see `withUnit`).

Source: [ui/src/components/Compare.tsx:161](https://github.com/Tahul/zidane/blob/main/ui/src/components/Compare.tsx#L161)

## Interfaces

### `CompareProps`

Interface.

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

```ts
interface CompareProps
```

**Properties**

- `after?` (`string`): The name of the second column. Default: the `compareAfter` label.
- `before?` (`string`): The name of the first column. Default: the `compareBefore` label.
- `className?` (`string`): Extra classes on the root element.
- `format?` (`(value: number) => string`): Formats a value. Default: the number in full, up to two decimals.
- `goodWhen?` (`'up' | 'down'`, default `'down'`): Which way is good, for the color of a change. `down`: a drop is better (time, cost). `up`: a rise is better.
- `mode?` (`'bars' | 'table'`, default `'bars'`): `bars`: a bar per row for its change, either side of a zero line. `table`: numbers only.
- `rows` (`readonly CompareRow[]`): The rows, in order.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `title?` (`ReactNode`): A title above the summary.
- `unit?` (`string`): The values' unit, for example `ms` (see `withUnit`).

Source: [ui/src/components/Compare.tsx:42](https://github.com/Tahul/zidane/blob/main/ui/src/components/Compare.tsx#L42)

### `CompareRow`

Interface.

One row: its label, the values before and after, and what the change came to.

```ts
interface CompareRow
```

**Properties**

- `after` (`number`): The value after.
- `before` (`number`): The value before.
- `change` (`number | null`): The relative change (0.1 is 10% more), or `null` when only the plain difference reads (from 0).
- `label` (`string`): What the row measures.
- `verdict` (`CompareVerdict`): Whether the change is better, worse, or the same.

Source: [ui/src/components/Compare.tsx:28](https://github.com/Tahul/zidane/blob/main/ui/src/components/Compare.tsx#L28)

## Types

### `CompareVerdict`

Type.

What a row's change came to.

```ts
type CompareVerdict = 'better' | 'worse' | 'same'
```

Source: [ui/src/components/Compare.tsx:25](https://github.com/Tahul/zidane/blob/main/ui/src/components/Compare.tsx#L25)
