Loading component…
Loading component…
An A/B test in two lines that quietly unfolds on hover – variants linked to a tiny chart, a metric switch with rolling numbers, and a winner you pick with a click
To reuse this local React demo, copy all files from the Code tab into the same folder, then import ExperimentCard from ./experiment-card.
import { ExperimentCard } from "@/components/ui/experiment-card";
export function SignupCopyTest() {
return (
<ExperimentCard
title="Signup button copy"
status={{ label: "Running", tone: "green" }}
note="Day 9 of 14"
metrics={[
{ id: "conversion", label: "Conversion", format: (n) => `${n.toFixed(1)}%` },
{ id: "revenue", label: "Revenue", format: (n) => `$${n.toFixed(2)}` },
]}
variants={[
{ id: "a", key: "A", name: "Start free trial", control: true, visitors: 4790, values: { conversion: 4.2, revenue: 18.4 } },
{ id: "b", key: "B", name: "Try it free", visitors: 4812, values: { conversion: 4.7, revenue: 19.1 }, confidence: { conversion: 96, revenue: 81 } },
]}
action={{ label: (v) => `Ship ${v.key}`, onClick: (v) => ship(v.id) }}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| title | string | Name of the experiment | |
| variants | ExperimentVariant[] | { id, key, name, values, control?, visitors?, confidence?, color? } – values and confidence hold one number per metric id; key is the short letter in the badge | |
| metrics | ExperimentMetric[] | { id, label, format?, lowerIsBetter? } – the switch above the rows; no switch with a single metric | |
| metric | string | Controlled metric id | |
| defaultMetric | string | first metric | Starting metric when uncontrolled |
| onMetricChange | (id: string) => void | Called with the new metric | |
| winner | string \| null | Controlled id of the picked variant | |
| defaultWinner | string \| null | null | Picked variant when uncontrolled |
| onWinnerChange | (id: string \| null) => void | Called when a variant is picked, or null when the pick is taken back | |
| status | { label: string; tone?: ExperimentTone } | The tag under the title – tone is red, amber, green, blue, violet or gray | |
| note | string | Short text next to the status, e.g. "Day 9 of 14" | |
| action | { label: string \| (variant) => string; onClick: (variant) => void } | The button that appears on the tray once a winner is picked | |
| hint | ReactNode | "Pick a winner" | The line on the tray while nothing is hovered or picked |
| trigger | "hover" \| "click" | "hover" | Hover opens under the mouse; taps and the keyboard always toggle |
| open | boolean | Controlled open state | |
| defaultOpen | boolean | false | Starts open when uncontrolled |
| onOpenChange | (open: boolean) => void | Called when the card opens or closes | |
| className | string | Extra class on the root |
Fills its container up to 340px; below 300px the note next to the status goes and the chips tighten
Touch screens: a tap opens, a tap outside closes, rows and the metric switch are taller
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"