mischief
examplethinking-state-demosource: ok · hit
Thinking State Demo
A worked example of Thinking State: A status row for work in progress, with a live elapsed timer and optional reasoning behind a disclosure.
npx shadcn add "https://ui.tinkererslabs.com/r/thinking-state-demo.json"free
Where it goes
stats
Interaction
animated-counter
Tags auto-generated by rules on 9/24/2026 — empty means no evidence, not lack of support.
Dependencies
Bundle weight · lightlucide-react@^1.31.0
Registry dependencies
https://ui.tinkererslabs.com/r/thinking-state.json
Files4 · source cached 10/9/2026, 9:23:05 AM
components/demos/thinking-state-demo.tsx
"use client"
import { DemoVariants } from "@/components/demos/demo-variants"
import { RestartButton } from "@/components/demos/restart-button"
import {
useScriptedTimeline,
type TimelineStep,
} from "@/components/demos/use-scripted-timeline"
import { StreamingText } from "@/registry/default/streaming-text/streaming-text"
import {
ThinkingState,
type ThinkingStatus,
} from "@/registry/default/thinking-state/thinking-state"
const steps: [TimelineStep<ThinkingStatus>, ...TimelineStep<ThinkingStatus>[]] =
[
{ state: "thinking", holdMs: 4200 },
{ state: "done", holdMs: 0 },
]
const reasoning =
"The index is created before the backfill runs, so any row still holding a null email will collide. Reordering the two statements is enough."
function LiveRun() {
const { state, elapsedMs, isFinished, restart, runId } =
useScriptedTimeline(steps)
return (
<div className="grid gap-4">
<ThinkingState
key={runId}
status={state}
elapsedMs={elapsedMs}
reasoning={<StreamingText key={runId} text={reasoning} speed={70} />}
/>
{isFinished ? <RestartButton onClick={restart} /> : null}
</div>
)
}
export function ThinkingStateDemo() {
return (
<DemoVariants
label="Thinking state"
variants={[
{ id: "live", label: "Live run", render: () => <LiveRun /> },
{
id: "reasoning",
label: "Reasoning open",
render: () => (
<ThinkingState
status="done"
elapsedMs={4200}
reasoning={<p>{reasoning}</p>}
defaultOpen
/>
),
},
{
id: "error",
label: "Failed",
render: () => <ThinkingState status="error" elapsedMs={1900} />,
},
]}
/>
)
}
components/demos/demo-variants.tsx
"use client"
import * as React from "react"
export type DemoVariant = {
id: string
label: string
render: () => React.ReactNode
}
export function DemoVariants({
variants,
label = "Demo variant",
}: {
variants: [DemoVariant, ...DemoVariant[]]
label?: string
}) {
const [activeId, setActiveId] = React.useState(variants[0].id)
const active =
variants.find((variant) => variant.id === activeId) ?? variants[0]
return (
<div className="grid w-full justify-items-center gap-6">
{/* Centres whatever the variant renders. Without this a demo that caps
its own width sits against the left edge while the switch below it
is centred, which reads as a mistake. */}
<div className="flex w-full justify-center">{active.render()}</div>
<div
role="group"
aria-label={label}
className="border-border bg-background/70 inline-flex flex-wrap justify-center gap-1 rounded-full border p-1"
>
{variants.map((variant) => {
const isActive = variant.id === active.id
return (
<button
key={variant.id}
type="button"
aria-pressed={isActive}
className={
isActive
? "bg-foreground text-background rounded-full px-3 py-1.5 text-xs font-semibold"
: "text-muted-foreground hover:text-foreground rounded-full px-3 py-1.5 text-xs font-semibold"
}
onClick={() => setActiveId(variant.id)}
>
{variant.label}
</button>
)
})}
</div>
</div>
)
}
components/demos/restart-button.tsx
"use client"
import { RotateCcw } from "lucide-react"
export function RestartButton({ onClick }: { onClick: () => void }) {
return (
<button className="restore-button" type="button" onClick={onClick}>
<RotateCcw aria-hidden="true" size={15} /> Replay
</button>
)
}
components/demos/use-scripted-timeline.ts
"use client"
import * as React from "react"
const TICK_MS = 100
export type TimelineStep<TState> = {
state: TState
holdMs: number
}
export function useScriptedTimeline<TState>(
steps: [TimelineStep<TState>, ...TimelineStep<TState>[]]
) {
const [index, setIndex] = React.useState(0)
const [elapsedMs, setElapsedMs] = React.useState(0)
const [runId, setRunId] = React.useState(0)
const isFinished = index >= steps.length - 1
React.useEffect(() => {
if (isFinished) return
const timer = window.setTimeout(
() => setIndex((current) => current + 1),
(steps[index] ?? steps[0]).holdMs
)
return () => window.clearTimeout(timer)
}, [index, isFinished, steps])
React.useEffect(() => {
if (isFinished) return
const timer = window.setInterval(
() => setElapsedMs((current) => current + TICK_MS),
TICK_MS
)
return () => window.clearInterval(timer)
}, [isFinished])
const restart = React.useCallback(() => {
setIndex(0)
setElapsedMs(0)
setRunId((current) => current + 1)
}, [])
return {
state: (steps[index] ?? steps[0]).state,
elapsedMs,
isFinished,
restart,
runId,
}
}