ComponentsReasoning Panel

Reasoning Panel

A collapsible “Thinking…” block for reasoning models with a shimmering label, live timer and auto-collapse when the answer starts.

Preview

Installation

  1. 1

    Run the following command

    npx shadcn@latest add https://localhostui.com/r/reasoning-panel.json
    

The panel uses ShimmerText from components/lokalhost_io/micro-ai-components/shimmer-text/shimmer-text.tsx (installed automatically with the CLI).

Usage

import { Reasoning } from "@/components/lokalhost_io/micro-ai-components/reasoning-panel/reasoning-panel";

<Reasoning isStreaming={isThinking} autoCollapse>
  <Reasoning.Trigger />
  <Reasoning.Content>{reasoning}</Reasoning.Content>
</Reasoning>

While isStreaming is true the trigger reads Thinking… 3s with a live timer and the panel is open. When it flips to false the label becomes Thought for 12s and, if autoCollapse is on, the panel closes 600ms later. If the user toggles the panel themselves, auto-collapse is switched off for that instance.

Steps mode

<Reasoning
  isStreaming
  steps={[
    { title: "Searching docs", status: "done" },
    { title: "Comparing options", status: "active" },
    { title: "Drafting answer", status: "pending" },
  ]}
>
  <Reasoning.Trigger />
  <Reasoning.Content />
</Reasoning>

With the Vercel AI SDK

Reasoning models stream reasoning parts before the text parts. Render the panel from the message parts and treat it as streaming until the first text part arrives.

const reasoning = message.parts.filter((p) => p.type === "reasoning").map((p) => p.text).join("");
const answerStarted = message.parts.some((p) => p.type === "text" && p.text.length > 0);

<Reasoning isStreaming={status === "streaming" && !answerStarted}>
  <Reasoning.Trigger />
  <Reasoning.Content>{reasoning}</Reasoning.Content>
</Reasoning>

With OpenAI / Anthropic streaming events

Append thinking deltas to a reasoning string and flip isStreaming off on the first answer delta.

for await (const event of stream) {
  if (event.type === "content_block_delta" && event.delta.type === "thinking_delta") {
    setReasoning((r) => r + event.delta.thinking);
  }
  if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
    setThinking(false);
    setAnswer((a) => a + event.delta.text);
  }
}

ShimmerText on its own

import { ShimmerText } from "@/components/lokalhost_io/micro-ai-components/shimmer-text/shimmer-text";

<ShimmerText>Searching the web…</ShimmerText>

It sweeps a light band across the text with background-clip: text and an animated background-position — pure CSS, no JavaScript per frame.

Props

Reasoning

PropTypeDefaultDescription
isStreamingbooleanfalseTrue while the model is thinking. Drives the live timer, shimmer and rail pulse.
defaultOpenbooleanisStreamingUncontrolled initial open state.
openboolean—Controlled open state.
onOpenChange(open: boolean) => void—Called when the panel opens or closes.
durationnumber—Final thinking time in seconds. When omitted the measured time is shown.
autoCollapsebooleantrueCollapse 600ms after thinking ends. A manual toggle disables it for that instance.
stepsReasoningStep[]—Render a mini step list ({ title, status: "pending" | "active" | "done" }) instead of raw text.
classNamestring—Classes on the root.

Reasoning.Trigger

PropTypeDefaultDescription
thinkingLabelstring"Thinking…"Label while thinking.
doneLabel(seconds: number) => string"Thought for {n}s" or "Thought for a few seconds" under 2sLabel after thinking.
hideTimerboolean—Hide the live seconds counter.

Reasoning.Content

PropTypeDefaultDescription
childrenReactNode—The reasoning text (streamed or complete). Ignored when the root has steps.
maxHeightnumber240Max height of the scroll area in px. Follows the bottom while streaming.

ShimmerText

PropTypeDefaultDescription
activebooleantrueTurn the sweep on or off.
durationnumber1.8Seconds per sweep.
as
"span""p""div"
"span"Element to render.

Accessibility

  • Built on Radix Collapsible: the trigger is a button with aria-expanded and aria-controls.
  • The timer is visual only; “Finished thinking” is announced once through a polite live region.
  • With reduced motion there is no shimmer, no icon rotation and collapse is instant.

Keyboard

KeyAction
Enter / SpaceToggle the panel when the trigger is focused
TabMoves into the scrollable content while open