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
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
| Prop | Type | Default | Description |
|---|---|---|---|
isStreaming | boolean | false | True while the model is thinking. Drives the live timer, shimmer and rail pulse. |
defaultOpen | boolean | isStreaming | Uncontrolled initial open state. |
open | boolean | — | Controlled open state. |
onOpenChange | (open: boolean) => void | — | Called when the panel opens or closes. |
duration | number | — | Final thinking time in seconds. When omitted the measured time is shown. |
autoCollapse | boolean | true | Collapse 600ms after thinking ends. A manual toggle disables it for that instance. |
steps | ReasoningStep[] | — | Render a mini step list ({ title, status: "pending" | "active" | "done" }) instead of raw text. |
className | string | — | Classes on the root. |
Reasoning.Trigger
| Prop | Type | Default | Description |
|---|---|---|---|
thinkingLabel | string | "Thinking…" | Label while thinking. |
doneLabel | (seconds: number) => string | "Thought for {n}s" or "Thought for a few seconds" under 2s | Label after thinking. |
hideTimer | boolean | — | Hide the live seconds counter. |
Reasoning.Content
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | The reasoning text (streamed or complete). Ignored when the root has steps. |
maxHeight | number | 240 | Max height of the scroll area in px. Follows the bottom while streaming. |
ShimmerText
| Prop | Type | Default | Description |
|---|---|---|---|
active | boolean | true | Turn the sweep on or off. |
duration | number | 1.8 | Seconds per sweep. |
as | "span""p""div" | "span" | Element to render. |
Accessibility
- Built on Radix Collapsible: the trigger is a button with
aria-expandedandaria-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
| Key | Action |
|---|---|
Enter / Space | Toggle the panel when the trigger is focused |
Tab | Moves into the scrollable content while open |