{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "thinking-state-demo",
  "title": "Thinking State Demo",
  "description": "A worked example of Thinking State: A status row for work in progress, with a live elapsed timer and optional reasoning behind a disclosure.",
  "dependencies": [
    "lucide-react@^1.31.0"
  ],
  "registryDependencies": [
    "https://ui.tinkererslabs.com/r/thinking-state.json"
  ],
  "files": [
    {
      "path": "components/demos/thinking-state-demo.tsx",
      "content": "\"use client\"\n\nimport { DemoVariants } from \"@/components/demos/demo-variants\"\nimport { RestartButton } from \"@/components/demos/restart-button\"\nimport {\n  useScriptedTimeline,\n  type TimelineStep,\n} from \"@/components/demos/use-scripted-timeline\"\nimport { StreamingText } from \"@/registry/default/streaming-text/streaming-text\"\nimport {\n  ThinkingState,\n  type ThinkingStatus,\n} from \"@/registry/default/thinking-state/thinking-state\"\n\nconst steps: [TimelineStep<ThinkingStatus>, ...TimelineStep<ThinkingStatus>[]] =\n  [\n    { state: \"thinking\", holdMs: 4200 },\n    { state: \"done\", holdMs: 0 },\n  ]\n\nconst reasoning =\n  \"The index is created before the backfill runs, so any row still holding a null email will collide. Reordering the two statements is enough.\"\n\nfunction LiveRun() {\n  const { state, elapsedMs, isFinished, restart, runId } =\n    useScriptedTimeline(steps)\n\n  return (\n    <div className=\"grid gap-4\">\n      <ThinkingState\n        key={runId}\n        status={state}\n        elapsedMs={elapsedMs}\n        reasoning={<StreamingText key={runId} text={reasoning} speed={70} />}\n      />\n\n      {isFinished ? <RestartButton onClick={restart} /> : null}\n    </div>\n  )\n}\n\nexport function ThinkingStateDemo() {\n  return (\n    <DemoVariants\n      label=\"Thinking state\"\n      variants={[\n        { id: \"live\", label: \"Live run\", render: () => <LiveRun /> },\n        {\n          id: \"reasoning\",\n          label: \"Reasoning open\",\n          render: () => (\n            <ThinkingState\n              status=\"done\"\n              elapsedMs={4200}\n              reasoning={<p>{reasoning}</p>}\n              defaultOpen\n            />\n          ),\n        },\n        {\n          id: \"error\",\n          label: \"Failed\",\n          render: () => <ThinkingState status=\"error\" elapsedMs={1900} />,\n        },\n      ]}\n    />\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/demo-variants.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type DemoVariant = {\n  id: string\n  label: string\n  render: () => React.ReactNode\n}\n\nexport function DemoVariants({\n  variants,\n  label = \"Demo variant\",\n}: {\n  variants: [DemoVariant, ...DemoVariant[]]\n  label?: string\n}) {\n  const [activeId, setActiveId] = React.useState(variants[0].id)\n  const active =\n    variants.find((variant) => variant.id === activeId) ?? variants[0]\n\n  return (\n    <div className=\"grid w-full justify-items-center gap-6\">\n      {/* Centres whatever the variant renders. Without this a demo that caps\n          its own width sits against the left edge while the switch below it\n          is centred, which reads as a mistake. */}\n      <div className=\"flex w-full justify-center\">{active.render()}</div>\n\n      <div\n        role=\"group\"\n        aria-label={label}\n        className=\"border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1\"\n      >\n        {variants.map((variant) => {\n          const isActive = variant.id === active.id\n\n          return (\n            <button\n              key={variant.id}\n              type=\"button\"\n              aria-pressed={isActive}\n              className={\n                isActive\n                  ? \"bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold\"\n                  : \"text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold\"\n              }\n              onClick={() => setActiveId(variant.id)}\n            >\n              {variant.label}\n            </button>\n          )\n        })}\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/restart-button.tsx",
      "content": "\"use client\"\n\nimport { RotateCcw } from \"lucide-react\"\n\nexport function RestartButton({ onClick }: { onClick: () => void }) {\n  return (\n    <button className=\"restore-button\" type=\"button\" onClick={onClick}>\n      <RotateCcw aria-hidden=\"true\" size={15} /> Replay\n    </button>\n  )\n}\n",
      "type": "registry:example"
    },
    {
      "path": "components/demos/use-scripted-timeline.ts",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nconst TICK_MS = 100\n\nexport type TimelineStep<TState> = {\n  state: TState\n  holdMs: number\n}\n\nexport function useScriptedTimeline<TState>(\n  steps: [TimelineStep<TState>, ...TimelineStep<TState>[]]\n) {\n  const [index, setIndex] = React.useState(0)\n  const [elapsedMs, setElapsedMs] = React.useState(0)\n  const [runId, setRunId] = React.useState(0)\n\n  const isFinished = index >= steps.length - 1\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setTimeout(\n      () => setIndex((current) => current + 1),\n      (steps[index] ?? steps[0]).holdMs\n    )\n\n    return () => window.clearTimeout(timer)\n  }, [index, isFinished, steps])\n\n  React.useEffect(() => {\n    if (isFinished) return\n\n    const timer = window.setInterval(\n      () => setElapsedMs((current) => current + TICK_MS),\n      TICK_MS\n    )\n\n    return () => window.clearInterval(timer)\n  }, [isFinished])\n\n  const restart = React.useCallback(() => {\n    setIndex(0)\n    setElapsedMs(0)\n    setRunId((current) => current + 1)\n  }, [])\n\n  return {\n    state: (steps[index] ?? steps[0]).state,\n    elapsedMs,\n    isFinished,\n    restart,\n    runId,\n  }\n}\n",
      "type": "registry:example"
    }
  ],
  "type": "registry:example"
}