Chain of Thought
nexus-ui/chain-of-thoughtFreeComponent
Structured multi-step thought timeline with step status, optional expandable output, and auto-close when steps finish
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/chain-of-thought.jsonSource
1"use client";23import * as React from "react";4import { Alert02Icon, ArrowDown01Icon } from "@hugeicons/core-free-icons";5import { HugeiconsIcon } from "@hugeicons/react";67import {8 Collapsible,9 CollapsibleContent,10 CollapsibleTrigger,11} from "@/components/ui/collapsible";12import { TextShimmer } from "@/components/nexus-ui/text-shimmer";13import { useOnChange } from "@/lib/use-on-change";14import { cn } from "@/lib/utils";1516type ChainOfThoughtRootContextValue = {17 registerStep: (id: string, status: ChainOfThoughtStepStatus) => void;18 allStepsComplete: boolean;19 hasAnyError: boolean;20};2122const ChainOfThoughtRootContext =23 React.createContext<ChainOfThoughtRootContextValue | null>(null);2425function useChainOfThoughtRootContext(component: string) {26 const ctx = React.useContext(ChainOfThoughtRootContext);27 if (!ctx) {28 throw new Error(`${component} must be used within <ChainOfThought>`);29 }30 return ctx;31}3233type ChainOfThoughtStepContextValue = {34 status: ChainOfThoughtStepStatus;35 hasContent: boolean;36};3738const ChainOfThoughtStepContext =39 React.createContext<ChainOfThoughtStepContextValue | null>(null);4041function useChainOfThoughtStepContext(component: string) {42 const ctx = React.useContext(ChainOfThoughtStepContext);43 if (!ctx) {44 throw new Error(`${component} must be used within <ChainOfThoughtStep>`);45 }46 return ctx;47}4849type ChainOfThoughtStepStatus = "pending" | "active" | "completed" | "error";5051type ChainOfThoughtProps = Omit<52 React.ComponentProps<typeof Collapsible>,53 "open" | "defaultOpen" | "onOpenChange"54> & {55 open?: boolean;56 defaultOpen?: boolean;57 onOpenChange?: (open: boolean) => void;58 autoCloseOnAllComplete?: boolean;59};6061function ChainOfThought({62 className,63 open: openProp,64 defaultOpen = true,65 onOpenChange,66 autoCloseOnAllComplete = true,67 children,68 ...props69}: ChainOfThoughtProps) {70 const isControlled = openProp !== undefined;71 const [internalOpen, setInternalOpen] = React.useState(defaultOpen);72 const [stepStatuses, setStepStatuses] = React.useState<73 Record<string, ChainOfThoughtStepStatus>74 >({});7576 const { allStepsComplete, hasAnyError } = React.useMemo(() => {77 const statuses = Object.values(stepStatuses);78 return {79 allStepsComplete:80 statuses.length > 0 &&81 statuses.every((status) => status === "completed"),82 hasAnyError: statuses.some((status) => status === "error"),83 };84 }, [stepStatuses]);8586 const open = isControlled ? openProp : internalOpen;8788// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from nexus-ui
All 15 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Attachmentsattachments | nexus-ui | Components | Free | 4 deps · 2 files | |
| Citationcitation | nexus-ui | Components | Free | 4 deps | |
| Feedback Barfeedback-bar | nexus-ui | Components | Free | 1 dep | |
| Imageimage | nexus-ui | Components | Free | 2 deps | |
| Messagemessage | nexus-ui | Components | Free | 9 deps · 2 files | |
| Model Selectormodel-selector | nexus-ui | Components | Free | 3 deps | |
| Prompt Inputprompt-input | nexus-ui | Components | Free | 1 dep | |
| Questionsquestions | nexus-ui | Components | Free | 2 deps |
