{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"release-train","type":"registry:component","title":"Release train","description":"Your environments down a rail, each with the version it runs: promote one and a copy rides down to the next station, waits while it deploys, then docks.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/status-button.json?as=dependency"],"files":[{"path":"registry/release-train.tsx","type":"registry:component","content":"// Hairline UI · release-train · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { StatusButton, type ActionStatus } from \"./status-button\";\n\n/* ─────────────────────────────────────────────────────────\n * RELEASE TRAIN: where each version is running, and where it's going\n *\n *   stations   your environments down a rail, each with the version\n *              it runs now in a chip at the end of its row\n *   promote    the switch on the rail between two stations: press it\n *              and a copy of the version peels off the chip above and\n *              rides down to the line between the two stations\n *   deploying  it waits there, its ring filling with your progress,\n *              while the old version still runs below\n *   live       it docks: the new chip slides into the slot and pushes\n *              the old one out to the side\n *   failed     the chip stops on the line, its ring turns red with a\n *              small shake, and the reason folds open with Retry\n *   rollback   the version that was pushed out comes back in from the\n *              side and the current one leaves\n *\n * The stations are yours (plain records); every action is one async\n * function. Chips glide by transform from measured positions; the\n * card never re-renders while they move.\n * ───────────────────────────────────────────────────────── */\n\nexport interface ReleaseStage {\n  key: string;\n  label: string;\n  /** A second line, e.g. the URL or region. */\n  detail?: string;\n  /** The version running here now. */\n  version?: string;\n  /** The version a rollback goes back to. */\n  previous?: string;\n  status?: \"live\" | \"deploying\" | \"failed\";\n  /** The version on its way here, while deploying or failed. */\n  incoming?: string;\n  /** 0–1 while deploying; leave it out for an open-ended wait. */\n  progress?: number;\n  /** Why the deploy failed. */\n  error?: string;\n}\n\nexport interface ReleaseTrainProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  stages: ReleaseStage[];\n  title?: string;\n  caption?: string;\n  /** Shows the switch between two stations whose versions differ. Throw to refuse. */\n  onPromote?: (from: string, to: string) => Promise<unknown> | void;\n  /** Shows Retry on a failed deploy. */\n  onRetry?: (key: string) => Promise<unknown> | void;\n  /** Shows Roll back on a station that has a previous version. */\n  onRollback?: (key: string) => Promise<unknown> | void;\n}\n\nconst EASE = \"cubic-bezier(0.16,1,0.3,1)\";\nconst GLIDE = \"cubic-bezier(0.77,0,0.175,1)\";\nconst FOCUS = \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nconst useReducedMotion = () =>\n  React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\ntype Leaving = { id: number; stage: string; version: string; to: \"side\" | \"up\" };\nlet leavingId = 0;\n\nconst transitOf = (s: ReleaseStage) => (s.status === \"deploying\" || s.status === \"failed\") && s.incoming ? s.incoming : null;\n\nexport function ReleaseTrain({ stages, title = \"Releases\", caption, onPromote, onRetry, onRollback, className = \"\", ...props }: ReleaseTrainProps) {\n  const reduced = useReducedMotion();\n  const listRef = React.useRef<HTMLOListElement>(null);\n  const rects = React.useRef(new Map<string, { x: number; y: number }>());\n  const [actions, setActions] = React.useState<Record<string, ActionStatus>>({});\n  const [shake, setShake] = React.useState<Record<string, number>>({});\n\n  // Chips that leave a slot: kept for one exit animation.\n  const [prev, setPrev] = React.useState(stages);\n  const [leaving, setLeaving] = React.useState<Leaving[]>([]);\n  if (prev !== stages) {\n    const out: Leaving[] = [];\n    stages.forEach((s) => {\n      const was = prev.find((p) => p.key === s.key);\n      if (!was) return;\n      if (was.version && was.version !== s.version) out.push({ id: ++leavingId, stage: s.key, version: was.version, to: \"side\" });\n      const wasTransit = transitOf(was);\n      // A deploy that stopped without docking goes back up the rail.\n      if (wasTransit && !transitOf(s) && s.version !== wasTransit) out.push({ id: ++leavingId, stage: s.key, version: wasTransit, to: \"up\" });\n    });\n    setPrev(stages);\n    if (out.length) setLeaving((l) => [...l, ...out]);\n    // A station that starts deploying settles its switch.\n    const settled = stages.filter((s, i) => i > 0 && transitOf(s) && !transitOf(prev.find((p) => p.key === s.key) ?? s)).map((s) => s.key);\n    if (settled.length || stages.some((s) => s.status === \"failed\" && prev.find((p) => p.key === s.key)?.status !== \"failed\")) {\n      setActions((a) => {\n        const next = { ...a };\n        stages.forEach((s, i) => {\n          if (i > 0 && settled.includes(s.key)) delete next[`promote:${stages[i - 1].key}`];\n          if (s.status === \"failed\") delete next[`retry:${s.key}`];\n        });\n        return next;\n      });\n    }\n    const failedNow = stages.filter((s) => s.status === \"failed\" && prev.find((p) => p.key === s.key)?.status !== \"failed\").map((s) => s.key);\n    if (failedNow.length) setShake((m) => ({ ...m, ...Object.fromEntries(failedNow.map((k) => [k, (m[k] ?? 0) + 1])) }));\n  }\n\n  // Glide every chip that's new in its place from where its version was a moment ago.\n  React.useLayoutEffect(() => {\n    const list = listRef.current;\n    if (!list) return;\n    const base = list.getBoundingClientRect();\n    const before = rects.current;\n    const now = new Map<string, { x: number; y: number }>();\n    const chips = Array.from(list.querySelectorAll<HTMLElement>(\"[data-chip]\"));\n    chips.forEach((el) => {\n      const r = el.getBoundingClientRect();\n      now.set(el.dataset.chip!, { x: r.left - base.left, y: r.top - base.top });\n    });\n    chips.forEach((el) => {\n      const id = el.dataset.chip!;\n      if (before.has(id) || reduced || !before.size) return;\n      const [kind, stage, version] = id.split(\"|\");\n      const i = stages.findIndex((s) => s.key === stage);\n      const above = i > 0 ? stages[i - 1] : null;\n      const here = now.get(id)!;\n      const from =\n        kind === \"dock\"\n          ? (before.get(`transit|${stage}|${version}`) ?? (above?.version === version ? before.get(`dock|${above.key}|${version}`) : undefined))\n          : above?.version === version\n            ? before.get(`dock|${above.key}|${version}`)\n            : undefined;\n      if (from) {\n        el.animate([{ transform: `translate(${from.x - here.x}px, ${from.y - here.y}px)` }, { transform: \"none\" }], { duration: kind === \"dock\" ? 460 : 620, easing: GLIDE });\n      } else {\n        el.animate([{ transform: \"translateX(18px)\", opacity: 0, filter: \"blur(3px)\" }, { transform: \"none\", opacity: 1, filter: \"blur(0px)\" }], { duration: 420, easing: EASE, delay: 80, fill: \"backwards\" });\n      }\n    });\n    rects.current = now;\n  });\n\n  const run = (key: string, fn: () => Promise<unknown> | void, stage: string) => {\n    setActions((a) => ({ ...a, [key]: \"pending\" }));\n    let result: Promise<unknown> | void;\n    try {\n      result = fn();\n    } catch {\n      setActions((a) => ({ ...a, [key]: \"error\" }));\n      setShake((m) => ({ ...m, [stage]: (m[stage] ?? 0) + 1 }));\n      return;\n    }\n    Promise.resolve(result).then(\n      () => setActions((a) => (a[key] === \"pending\" && key.startsWith(\"rollback\") ? { ...a, [key]: \"idle\" } : a)),\n      () => {\n        setActions((a) => ({ ...a, [key]: \"error\" }));\n        setShake((m) => ({ ...m, [stage]: (m[stage] ?? 0) + 1 }));\n      },\n    );\n  };\n\n  return (\n    <div className={`w-full rounded-[20px] bg-background shadow-[0_0_0_1px_var(--border)] ${className}`} data-release-train=\"\" {...props}>\n      <div aria-hidden=\"true\" data-natural-width className=\"grid h-0\" style={{ gridTemplateColumns: \"minmax(0, 420px)\" }} />\n      <div className=\"@container w-full p-4 @md:p-5\">\n        <div className=\"flex items-baseline justify-between gap-3\">\n          <p className=\"truncate text-[12.5px] text-muted-foreground\">{title}</p>\n          {caption && <p className=\"shrink-0 font-mono text-[11.5px] text-muted-foreground/80\">{caption}</p>}\n        </div>\n        <ol ref={listRef} className=\"relative mt-2\">\n          {/* The rail. */}\n          <span aria-hidden=\"true\" className=\"absolute bottom-[26px] left-[9.5px] top-[26px] w-px bg-[color-mix(in_oklab,var(--foreground)_16%,var(--border))]\" />\n          {stages.map((s, i) => {\n            const next = stages[i + 1];\n            const canPromote = !!onPromote && !!next && !!s.version && s.version !== next.version && !transitOf(next) && s.status !== \"deploying\";\n            const promoteKey = `promote:${s.key}`;\n            return (\n              <Station\n                key={s.key}\n                stage={s}\n                index={i}\n                reduced={reduced}\n                shake={shake[s.key] ?? 0}\n                leaving={leaving.filter((l) => l.stage === s.key)}\n                onLeft={(id) => setLeaving((l) => l.filter((x) => x.id !== id))}\n                retry={onRetry ? { status: actions[`retry:${s.key}`] ?? \"idle\", run: () => run(`retry:${s.key}`, () => onRetry(s.key), s.key) } : null}\n                rollback={\n                  onRollback && s.previous && s.previous !== s.version && !transitOf(s)\n                    ? { status: actions[`rollback:${s.key}`] ?? \"idle\", run: () => run(`rollback:${s.key}`, () => onRollback(s.key), s.key) }\n                    : null\n                }\n                promote={\n                  next\n                    ? {\n                        shown: canPromote || actions[promoteKey] === \"pending\",\n                        status: actions[promoteKey] ?? \"idle\",\n                        label: `Promote ${s.version ?? \"\"} to ${next.label}`,\n                        run: () => run(promoteKey, () => onPromote?.(s.key, next.key), next.key),\n                      }\n                    : null\n                }\n              />\n            );\n          })}\n        </ol>\n      </div>\n    </div>\n  );\n}\n\ninterface StationProps {\n  stage: ReleaseStage;\n  index: number;\n  reduced: boolean;\n  shake: number;\n  leaving: Leaving[];\n  onLeft: (id: number) => void;\n  retry: { status: ActionStatus; run: () => void } | null;\n  rollback: { status: ActionStatus; run: () => void } | null;\n  promote: { shown: boolean; status: ActionStatus; label: string; run: () => void } | null;\n}\n\nfunction Station({ stage: s, index, reduced, shake, leaving, onLeft, retry, rollback, promote }: StationProps) {\n  const color = `var(--chart-${(index % 5) + 1}, var(--primary))`;\n  const transit = transitOf(s);\n  const failed = s.status === \"failed\";\n  const transitRef = React.useRef<HTMLSpanElement>(null);\n  const [error, setError] = React.useState(s.error ?? \"\");\n  if (failed && s.error && s.error !== error) setError(s.error);\n\n  React.useEffect(() => {\n    if (!shake || reduced) return;\n    transitRef.current?.animate([{ translate: \"0 0\" }, { translate: \"-4px 0\" }, { translate: \"4px 0\" }, { translate: \"-2px 0\" }, { translate: \"0 0\" }], { duration: 380, easing: \"ease-out\" });\n  }, [shake, reduced]);\n\n  const status = transit ? (failed ? `deploy of ${transit} failed` : `deploying ${transit}`) : s.version ? `running ${s.version}` : \"nothing deployed\";\n\n  return (\n    <li className=\"relative grid grid-cols-[20px_minmax(0,1fr)_auto] items-start gap-x-3 py-3\" aria-label={`${s.label}: ${status}`}>\n      {/* The station on the rail. */}\n      <span aria-hidden=\"true\" className=\"relative mt-[5px] flex size-5 items-center justify-center\">\n        <span\n          className=\"size-[11px] rounded-full transition-[background-color,box-shadow] duration-300\"\n          style={{\n            background: failed ? \"var(--color-red-500, #ef4444)\" : transit ? \"var(--background)\" : s.version ? color : \"var(--background)\",\n            boxShadow: transit && !failed ? `inset 0 0 0 2px ${color}` : s.version ? \"0 0 0 3px var(--background)\" : \"inset 0 0 0 1.5px var(--border), 0 0 0 3px var(--background)\",\n          }}\n        />\n      </span>\n\n      <div className=\"min-w-0\">\n        <p className=\"truncate text-[13.5px] font-medium leading-[30px] tracking-[-0.01em] text-foreground\">{s.label}</p>\n        {s.detail && <p className=\"-mt-1 truncate font-mono text-[11.5px] text-muted-foreground\">{s.detail}</p>}\n        {/* Why it failed, and Retry. */}\n        <div className=\"grid transition-[grid-template-rows,opacity] duration-[420ms]\" style={{ gridTemplateRows: failed ? \"1fr\" : \"0fr\", opacity: failed ? 1 : 0, transitionTimingFunction: EASE }}>\n          <div className=\"min-h-0 min-w-0 overflow-clip\" inert={!failed}>\n            <p className=\"pt-1.5 text-[12px] leading-snug text-red-600 dark:text-red-400\">{error || \"The deploy failed.\"}</p>\n            {retry && (\n              <div className=\"pt-2\">\n                <StatusButton size=\"sm\" variant=\"outline\" status={retry.status === \"error\" ? \"error\" : retry.status} labels={{ idle: \"Retry\", pending: \"Retrying\", success: \"Retrying\", error: \"Retry\" }} onClick={retry.run} />\n              </div>\n            )}\n          </div>\n        </div>\n        {/* Roll back. */}\n        <div className=\"grid transition-[grid-template-rows,opacity] duration-[420ms]\" style={{ gridTemplateRows: rollback ? \"1fr\" : \"0fr\", opacity: rollback ? 1 : 0, transitionTimingFunction: EASE }}>\n          <div className=\"min-h-0 min-w-0 overflow-clip\" inert={!rollback}>\n            <div className=\"pt-1.5\">\n              <StatusButton\n                size=\"sm\"\n                variant=\"ghost\"\n                className=\"-ml-2\"\n                status={rollback?.status ?? \"idle\"}\n                icon={<RollbackIcon />}\n                labels={{ idle: `Roll back to ${s.previous ?? \"\"}`, pending: \"Rolling back\", success: \"Rolled back\", error: \"Try again\" }}\n                onClick={rollback?.run}\n              />\n            </div>\n          </div>\n        </div>\n      </div>\n\n      {/* The slot: the running version docked; the incoming one waiting on the line above it. */}\n      <div className=\"relative mt-[3px] flex h-6 min-w-[64px] justify-end\">\n        {s.version && (\n          <span key={`dock|${s.version}`} data-chip={`dock|${s.key}|${s.version}`} className=\"inline-flex h-6 items-center rounded-full bg-muted px-2.5 font-mono text-[11.5px] text-foreground tabular-nums\">\n            {s.version}\n          </span>\n        )}\n        {leaving.map((l) => (\n          <LeavingChip key={l.id} leave={l} reduced={reduced} onDone={() => onLeft(l.id)} />\n        ))}\n        {transit && (\n          <span\n            ref={transitRef}\n            key={`transit|${transit}`}\n            data-chip={`transit|${s.key}|${transit}`}\n            className=\"absolute right-0 top-[-29px] z-10 inline-flex h-6 items-center gap-1.5 rounded-full bg-background pl-1.5 pr-2.5 font-mono text-[11.5px] text-foreground tabular-nums shadow-[0_0_0_1px_var(--border)]\"\n          >\n            <Ring progress={s.progress} failed={failed} color={color} />\n            {transit}\n          </span>\n        )}\n      </div>\n\n      {/* The switch to the next station. */}\n      {promote && (\n        <button\n          type=\"button\"\n          aria-label={promote.label}\n          aria-hidden={!promote.shown}\n          tabIndex={promote.shown ? 0 : -1}\n          disabled={promote.status === \"pending\"}\n          onClick={promote.run}\n          className={`absolute bottom-0 left-0 z-10 flex size-5 translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-background text-muted-foreground shadow-[0_0_0_1px_color-mix(in_oklab,var(--foreground)_18%,var(--border))] transition-[opacity,scale,color] duration-300 hover:text-foreground disabled:cursor-default ${FOCUS}`}\n          style={{ opacity: promote.shown ? 1 : 0, scale: promote.shown ? \"1\" : \"0.6\", pointerEvents: promote.shown ? \"auto\" : \"none\", transitionTimingFunction: EASE }}\n        >\n          {promote.status === \"pending\" ? (\n            <svg viewBox=\"0 0 16 16\" className=\"size-3 animate-spin\" fill=\"none\" aria-hidden=\"true\">\n              <circle cx=\"8\" cy=\"8\" r=\"5.5\" stroke=\"currentColor\" strokeOpacity=\"0.25\" strokeWidth=\"2\" />\n              <path d=\"M13.5 8A5.5 5.5 0 0 0 8 2.5\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" />\n            </svg>\n          ) : (\n            <svg viewBox=\"0 0 16 16\" className=\"size-3\" fill=\"none\" aria-hidden=\"true\">\n              <path d=\"M8 3.5v8.5M4.5 8.5 8 12l3.5-3.5\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n            </svg>\n          )}\n        </button>\n      )}\n    </li>\n  );\n}\n\nfunction LeavingChip({ leave, reduced, onDone }: { leave: Leaving; reduced: boolean; onDone: () => void }) {\n  const ref = React.useRef<HTMLSpanElement>(null);\n  const done = React.useRef(onDone);\n  React.useLayoutEffect(() => {\n    done.current = onDone;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el || reduced) return void done.current();\n    const to = leave.to === \"side\" ? \"translateX(26px)\" : \"translateY(-34px)\";\n    const a = el.animate([{ transform: leave.to === \"up\" ? \"translateY(-29px)\" : \"none\", opacity: 1, filter: \"blur(0px)\" }, { transform: to, opacity: 0, filter: \"blur(3px)\" }], {\n      duration: 380,\n      easing: EASE,\n      delay: leave.to === \"side\" ? 120 : 0,\n      fill: \"both\",\n    });\n    a.onfinish = () => done.current();\n    return () => a.cancel();\n  }, [leave.to, reduced]);\n  return (\n    <span ref={ref} aria-hidden=\"true\" className=\"absolute right-0 top-0 inline-flex h-6 items-center rounded-full bg-muted px-2.5 font-mono text-[11.5px] text-muted-foreground tabular-nums\">\n      {leave.version}\n    </span>\n  );\n}\n\nfunction Ring({ progress, failed, color }: { progress?: number; failed: boolean; color: string }) {\n  const open = progress === undefined && !failed;\n  const p = failed ? 1 : Math.max(0, Math.min(1, progress ?? 0.3));\n  return (\n    <svg viewBox=\"0 0 16 16\" className={`size-3.5 shrink-0 ${open ? \"animate-spin\" : \"\"}`} fill=\"none\" aria-hidden=\"true\">\n      <circle cx=\"8\" cy=\"8\" r=\"6\" stroke=\"currentColor\" strokeOpacity=\"0.14\" strokeWidth=\"2\" />\n      <circle\n        cx=\"8\"\n        cy=\"8\"\n        r=\"6\"\n        transform=\"rotate(-90 8 8)\"\n        stroke={failed ? \"var(--color-red-500, #ef4444)\" : color}\n        strokeWidth=\"2\"\n        strokeLinecap=\"round\"\n        pathLength={1}\n        strokeDasharray=\"1 1\"\n        style={{ strokeDashoffset: 1 - p, transition: `stroke-dashoffset 600ms ${EASE}, stroke 300ms` }}\n      />\n      {failed && <path d=\"M6 6l4 4M10 6l-4 4\" stroke=\"var(--color-red-500, #ef4444)\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />}\n    </svg>\n  );\n}\n\nfunction RollbackIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" fill=\"none\" aria-hidden=\"true\">\n      <path d=\"M4 6.5h6a3 3 0 0 1 0 6H7\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" />\n      <path d=\"M6.5 4 4 6.5 6.5 9\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" />\n    </svg>\n  );\n}\n"}],"css":{},"docs":"Docs and live preview: https://hairlineui.com/ui/release-train. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}