# Comparison view

Before and after, numerically: each measure's two values and the change, coloured by whether that change is good for it. A side that wasn't measured shows a dash and no change is computed from it.

- Registry name: `comparison-view` (`@candor/comparison-view`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/comparison-view

## Install

```bash
npx candor-ui add comparison-view
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/comparison-view`.
It brings in: data, locale, scale, utils.

## Example

```tsx
"use client"

import { ComparisonView, type ComparisonRow } from "@/components/comparison-view"

const rows: ComparisonRow[] = [
  { label: "Test coverage", before: 0.72, after: 0.78, format: "percent", good: "up" },
  { label: "Failing tests", before: 10, after: 6, good: "down" },
  { label: "Median deploy time", before: 412, after: 468, format: "duration", good: "down" },
  { label: "Stale feature flags", before: 14, after: 9, good: "down" },
  { label: "Users affected by incidents", before: null, after: null, good: "down" },
]

export default function Example() {
  return <ComparisonView className="max-w-xl" before="4.1 release" after="4.2 release" rows={rows} />
}
```

## <ComparisonView>

Props:

- `before: string`: Heading of the before column, e.g. "Last quarter".
- `after: string`: Heading of the after column, e.g. "This quarter".
- `rows: ComparisonRow[]`: One row per measure: its two values (null when not measured), format, and which direction is good.
- `className?: string | undefined`

## Strings (`comparisonView`)

The fixed words, English by default. Override any of them under `comparisonView` in `<LocaleProvider strings={{ comparisonView: { … } }}>`; the table is exported as `comparisonViewStrings`.

- `measure`: Measure
- `change`: Change
- `better`: (better)
- `worse`: (worse)

## Types

### ComparisonRow

```ts
{ label: string; before: number | null; after: number | null; format?: ValueFormat | undefined; good: "up" | "down" }
```

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
