BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/nexus-ui/reasoning

Reasoning

nexus-ui/reasoning
FreeComponent

Collapsible model reasoning trace with streaming-aware labels and markdown body

Live preview

live · rendered by the registry
Rendered by nexus-ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://nexus-ui.dev/r/reasoning.json

Source

components/nexus-ui/reasoning.tsxnexus-ui.dev/r/reasoning.json · first 6 KB
1"use client";
2
3import * as React from "react";
4import { AiBrain01Icon, ArrowDown01Icon } from "@hugeicons/core-free-icons";
5import { HugeiconsIcon } from "@hugeicons/react";
6import { Streamdown } from "streamdown";
7
8import {
9 Collapsible,
10 CollapsibleContent,
11 CollapsibleTrigger,
12} from "@/components/ui/collapsible";
13import { TextShimmer } from "@/components/nexus-ui/text-shimmer";
14import { useOnChange } from "@/lib/use-on-change";
15import { cn } from "@/lib/utils";
16
17type ReasoningContextValue = {
18 isStreaming: boolean;
19 label: string;
20};
21
22const ReasoningContext = React.createContext<ReasoningContextValue | null>(
23 null,
24);
25
26function useReasoningContext(component: string): ReasoningContextValue {
27 const ctx = React.useContext(ReasoningContext);
28 if (!ctx) {
29 throw new Error(`${component} must be used within <Reasoning>`);
30 }
31 return ctx;
32}
33
34type ReasoningProps = Omit<
35 React.ComponentProps<typeof Collapsible>,
36 "open" | "defaultOpen" | "onOpenChange"
37> & {
38 isStreaming?: boolean;
39 open?: boolean;
40 defaultOpen?: boolean;
41 onOpenChange?: (open: boolean) => void;
42};
43
44function Reasoning({
45 className,
46 isStreaming = false,
47 open: openProp,
48 defaultOpen = false,
49 onOpenChange,
50 children,
51 ...props
52}: ReasoningProps) {
53 const isControlled = openProp !== undefined;
54 const [internalOpen, setInternalOpen] = React.useState(
55 defaultOpen || isStreaming,
56 );
57 const open = isControlled ? openProp : internalOpen;
58 const [durationLabel, setDurationLabel] = React.useState<string | null>(null);
59 const [hasStreamed, setHasStreamed] = React.useState(isStreaming);
60 const startedAtRef = React.useRef<number | null>(null);
61
62 React.useEffect(() => {
63 if (isStreaming) {
64 startedAtRef.current = Date.now();
65 onOpenChange?.(true);
66 }
67 }, [isStreaming, onOpenChange]);
68
69 useOnChange(isStreaming, (current, previous) => {
70 if (!previous && current) {
71 setHasStreamed(true);
72 startedAtRef.current = Date.now();
73 setDurationLabel(null);
74 if (!isControlled) {
75 setInternalOpen(true);
76 }
77 onOpenChange?.(true);
78 }
79
80 if (previous && !current) {
81 const startedAt = startedAtRef.current;
82 const elapsedSeconds =
83 startedAt != null
84 ? Math.max(1, Math.round((Date.now() - startedAt) / 1000))
85 : null;
86 setDurationLabel(
87 elapsedSeconds != null ? String(elapsedSeconds) : "a few",
88 );
89 startedAtRef.current = null;
90 if (!isControlled) {
91// … truncated

What it pulls in

npm packages

  • @hugeicons/react
  • @hugeicons/core-free-icons
  • streamdown

Other registry items

  • collapsible

Files it writes

  • components/nexus-ui/reasoning.tsx
  • lib/use-on-change.ts

Facts

Registry
nexus-ui
Type
registry:ui
Access
Free
Files written
2
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
today

Go to the source

Docs on nexus-ui nexus-ui.dev victorcodess/nexus-ui on GitHub Raw registry item This item as JSON

More from nexus-ui

All 15 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Attachmentsattachmentsnexus-uiComponentsFree4 deps · 2 files
Chain of Thoughtchain-of-thoughtnexus-uiComponentsFree2 deps · 2 files
Citationcitationnexus-uiComponentsFree4 deps
Feedback Barfeedback-barnexus-uiComponentsFree1 dep
Imageimagenexus-uiComponentsFree2 deps
Messagemessagenexus-uiComponentsFree9 deps · 2 files
Model Selectormodel-selectornexus-uiComponentsFree3 deps
Prompt Inputprompt-inputnexus-uiComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex