affectUI › Components › Chat
Thinking Loader
A small working pill for AI replies – an eight-ray spinner and a shimmering label that rolls through phases and settles on a check.
Free and open source (MIT). Install: npx shadcn@latest add https://www.affectui.com/r/thinking-loader.json · Import from @/components/ui/thinking-loader
When to use
- The wait between sending a prompt and the first streamed token – one line that says what the model is doing
- Agent and pipeline steps with real labels: searching, reading, running a tool, writing
- Inline in a chat bubble or next to a button where a full panel would be too much
When not to use
- When people should see the sources and every step – use Thinking State
- Page or data loading with no phases – a skeleton or a plain spinner reads calmer
- Waits under half a second – the loader would only flash
Usage
import { ThinkingLoader } from "@/components/ui/thinking-loader";
export function AssistantPending({ streaming }: { streaming: boolean }) {
return (
<ThinkingLoader
phases={["Thinking", "Searching the web", "Reading sources", "Writing response"]}
interval={2200}
done={streaming}
/>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
phases | string[] | ["Thinking", "Searching the web", "Reading sources", "Writing response"] | Labels to walk through, one after another |
interval | number | 2200 | Time per phase in ms when the phase isn't controlled |
phase | number | Controlled index into phases – the timer stops and the loader shows this phase | |
loop | boolean | false | Start over after the last phase instead of holding it |
done | boolean | false | Turns the spinner into a check and the label into doneLabel; setting it back to false starts over |
doneLabel | string | ((seconds: number) => string) | (s) => `Thought for ${s}s` | Label once done – a function gets the seconds since the loader started |
size | "sm" | "md" | "md" | 28 or 34px tall |
variant | "pill" | "plain" | "pill" | A bordered capsule, or just the spinner and the label |
className | string | Extra class on the root |
Accessibility
- role="status" with aria-live="polite": screen readers hear each new phase and the done label once
- The spinner, the check and the label rolling out are aria-hidden; the shimmer copy has empty alt text, so labels are read once
Responsive
- Sizes to its label; long phases stay on one line, so keep them short (two to four words)
- Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
Requirements
- React 19
Related
- Thinking State – AI working panel with a live timer, searched sources and thinking steps that appear one by one
- AI Answer – Streamed answer with source cards, citation chips that preview their source, copy, regenerate, feedback and follow-ups
- Chat Composer – Prompt composer with model picker, voice input, app connections and approval request
Guides
- React components for AI chat interfaces – What an AI chat UI needs – composer, streaming answers, thinking states, tool calls, citations, message actions – and React components for each.
- Streaming AI responses in React without layout shift – How to render streamed LLM answers in React so the page doesn't jump – stable containers, a clear thinking state, smooth text, and actions that appear in place.
- How to show what an AI agent is doing – UI patterns that make an AI agent's work visible – the current step, its plan, tool calls, a live tree or timeline, and a trace of where time and money went.
- MCP UI in React: tool calls, results and approvals – Build the interface around MCP tools: visible calls, useful results, approvals and errors. Understand where the protocol ends and your React UI begins.
- Generative UI in React: turn tool results into useful views – Use model-selected tools and validated data to show React views. Build useful generative UI without executing arbitrary model-generated code.