{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "launch-phase-timeline",
  "title": "Launch Phase Timeline",
  "description": "Roll out an AI feature in safe steps: a stepped curve of who has it, the checks each phase must pass, and controls to open it wider or roll it back.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/launch-phase-timeline/launch-phase-timeline.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PhaseGate {\n  id: string;\n  label: string;\n  /** The reading now, e.g. \"1.4%\". */\n  value: string;\n  /** The limit it has to meet, e.g. \"under 1%\". */\n  target: string;\n  pass: boolean;\n  /** The reading after checks run again. Leave out if it won't change. */\n  recheck?: string;\n}\n\nexport interface LaunchPhase {\n  id: string;\n  label: string;\n  /** Who gets it, e.g. \"Team only\". */\n  audience: string;\n  /** Share of users, from 0 to 100. */\n  rollout: number;\n  /** Short date range, e.g. \"16 to 20 Mar\". */\n  dates: string;\n  gates: PhaseGate[];\n}\n\nexport interface LaunchPhaseTimelineProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  title?: string;\n  subtitle?: string;\n  /** In rollout order. */\n  phases?: LaunchPhase[];\n  /** Which phase is live at the start, from 0. */\n  defaultPhase?: number;\n  /** How long a check takes, in milliseconds. */\n  checkMs?: number;\n  onPromote?: (phase: LaunchPhase) => void;\n  onRollBack?: (phase: LaunchPhase) => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst H = 176;\nconst TOP = 10;\nconst BASE = H - 22;\nconst LEFT = 38;\nconst RIGHT = 8;\n\nconst PALETTES = {\n  dark: {\n    bg: \"#08090A\",\n    cell: \"#0B0C0D\",\n    picked: \"#121315\",\n    border: \"rgba(255,255,255,0.08)\",\n    grid: \"rgba(255,255,255,0.05)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    fill: 0.2,\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    cell: \"#FFFFFF\",\n    picked: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.08)\",\n    grid: \"rgba(8,9,10,0.06)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.04)\",\n    fill: 0.14,\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_PHASES: LaunchPhase[] = [\n  {\n    id: \"team\",\n    label: \"Team\",\n    audience: \"Our own staff\",\n    rollout: 1,\n    dates: \"2 to 6 Mar\",\n    gates: [\n      {\n        id: \"crash\",\n        label: \"No serious bugs\",\n        value: \"0 open\",\n        target: \"0 open\",\n        pass: true,\n      },\n      {\n        id: \"answers\",\n        label: \"Answer quality\",\n        value: \"91%\",\n        target: \"over 85%\",\n        pass: true,\n      },\n    ],\n  },\n  {\n    id: \"beta\",\n    label: \"Beta\",\n    audience: \"Customers who opted in\",\n    rollout: 5,\n    dates: \"9 to 13 Mar\",\n    gates: [\n      {\n        id: \"errors\",\n        label: \"Error rate\",\n        value: \"0.8%\",\n        target: \"under 2%\",\n        pass: true,\n      },\n      {\n        id: \"answers\",\n        label: \"Answer quality\",\n        value: \"92%\",\n        target: \"over 88%\",\n        pass: true,\n      },\n      {\n        id: \"feedback\",\n        label: \"Positive feedback\",\n        value: \"84%\",\n        target: \"over 75%\",\n        pass: true,\n      },\n    ],\n  },\n  {\n    id: \"early\",\n    label: \"Early\",\n    audience: \"A quarter of all customers\",\n    rollout: 25,\n    dates: \"16 to 20 Mar\",\n    gates: [\n      {\n        id: \"errors\",\n        label: \"Error rate\",\n        value: \"1.4%\",\n        target: \"under 1%\",\n        pass: false,\n        recheck: \"0.7%\",\n      },\n      {\n        id: \"answers\",\n        label: \"Answer quality\",\n        value: \"93%\",\n        target: \"over 90%\",\n        pass: true,\n      },\n      {\n        id: \"cost\",\n        label: \"Cost per reply\",\n        value: \"$0.31\",\n        target: \"under $0.40\",\n        pass: true,\n      },\n      {\n        id: \"tickets\",\n        label: \"Support tickets\",\n        value: \"+2%\",\n        target: \"under +5%\",\n        pass: true,\n      },\n    ],\n  },\n  {\n    id: \"wide\",\n    label: \"Wide\",\n    audience: \"Most customers\",\n    rollout: 60,\n    dates: \"23 to 27 Mar\",\n    gates: [\n      {\n        id: \"errors\",\n        label: \"Error rate\",\n        value: \"0.6%\",\n        target: \"under 1%\",\n        pass: true,\n      },\n      {\n        id: \"answers\",\n        label: \"Answer quality\",\n        value: \"94%\",\n        target: \"over 90%\",\n        pass: true,\n      },\n      {\n        id: \"cost\",\n        label: \"Cost per reply\",\n        value: \"$0.29\",\n        target: \"under $0.40\",\n        pass: true,\n      },\n    ],\n  },\n  {\n    id: \"all\",\n    label: \"All\",\n    audience: \"All customers\",\n    rollout: 100,\n    dates: \"From 30 Mar\",\n    gates: [\n      {\n        id: \"errors\",\n        label: \"Error rate\",\n        value: \"0.5%\",\n        target: \"under 1%\",\n        pass: true,\n      },\n      {\n        id: \"load\",\n        label: \"Peak load tested\",\n        value: \"2.1x\",\n        target: \"over 2x\",\n        pass: true,\n      },\n    ],\n  },\n];\n\nconst round = (n: number) => Math.round(n * 10) / 10;\n\nfunction useReducedMotion() {\n  return React.useSyncExternalStore(\n    (callback) => {\n      const query = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n      query.addEventListener(\"change\", callback);\n      return () => query.removeEventListener(\"change\", callback);\n    },\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\nfunction useWidth<T extends HTMLElement>(fallback: number) {\n  const ref = React.useRef<T>(null);\n  const [width, setWidth] = React.useState(fallback);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => {\n      setWidth(Math.round(entry.contentRect.width));\n    });\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n  return [ref, width] as const;\n}\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle\n        cx={r}\n        cy={r}\n        r={r}\n        className=\"motion-safe:transition-[fill] motion-safe:duration-200\"\n        style={{ fill: color }}\n      />\n    </svg>\n  );\n}\n\nfunction Mark({ ok, color }: { ok: boolean; color: string }) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 16 16\"\n      width=\"16\"\n      height=\"16\"\n      fill=\"none\"\n      className=\"block shrink-0\"\n    >\n      <path\n        d={ok ? \"m3.5 8.5 3 3 6-7\" : \"M8 3.5v5.5M8 12v.01\"}\n        stroke={color}\n        strokeWidth=\"1.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function LaunchPhaseTimeline({\n  theme = \"dark\",\n  title = \"Roll out the new support assistant\",\n  subtitle = \"Each phase opens only when its checks pass.\",\n  phases = DEFAULT_PHASES,\n  defaultPhase = 2,\n  checkMs = 1100,\n  onPromote,\n  onRollBack,\n  className,\n  style,\n  ...rest\n}: LaunchPhaseTimelineProps) {\n  const c = PALETTES[theme];\n  const reduce = useReducedMotion();\n  const [live, setLive] = React.useState(defaultPhase);\n  const [viewing, setViewing] = React.useState(defaultPhase);\n  const [rechecked, setRechecked] = React.useState<string[]>([]);\n  const [checking, setChecking] = React.useState(false);\n  const [wrapRef, width] = useWidth<HTMLDivElement>(980);\n  const timer = React.useRef(0);\n  const uid = React.useId();\n\n  const last = phases.length - 1;\n  const current = phases[live];\n  const next = phases[live + 1];\n  const shown = phases[viewing];\n  const isViewingLive = viewing === live;\n\n  const gateOf = (phase: LaunchPhase, gate: PhaseGate) => {\n    const fixed = rechecked.includes(phase.id) && gate.recheck;\n    return {\n      value: fixed ? (gate.recheck as string) : gate.value,\n      pass: fixed ? true : gate.pass,\n    };\n  };\n  const failing = current\n    ? current.gates.filter((g) => !gateOf(current, g).pass).length\n    : 0;\n  const canPromote = Boolean(next) && failing === 0 && !checking;\n\n  React.useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  // The rollout as steps: flat through a phase, then up to the next one.\n  const span = width - LEFT - RIGHT;\n  const colW = span / phases.length;\n  const x = (i: number) => round(LEFT + i * colW);\n  const y = (v: number) => round(BASE - (v / 100) * (BASE - TOP));\n  const stepPath = (from: number, to: number) => {\n    let d = `M${x(from)} ${y(phases[from]?.rollout ?? 0)}`;\n    for (let i = from; i <= to; i += 1) {\n      const v = y(phases[i].rollout);\n      d += ` L${x(i)} ${v} L${x(i + 1)} ${v}`;\n    }\n    return d;\n  };\n  const line = stepPath(0, live);\n  const area = `${line} L${x(live + 1)} ${BASE} L${x(0)} ${BASE} Z`;\n  const planned = live < last ? stepPath(live, last) : \"\";\n\n  const runChecks = () => {\n    if (checking) return;\n    setChecking(true);\n    timer.current = window.setTimeout(\n      () => {\n        setChecking(false);\n        if (current) {\n          setRechecked((prev) =>\n            prev.includes(current.id) ? prev : [...prev, current.id],\n          );\n        }\n      },\n      reduce ? 0 : checkMs,\n    );\n  };\n\n  const promote = () => {\n    if (!canPromote || !next) return;\n    setLive(live + 1);\n    setViewing(live + 1);\n    onPromote?.(next);\n  };\n\n  const rollBack = () => {\n    const back = phases[live - 1];\n    if (!back) return;\n    setLive(live - 1);\n    setViewing(live - 1);\n    onRollBack?.(back);\n  };\n\n  const status = !next\n    ? { text: \"Fully rolled out\", color: GREEN }\n    : failing\n      ? {\n          text: `${failing} ${failing === 1 ? \"check is\" : \"checks are\"} holding this phase`,\n          color: ORANGE,\n        }\n      : { text: `Ready for ${next.label}`, color: GREEN };\n\n  return (\n    <section\n      aria-label={title}\n      className={`@container w-full ${className ?? \"\"}`}\n      style={{ background: c.bg, color: c.text, fontFamily: FONT, ...style }}\n      {...rest}\n    >\n      <div className=\"p-5 pb-3 @3xl:px-8 @3xl:pt-7\">\n        <div className=\"flex items-start justify-between gap-4\">\n          <header className=\"min-w-0\">\n            <h2 className=\"m-0 text-[24px] leading-[30px] font-[590] tracking-[-0.018em]\">\n              {title}\n            </h2>\n            <p\n              className=\"m-0 mt-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n              style={{ color: c.sub }}\n            >\n              {subtitle}\n            </p>\n          </header>\n          <div className=\"shrink-0 text-right\">\n            <p\n              aria-live=\"polite\"\n              className=\"m-0 text-[32px] leading-[32px] font-[510] tracking-[-0.022em] tabular-nums\"\n            >\n              {current?.rollout}%\n            </p>\n            <p\n              className=\"m-0 mt-1.5 text-[13px] leading-[20px] tabular-nums\"\n              style={{ color: c.sub }}\n            >\n              Phase {live + 1} of {phases.length}\n            </p>\n          </div>\n        </div>\n\n        <div ref={wrapRef} className=\"mt-3 w-full\" style={{ height: H }}>\n          <svg\n            role=\"img\"\n            aria-label={`${current?.rollout}% of users, ${current?.label} phase. ${phases.map((p) => `${p.label} ${p.rollout}%`).join(\", \")}.`}\n            width={width}\n            height={H}\n            className=\"block\"\n          >\n            <defs>\n              <linearGradient id={uid} x1=\"0\" x2=\"0\" y1=\"0\" y2=\"1\">\n                <stop stopColor={ACCENT} stopOpacity={c.fill} />\n                <stop offset=\"1\" stopColor={ACCENT} stopOpacity=\"0\" />\n              </linearGradient>\n            </defs>\n            {[0, 50, 100].map((t) => (\n              <g key={t}>\n                <line\n                  x1={LEFT}\n                  x2={width - RIGHT}\n                  y1={y(t)}\n                  y2={y(t)}\n                  stroke={c.grid}\n                />\n                <text x={0} y={y(t) + 4} fontSize=\"11\" fill={c.faint}>\n                  {t}%\n                </text>\n              </g>\n            ))}\n            <path d={area} fill={`url(#${uid})`} />\n            {planned && (\n              <path\n                d={planned}\n                fill=\"none\"\n                stroke={c.faint}\n                strokeWidth=\"1.5\"\n                strokeDasharray=\"3 4\"\n              />\n            )}\n            <path d={line} fill=\"none\" stroke={ACCENT} strokeWidth=\"1.75\" />\n            <line\n              x1={x(live + 1)}\n              x2={x(live + 1)}\n              y1={TOP}\n              y2={BASE}\n              stroke={c.faint}\n            />\n            {phases.map((p, i) => (\n              <text\n                key={p.id}\n                x={round(x(i) + colW / 2)}\n                y={H - 5}\n                textAnchor=\"middle\"\n                fontSize=\"11\"\n                fill={i === live ? c.text : c.faint}\n              >\n                {width < 520 ? `${p.rollout}%` : p.dates}\n              </text>\n            ))}\n          </svg>\n        </div>\n      </div>\n\n      <div\n        role=\"group\"\n        aria-label=\"Phases\"\n        className=\"grid gap-px border-y\"\n        style={{\n          background: c.border,\n          borderColor: c.border,\n          gridTemplateColumns: `repeat(${phases.length}, minmax(0, 1fr))`,\n        }}\n      >\n        {phases.map((p, i) => {\n          const state = i < live ? \"Done\" : i === live ? \"Live\" : \"Soon\";\n          const on = i === viewing;\n          return (\n            <button\n              key={p.id}\n              type=\"button\"\n              data-phase={p.id}\n              aria-pressed={on}\n              onClick={() => setViewing(i)}\n              className=\"min-w-0 cursor-pointer border-0 px-2.5 py-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2] focus-visible:ring-inset motion-safe:transition-colors motion-safe:duration-150 @3xl:px-5\"\n              style={{ background: on ? c.picked : c.cell }}\n            >\n              <span\n                className=\"block truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\"\n                style={{ color: i > live ? c.sub : c.text }}\n              >\n                {p.label}\n              </span>\n              <span\n                className=\"mt-0.5 flex items-center gap-1.5 text-[12px] leading-[16px] tracking-[-0.005em]\"\n                style={{ color: c.faint }}\n              >\n                <Dot\n                  size={6}\n                  color={i < live ? GREEN : i === live ? ACCENT : c.faint}\n                />\n                <span className=\"truncate\">{state}</span>\n              </span>\n            </button>\n          );\n        })}\n      </div>\n\n      {/* Every phase shares one cell, so moving between them never changes the block's height. */}\n      <div\n        className=\"grid p-5 @3xl:px-8\"\n        style={{ gridTemplateColumns: \"minmax(0, 1fr)\" }}\n      >\n        {phases.map((p, i) => {\n          const on = i === viewing;\n          return (\n            <div\n              key={p.id}\n              aria-hidden={!on}\n              className={`min-w-0 [grid-area:1/1] ${on ? \"visible\" : \"invisible\"}`}\n            >\n              <p className=\"m-0 text-[15px] leading-[22px] font-[590] tracking-[-0.012em]\">\n                {p.audience}\n              </p>\n              <p\n                className=\"m-0 text-[12.5px] leading-[18px] tracking-[-0.008em] tabular-nums\"\n                style={{ color: c.faint }}\n              >\n                {p.dates}, {p.rollout}% of users\n              </p>\n              <ul\n                className=\"m-0 mt-3 grid list-none gap-x-8 p-0 @3xl:grid-cols-2\"\n                style={{ minHeight: 84 }}\n              >\n                {p.gates.map((g) => {\n                  const reading = gateOf(p, g);\n                  const pending = i > live;\n                  return (\n                    <li\n                      key={g.id}\n                      className=\"flex items-center gap-2.5 border-t py-2 text-[13px] leading-[20px] tracking-[-0.011em]\"\n                      style={{ borderColor: c.border }}\n                    >\n                      <Mark\n                        ok={reading.pass}\n                        color={\n                          pending ? c.faint : reading.pass ? GREEN : ORANGE\n                        }\n                      />\n                      <span\n                        className=\"min-w-0 flex-1 truncate\"\n                        style={{ color: c.soft }}\n                      >\n                        {g.label}\n                      </span>\n                      <span\n                        className=\"shrink-0 tabular-nums\"\n                        style={{ color: c.faint }}\n                      >\n                        {g.target}\n                      </span>\n                      <span\n                        className=\"shrink-0 text-right font-[510] tabular-nums\"\n                        style={{\n                          width: 52,\n                          color: pending\n                            ? c.faint\n                            : reading.pass\n                              ? c.text\n                              : ORANGE,\n                        }}\n                      >\n                        {pending ? \"Waiting\" : reading.value}\n                      </span>\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          );\n        })}\n      </div>\n\n      <footer\n        className=\"flex flex-wrap items-center justify-between gap-x-4 gap-y-3 border-t px-5 py-3.5 @3xl:px-8\"\n        style={{ borderColor: c.border }}\n      >\n        <p\n          aria-live=\"polite\"\n          className=\"m-0 flex min-w-0 items-center gap-2 text-[13px] leading-[20px] font-[510] tracking-[-0.011em]\"\n        >\n          <Dot size={8} color={checking ? ACCENT : status.color} />\n          <span className=\"truncate\">\n            {checking\n              ? \"Running the checks\"\n              : isViewingLive\n                ? status.text\n                : `Viewing ${shown?.label}. ${current?.label} is live`}\n          </span>\n        </p>\n        <div className=\"flex w-full justify-end gap-2 @2xl:w-auto\">\n          <button\n            type=\"button\"\n            data-back=\"\"\n            disabled={live === 0 || checking}\n            onClick={rollBack}\n            className={`h-9 flex-1 cursor-pointer rounded-full border-0 px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] whitespace-nowrap disabled:cursor-default @2xl:flex-none ${RING}`}\n            style={{\n              background: c.chip,\n              color: live === 0 ? c.faint : c.soft,\n            }}\n          >\n            Roll back\n          </button>\n          <button\n            type=\"button\"\n            data-check=\"\"\n            disabled={checking || !next}\n            onClick={runChecks}\n            className={`h-9 flex-1 cursor-pointer rounded-full border-0 px-3 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] whitespace-nowrap disabled:cursor-default @2xl:flex-none ${RING}`}\n            style={{\n              background: c.chip,\n              color: checking || !next ? c.faint : c.soft,\n            }}\n          >\n            Run checks\n          </button>\n          <button\n            type=\"button\"\n            data-promote=\"\"\n            disabled={!canPromote}\n            onClick={promote}\n            className={`h-9 flex-1 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] whitespace-nowrap tabular-nums disabled:cursor-default @2xl:w-[128px] @2xl:flex-none ${RING}`}\n            style={{\n              background: canPromote ? c.btn : c.chip,\n              color: canPromote ? c.btnText : c.faint,\n            }}\n          >\n            {next ? `Open to ${next.rollout}%` : \"All open\"}\n          </button>\n        </div>\n      </footer>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}