Thinking
A model's reasoning, with a live timer.
Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add thinkingOr install the package
Don’t want the file? Import from
asta-ui/thinkingand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { Thinking } from "asta-ui/thinking";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useEffect, useId, useRef, useState, type RefObject } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); const CURVE = "cubic-bezier(.16,1,.3,1)"; const MASK = "linear-gradient(90deg, transparent 32%, #000 50%, transparent 68%)"; // The shimmer is a soft-edged window that slides across the label while the bright copy inside it slides the other // way, so the letters stay put and only the light moves. Both are transforms. const KEYFRAMES = `@keyframes asta-thinking-sweep { from { transform: translateX(-100%) } 70%, to { transform: translateX(100%) } } @keyframes asta-thinking-counter { from { transform: translateX(100%) } 70%, to { transform: translateX(-100%) } } @keyframes asta-thinking-in { from { opacity: 0; transform: translateY(4px) } } @keyframes asta-thinking-pulse { 0%, 100% { opacity: .4 } 50% { opacity: 1 } } @media (prefers-reduced-motion: reduce) { .asta-thinking-a, .asta-thinking-a * { animation: none !important; transition-duration: 0s !important } .asta-thinking-shine { display: none } }`; export type ThinkingStatus = "thinking" | "done" | "stopped"; export interface ThinkingProps { /** `thinking` runs the shimmer and the timer. `done` and `stopped` freeze them and fold the panel. */ status?: ThinkingStatus; /** Reasoning summary lines. Append to the array while thinking and each new line fades in. */ steps?: string[]; /** One line shown under the header once finished, while folded. Defaults to the last step. */ summary?: string; /** Elapsed seconds, if you track time yourself. Leave it out and the component times itself. */ seconds?: number; /** Label while thinking. */ label?: string; open?: boolean; defaultOpen?: boolean; onOpenChange?: (open: boolean) => void; /** `block` shows a preview line and the panel under the header. `inline` is one line that sits in text, with no panel. */ variant?: "block" | "inline"; size?: "sm" | "md"; className?: string; } export const formatThinkingTime = (s: number) => (s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, "0")}s`); /** Whole seconds since thinking started. Ticks once a second and rests while offscreen or in a hidden tab. */ function useElapsed(running: boolean, el: RefObject<HTMLElement | null>) { const [secs, setSecs] = useState(0); const start = useRef<number | null>(null); useEffect(() => { if (!running) return; if (start.current === null) start.current = Date.now(); const node = el.current; let seen = true; let timer: ReturnType<typeof setInterval> | undefined; const tick = () => setSecs(Math.floor((Date.now() - (start.current ?? Date.now())) / 1000)); const sync = () => { clearInterval(timer); timer = undefined; tick(); if (seen && !document.hidden) timer = setInterval(tick, 1000); }; const io = node ? new IntersectionObserver(([e]) => { seen = e.isIntersecting; sync(); }) : null; if (node) io?.observe(node); document.addEventListener("visibilitychange", sync); sync(); return () => { clearInterval(timer); io?.disconnect(); document.removeEventListener("visibilitychange", sync); tick(); }; }, [running, el]); // The next run starts the clock again. useEffect(() => { if (running) return; return () => { start.current = null; }; }, [running]); return secs; } function Shimmer({ text, on }: { text: string; on: boolean }) { return ( <span className={cx("relative inline-block truncate", on ? "text-mute" : "text-ink")}> {text} {on && ( <span aria-hidden className="asta-thinking-shine pointer-events-none absolute inset-0 overflow-hidden"> <span className="absolute inset-0 animate-[asta-thinking-sweep_2.2s_linear_infinite]" style={{ maskImage: MASK, WebkitMaskImage: MASK }}> <span className="absolute inset-0 animate-[asta-thinking-counter_2.2s_linear_infinite] whitespace-nowrap text-ink">{text}</span> </span> </span> )} </span> ); } function Spark({ live, className }: { live: boolean; className: string }) { return ( <svg viewBox="0 0 24 24" className={cx(className, "shrink-0", live ? "animate-[asta-thinking-pulse_1.6s_ease-in-out_infinite] text-brand" : "text-mute")} fill="currentColor" aria-hidden> <path d="M12 3.5c.7 4.6 2.4 6.3 7 7-4.6.7-6.3 2.4-7 7-.7-4.6-2.4-6.3-7-7 4.6-.7 6.3-2.4 7-7Z" /> <path d="M19 16.5c.25 1.6.9 2.25 2.5 2.5-1.6.25-2.25.9-2.5 2.5-.25-1.6-.9-2.25-2.5-2.5 1.6-.25 2.25-.9 2.5-2.5Z" opacity=".55" /> </svg> ); } /** * Shows that a model is reasoning. The label shimmers and a timer counts up while it thinks, and the reasoning * summary streams in line by line inside a disclosure. When it finishes the shimmer stops, the label reads * "Thought for 12s" and the panel folds down to one summary line you can open again. */ export function Thinking({ status = "thinking", steps = [], summary, seconds, label = "Thinking", open, defaultOpen = false, onOpenChange, variant = "block", size = "md", className, }: ThinkingProps) { const id = useId(); const root = useRef<HTMLDivElement>(null); const live = status === "thinking"; const own = useElapsed(live && seconds === undefined, root); const secs = seconds ?? own; const [inner, setInner] = useState(defaultOpen); const isOpen = open ?? inner; const setOpen = (next: boolean) => { if (open === undefined) setInner(next); onOpenChange?.(next); }; // Fold the panel once the run ends, the way a finished thought collapses to its summary. const [prev, setPrev] = useState(status); if (prev !== status) { setPrev(status); if (!live && open === undefined) setInner(false); } const time = formatThinkingTime(secs); const heading = live ? label : status === "stopped" ? `Stopped after ${time}` : `Thought for ${time}`; const sm = size === "sm"; const inline = variant === "inline"; const canOpen = !inline && steps.length > 0; const preview = live ? steps[steps.length - 1] : (summary ?? steps[steps.length - 1]); const head = ( <> <Spark live={live} className={sm ? "h-3.5 w-3.5" : "h-4 w-4"} /> <Shimmer text={heading} on={live} /> {live && <span className="shrink-0 tabular-nums text-mute">{time}</span>} {canOpen && ( <svg viewBox="0 0 24 24" aria-hidden className={cx("h-3.5 w-3.5 shrink-0 text-mute transition-transform duration-300", isOpen && "rotate-90")} style={{ transitionTimingFunction: CURVE }} fill="none" stroke="currentColor" strokeWidth="2.55" strokeLinecap="round" strokeLinejoin="round" > <path d="m9.5 6 6 6-6 6" /> </svg> )} </> ); return ( <div ref={root} className={cx("asta-thinking-a min-w-0 text-ink", inline ? "inline-flex max-w-full align-middle" : "flex w-full flex-col", sm ? "text-[12.5px]" : "text-[13.5px]", className)} > <style href="asta-thinking" precedence="asta">{KEYFRAMES}</style> <span className="sr-only" aria-live="polite"> {live ? `${label}…` : heading.replace(/(\d+)s$/, "$1 seconds")} </span> {canOpen ? ( <button type="button" aria-expanded={isOpen} aria-controls={`${id}-panel`} onClick={() => setOpen(!isOpen)} className="-mx-1.5 flex min-w-0 max-w-full items-center gap-1.5 self-start rounded-md px-1.5 py-1 font-medium outline-none transition-colors duration-200 hover:bg-paper-2 focus-visible:ring-2 focus-visible:ring-brand/50" > {head} </button> ) : ( <span className="flex min-w-0 items-center gap-1.5 py-1 font-medium">{head}</span> )} {!inline && preview && !isOpen && ( <p key={preview} title={preview} className={cx("asta-thinking-a truncate text-mute animate-[asta-thinking-in_.4s_cubic-bezier(.16,1,.3,1)_both]", sm ? "pl-5" : "pl-[22px]")}> {preview} </p> )} {canOpen && ( <div id={`${id}-panel`} inert={!isOpen} // perf-ok: the disclosure opens by grid rows, like an accordion panel className={cx("grid transition-[grid-template-rows,opacity] duration-300", isOpen ? "grid-rows-[1fr] opacity-100" : "grid-rows-[0fr] opacity-0")} style={{ transitionTimingFunction: CURVE }} > <div className="min-h-0 overflow-hidden"> <ol aria-label="Reasoning" className="ml-[7px] mt-1 flex flex-col gap-2 pb-1 pl-[14px] shadow-[inset_1px_0_0_color-mix(in_srgb,var(--color-ink)_12%,transparent)]"> {steps.map((s, i) => ( <li key={`${i}-${s}`} className="asta-thinking-a leading-relaxed text-ink-2 animate-[asta-thinking-in_.45s_cubic-bezier(.16,1,.3,1)_both]"> {s} {live && i === steps.length - 1 && ( <span aria-hidden className="ml-1.5 inline-block h-1.5 w-1.5 rounded-full bg-brand align-middle animate-[asta-thinking-pulse_1.2s_ease-in-out_infinite]" /> )} </li> ))} </ol> </div> </div> )} </div> ); } export default Thinking;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Thinking component to my project. A model's reasoning, with a live timer. It includes: shimmer label, live timer, reasoning lines, done summary, inline, sm, md. Install it: ```sh pnpm dlx asta-ui@latest add thinking --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/thinking.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Thinking } from "@/components/astabyte/thinking"; ``` Usage example and props: https://ui.astabyte.com/thinking Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<!-- A <details> disclosure. data-status="thinking" runs the shimmer; asta.js counts data-asta-elapsed up (an epoch ms start, or "now"). When done, set data-status="done", drop the time, and fold it (remove open) to show the preview line. --> <div style="display:grid;gap:24px;max-width:520px"> <details class="asta-thinking" data-status="thinking" open> <summary class="asta-thinking-head"> <svg class="asta-thinking-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/><path d="M12.5 10c.2 1.4.8 2 2.2 2.2-1.4.2-2 .8-2.2 2.2-.2-1.4-.8-2-2.2-2.2 1.4-.2 2-.8 2.2-2.2Z" opacity=".55"/></svg> <span class="asta-thinking-label">Thinking<span class="asta-thinking-shine" aria-hidden="true"><span><span>Thinking</span></span></span></span> <span class="asta-thinking-time" data-asta-elapsed="now">0s</span> <svg class="asta-thinking-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg> <span class="asta-thinking-preview">Comparing line items. Seats are flat at 24, so the change is in usage.</span> </summary> <ol class="asta-thinking-steps" aria-label="Reasoning"> <li>Pulling the October and November invoices for the Astabyte workspace.</li> <li>Comparing line items. Seats are flat at 24, so the change is in usage.</li> </ol> </details> <details class="asta-thinking" data-status="done"> <summary class="asta-thinking-head"> <svg class="asta-thinking-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/><path d="M12.5 10c.2 1.4.8 2 2.2 2.2-1.4.2-2 .8-2.2 2.2-.2-1.4-.8-2-2.2-2.2 1.4-.2 2-.8 2.2-2.2Z" opacity=".55"/></svg> <span class="asta-thinking-label">Thought for 12s</span> <svg class="asta-thinking-chevron" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m6 4 4 4-4 4"/></svg> <span class="asta-thinking-preview">Usage up 37% from export retries, and a $120 credit expired.</span> </summary> <ol class="asta-thinking-steps" aria-label="Reasoning"> <li>Pulling the October and November invoices for the Astabyte workspace.</li> <li>API requests rose from 1.9M to 2.6M, most of it from the nightly export job.</li> <li>Checking credits. The $120 launch credit expired on Nov 1.</li> </ol> </details> <div style="display:flex;flex-wrap:wrap;gap:24px"> <div class="asta-thinking asta-thinking-inline asta-thinking-sm" data-status="thinking"> <span class="asta-thinking-head"> <svg class="asta-thinking-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/></svg> <span class="asta-thinking-label">Searching the docs<span class="asta-thinking-shine" aria-hidden="true"><span><span>Searching the docs</span></span></span></span> <span class="asta-thinking-time">2s</span> </span> </div> <div class="asta-thinking asta-thinking-inline asta-thinking-sm" data-status="stopped"> <span class="asta-thinking-head"> <svg class="asta-thinking-icon" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 1.5c.4 2.9 1.6 4.1 4.5 4.5-2.9.4-4.1 1.6-4.5 4.5-.4-2.9-1.6-4.1-4.5-4.5C6.4 5.6 7.6 4.4 8 1.5Z"/></svg> <span class="asta-thinking-label">Stopped after 9s</span> </span> </div> </div> </div>
Usage
The demo above, as code.
"use client";
import { useEffect, useState } from "react";
import { Thinking } from "@/components/astabyte/thinking";
const STEPS = [
"Pulling the October and November invoices for the Astabyte workspace.",
"Comparing line items. Seats are flat at 24, so the change is in usage.",
"API requests rose from 1.9M to 2.6M, most of it from the nightly export job.",
"The export job has retried on timeouts since Nov 12, doubling its calls.",
"Checking credits. The $120 launch credit expired on Nov 1.",
];
const ANSWER =
"Your bill went up 18% for two reasons. API usage rose 37%, almost all of it from the nightly export retrying after timeouts since Nov 12. And the $120 launch credit ran out on Nov 1. Fixing the retries should bring December back to about $1,240.";
export default function ThinkingDemo() {
const [run, setRun] = useState(0);
const [shown, setShown] = useState(0);
const [done, setDone] = useState(false);
// Stream one reasoning line at a time, then finish.
useEffect(() => {
const timers = STEPS.map((_, i) => setTimeout(() => setShown(i + 1), 700 + i * 1500));
timers.push(setTimeout(() => setDone(true), 700 + STEPS.length * 1500));
return () => timers.forEach(clearTimeout);
}, [run]);
const again = () => {
setShown(0);
setDone(false);
setRun((r) => r + 1);
};
return (
<div className="flex min-h-[460px] w-full flex-col items-center justify-center gap-8 p-4 sm:p-10">
<div className="w-full max-w-[560px] rounded-[14px] bg-paper p-5 shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_9%,transparent),0_1px_2px_rgb(0_0_0/0.04)]">
<p className="ml-auto w-fit max-w-[80%] rounded-xl bg-paper-2 px-3.5 py-2.5 text-[14px] leading-relaxed text-ink">
Why did our November invoice go up 18%?
</p>
<div className="mt-5 flex min-h-[148px] flex-col gap-2">
<Thinking key={run} status={done ? "done" : "thinking"} steps={STEPS.slice(0, shown)} defaultOpen summary="Usage up 37% from export retries, and a $120 credit expired." />
{done && <p className="text-[14px] leading-relaxed text-ink animate-[asta-thinking-in_.5s_cubic-bezier(.16,1,.3,1)_both]">{ANSWER}</p>}
</div>
<div className="mt-4 flex justify-end">
<button
type="button"
onClick={again}
disabled={!done}
className="rounded-md px-2.5 py-1.5 text-[12.5px] font-medium text-brand outline-none transition-[background-color,opacity] duration-200 hover:bg-[color-mix(in_srgb,var(--color-brand)_8%,transparent)] focus-visible:ring-2 focus-visible:ring-brand/50 disabled:opacity-40"
>
Ask again
</button>
</div>
</div>
<div className="flex w-full max-w-[560px] flex-wrap items-center gap-x-6 gap-y-3 text-[12.5px] text-mute">
<span className="flex items-center gap-2">
Inline <Thinking variant="inline" size="sm" status="thinking" label="Searching the docs" />
</span>
<Thinking variant="inline" size="sm" status="done" seconds={4} />
<Thinking variant="inline" size="sm" status="stopped" seconds={9} />
</div>
</div>
);
}