{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reasoning-block",
  "title": "Reasoning block",
  "description": "\"Thinking 8.7s\" disclosure with a live tenths timer, a shimmering label while the model reasons, the current step previewed under the header and the full step list plus notes folded inside.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/ai/reasoning-block.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\"\nimport { Brain, ChevronRight } from \"lucide-react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\n/*\n * \"Thinking 8.7s\" disclosure for a model's reasoning: a live timer and shimmering label while it thinks, the\n * current step shown as a one-line preview, then \"Thought for 8.7s\" with the full step list and notes inside.\n */\n\nconst CSS = `\n.pc-reason-shimmer{background:linear-gradient(90deg,var(--muted-foreground) 0%,var(--foreground) 45%,var(--muted-foreground) 100%);background-size:220% 100%;-webkit-background-clip:text;background-clip:text;color:transparent;animation:pc-reason-shimmer 1.6s linear infinite}\n@keyframes pc-reason-shimmer{from{background-position:120% 0}to{background-position:-120% 0}}\n@keyframes pc-reason-pulse{0%,100%{transform:scale(1);opacity:.55}50%{transform:scale(1.9);opacity:0}}\n.pc-reason-dot::after{content:\"\";position:absolute;inset:0;border-radius:9999px;background:currentColor;animation:pc-reason-pulse 1.4s ease-out infinite}\n@media (prefers-reduced-motion:reduce){.pc-reason-shimmer{animation:none;background:none;color:var(--foreground)}.pc-reason-dot::after{animation:none;display:none}}\n`\n\nexport type ReasoningStep = {\n  id?: string\n  title: string\n  /** Muted text under the title. */\n  detail?: string\n}\n\nexport type ReasoningBlockLabels = {\n  thinking: (seconds: string) => string\n  thought: (seconds: string) => string\n  toggle: string\n}\nconst DEFAULT_LABELS: ReasoningBlockLabels = { thinking: (s) => `Thinking ${s}`, thought: (s) => `Thought for ${s}`, toggle: \"Show reasoning\" }\n\nexport type ReasoningBlockProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  /** The model is still reasoning: the label shimmers and the timer runs. */\n  thinking?: boolean\n  /** Final duration in seconds, when you have it from the API. Otherwise the elapsed time is measured here. */\n  duration?: number\n  /** Step summaries, shown in order; the last one is the current step while thinking. */\n  steps?: ReasoningStep[]\n  /** Free-form reasoning text shown under the steps. */\n  children?: React.ReactNode\n  open?: boolean\n  defaultOpen?: boolean\n  onOpenChange?: (open: boolean) => void\n  /** Show the current step under the header while collapsed and thinking. */\n  preview?: boolean\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<ReasoningBlockLabels>\n}\n\nconst fmt = (s: number) => `${s.toFixed(1)}s`\n\n/** \"Thinking 8.7s\" disclosure with a live timer and step summaries. */\nexport function ReasoningBlock({ thinking = false, duration, steps = [], children, open: openProp, defaultOpen = false, onOpenChange, preview = true, labels, className, ...props }: ReasoningBlockProps) {\n  const l = useLabels(\"reasoning-block\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const uid = React.useId()\n  const [openInner, setOpenInner] = React.useState(defaultOpen)\n  const open = openProp ?? openInner\n  const [elapsed, setElapsed] = React.useState(0)\n  const started = React.useRef<number | null>(null)\n\n  React.useEffect(() => {\n    if (!thinking) return\n    started.current = performance.now()\n    setElapsed(0)\n    const id = window.setInterval(() => setElapsed((performance.now() - (started.current ?? 0)) / 1000), 100)\n    return () => {\n      window.clearInterval(id)\n      if (started.current !== null) setElapsed((performance.now() - started.current) / 1000)\n    }\n  }, [thinking])\n\n  const seconds = thinking ? elapsed : (duration ?? elapsed)\n  const label = thinking ? l.thinking(fmt(seconds)) : l.thought(fmt(seconds))\n  const current = steps[steps.length - 1]\n  const hasBody = steps.length > 0 || children !== undefined\n  const toggle = () => {\n    if (openProp === undefined) setOpenInner(!open)\n    onOpenChange?.(!open)\n  }\n\n  return (\n    <div data-thinking={thinking || undefined} className={cn(\"pc-reason text-sm\", className)} {...props}>\n      <GooduiTokens />\n      <style href=\"pc-reasoning-block\" precedence=\"default\">\n        {CSS}\n      </style>\n      <button\n        type=\"button\"\n        aria-expanded={open}\n        aria-controls={`${uid}-body`}\n        aria-label={`${l.toggle}: ${label}`}\n        disabled={!hasBody}\n        onClick={toggle}\n        className=\"pc-press pc-press-soft group/reason inline-flex max-w-full items-center gap-1.5 rounded-md py-1 pe-1.5 outline-none focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-default\"\n      >\n        <Brain className={cn(\"size-4 shrink-0\", thinking ? \"text-foreground\" : \"text-muted-foreground\")} aria-hidden=\"true\" />\n        <span className={cn(\"font-medium tabular-nums\", thinking ? \"pc-reason-shimmer\" : \"text-muted-foreground group-hover/reason:text-foreground\")} aria-hidden=\"true\">\n          {label}\n        </span>\n        {hasBody && <ChevronRight className={cn(\"size-3.5 shrink-0 text-muted-foreground transition-transform duration-200 rtl:rotate-180\", open && \"rotate-90 rtl:rotate-90\")} aria-hidden=\"true\" />}\n      </button>\n\n      {preview && thinking && !open && current && (\n        <span className=\"sr-only\" role=\"status\" aria-live=\"polite\">\n          {current.title}\n        </span>\n      )}\n      <AnimatePresence initial={false} mode=\"popLayout\">\n        {preview && thinking && !open && current && (\n          <motion.div\n            key={current.id ?? current.title}\n            aria-hidden=\"true\"\n            initial={reduce ? { opacity: 0 } : { opacity: 0, y: 4 }}\n            animate={{ opacity: 1, y: 0 }}\n            exit={reduce ? { opacity: 0, transition: { duration: 0.1 } } : { opacity: 0, y: -4, transition: { duration: 0.15 } }}\n            transition={reduce ? { duration: 0 } : { duration: 0.2 }}\n            className=\"ms-6 truncate text-xs text-muted-foreground\"\n          >\n            {current.title}\n          </motion.div>\n        )}\n      </AnimatePresence>\n\n      <AnimatePresence initial={false}>\n        {open && hasBody && (\n          <motion.div\n            key=\"body\"\n            id={`${uid}-body`}\n            initial={{ height: 0, opacity: 0 }}\n            animate={{ height: \"auto\", opacity: 1 }}\n            exit={{ height: 0, opacity: 0 }}\n            transition={reduce ? { duration: 0 } : spring.ui}\n            className=\"overflow-hidden\"\n          >\n            <div className=\"ms-2 mt-1 border-s-2 ps-4 pb-1\">\n              {steps.length > 0 && (\n                <ol className=\"flex flex-col gap-2.5\">\n                  {steps.map((s, i) => {\n                    const live = thinking && i === steps.length - 1\n                    return (\n                      <motion.li\n                        key={s.id ?? `${i}-${s.title}`}\n                        initial={reduce ? { opacity: 0 } : { opacity: 0, y: 6 }}\n                        animate={{ opacity: 1, y: 0 }}\n                        transition={reduce ? { duration: 0 } : spring.snap}\n                        className=\"relative flex gap-2.5\"\n                      >\n                        <span className={cn(\"relative mt-[7px] size-1.5 shrink-0 rounded-full\", live ? \"pc-reason-dot bg-foreground text-foreground\" : \"bg-muted-foreground/60\")} aria-hidden=\"true\" />\n                        <span className=\"min-w-0\">\n                          <span className={cn(\"block leading-5\", live ? \"text-foreground\" : \"text-muted-foreground\")}>{s.title}</span>\n                          {s.detail && <span className=\"block text-xs leading-5 text-muted-foreground\">{s.detail}</span>}\n                        </span>\n                      </motion.li>\n                    )\n                  })}\n                </ol>\n              )}\n              {children !== undefined && <div className={cn(\"text-muted-foreground leading-6\", steps.length > 0 && \"mt-3\")}>{children}</div>}\n            </div>\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/reasoning-block.tsx"
    }
  ],
  "categories": [
    "components",
    "ai"
  ],
  "type": "registry:component"
}