# UI Parity for Storybook

**Catch design drift between Figma and Storybook before it ships.** A compliance score per component — right inside the Storybook you already have.

[![npm version](https://img.shields.io/npm/v/@uicopilot/storybook-addon?color=ea580c&label=npm)](https://www.npmjs.com/package/@uicopilot/storybook-addon)
[![weekly downloads](https://img.shields.io/npm/dw/@uicopilot/storybook-addon?color=ea580c&label=downloads)](https://www.npmjs.com/package/@uicopilot/storybook-addon)
[![license](https://img.shields.io/npm/l/@uicopilot/storybook-addon?color=ea580c)](https://www.npmjs.com/package/@uicopilot/storybook-addon)
![Storybook 9+](https://img.shields.io/badge/storybook-%E2%89%A59.0-ff4785)

![UI Parity panel showing a color mismatch and a compliance score](https://app.uiparity.com/readme/hero.png)

---

## Why

Your design system is the contract. When a button ships with the wrong brand color or 4px too much padding, nobody notices until it's in production — or a designer files a ticket weeks later. UI Parity checks each component against its Figma frame **inside Storybook**, so drift shows up while you're still in the story.

You get a **compliance score and an exact list of what's off** (Expected vs. Actual, per property) — not a fuzzy pixel diff you have to eyeball.

## Install

```bash
npm install --save-dev @uicopilot/storybook-addon
```

Register it in `.storybook/main.ts`:

```ts
export default {
  addons: ['@uicopilot/storybook-addon'],
};
```

That's it — no other config. Restart Storybook and you'll see a **UI Parity** tab in the addon panel and a toolbar button on every story.

## Quick start

1. **Open the UI Parity panel** on any story and sign in with Google — or hit **"Try without signing in"** to start a guest session.
2. **Map the story to its Figma frame** (one click, "Map to Figma"). This tells UI Parity what the component is _supposed_ to look like.
3. **Click "Compare to design."** You get a traffic-light verdict, a compliance score (e.g. `69 · D`), and a list of exactly which properties drifted.

## What it checks

**Compare to design** is the free, deterministic check. It diffs the story's _computed_ styles against the Figma spec — no screenshots, no AI, no credits:

| Catches today              | Property                                                                                                          |
| -------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Wrong brand / token colors | `color`, fill, background (banded by ΔE, so a barely-visible shift is a minor, a wrong brand color is a critical) |
| Off typography             | `font-family`, size, weight                                                                                       |
| Spacing drift              | padding, gap, margins (sub-5px diffs downgrade to minor)                                                          |
| Corner radius              | `border-radius`                                                                                                   |
| Borders                    | width, color, style                                                                                               |

> **AI visual review** — catching layout, shadows, missing elements, and icon drift from a screenshot comparison — is rolling out next. Today the deterministic spec-diff is what everyone gets, free.

## The compliance score

Every review returns a score `0–100` and a severity band `A–D`, MQM-style:

```
score = 100 - (minor x 1) - (major x 3) - (critical x 10)     capped by band
```

| Band  | Meaning              | Score cap |
| ----- | -------------------- | --------- |
| **A** | Clean — no issues    | 100       |
| **B** | Minor issues only    | 99        |
| **C** | Has a major issue    | 89        |
| **D** | Has a critical issue | 69        |

Any open critical (a wrong brand color, say) caps the component at **69 · D** no matter how few issues there are — the score can't hide a real failure. Severities are perceptually adjusted first (color diffs by ΔE2000, dimension diffs by pixel distance), so "barely visible" never scores as "critical."

## Requirements

- **Storybook** `9.0` or newer
- A **Figma** account with a **Dev or Full seat** — free/Viewer seats can't grant the design-read access UI Parity needs to index your components
- A free **[UI Parity](https://uiparity.com)** account — sign in with Google, or start as a guest and sign up to save your results

## Self-hosting the dashboard

The addon talks to `https://app.uiparity.com` by default. Point it at your own deployment with `STORYBOOK_UICOPILOT_URL` in `.storybook/main.ts`:

```ts
export default {
  addons: ['@uicopilot/storybook-addon'],
  env: (config) => ({
    ...config,
    STORYBOOK_UICOPILOT_URL: 'https://your-dashboard.example.com',
  }),
};
```

## Links

- **[uiparity.com](https://uiparity.com)** — product & sign-up
- **[app.uiparity.com](https://app.uiparity.com)** — the dashboard
- **feedback@uiparity.com** — questions, bugs, feature requests

## License

MIT © UI Parity
