# ChainOfThought > Collapsible reasoning trail with a timeline of steps **Category**: components **URL**: https://peakui.pro/en/docs/react/components/chain-of-thought **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/chain-of-thought.mdx ## Usage ```tsx import {ChainOfThought} from "@peakui-pro/react"; ``` ```tsx import {ChainOfThought} from "@peakui-pro/react"; export function Basic() { return ( Thought for 4 seconds Looked up chat template patterns for message layout and composer spacing. Mapped the template structure to SDK-agnostic compound components. ); } ``` ### Anatomy ```tsx import {ChainOfThought} from "@peakui-pro/react"; export default () => ( {/* An h3 holding the core button; `level` sets the heading level. */} Thought for 4 seconds {/* Nodes only: a render function draws nothing. */} {/* role="list" */} {/* role="listitem": a Step belongs inside Steps. */} Looked up the layout patterns. ); ``` ## Examples ### Streaming `isStreaming` shimmers the trigger label; the trail stays open and closable. ```tsx import {ChainOfThought} from "@peakui-pro/react"; export function Streaming() { return ( Thinking... Breaking the request into presentation-only components. ); } ``` ### Agent Trace Stack several blocks; a step's `label` can hold your own collapsible button. ```tsx "use client"; import {ChevronRight} from "@gravity-ui/icons"; import {ChainOfThought} from "@peakui-pro/react"; import {useState} from "react"; // A step whose label is the host's own button, opening the body beside it. function ToolStep({file, title}: {file: string; title: string}) { const [isOpen, setIsOpen] = useState(true); return ( setIsOpen(!isOpen)} > {title} } > {isOpen ? file : null} ); } export function AgentTrace() { return (
Thought for 2s The user wants a simple login page. Explore - 2 files
); } ``` ### Agent Trace Streaming `isStreaming` on the block being written leaves the finished ones plain. ```tsx "use client"; import {ChevronRight} from "@gravity-ui/icons"; import {ChainOfThought} from "@peakui-pro/react"; import {useState} from "react"; function ToolStep({file, title}: {file: string; title: string}) { const [isOpen, setIsOpen] = useState(true); return ( setIsOpen(!isOpen)} > {title} } > {isOpen ? file : null} ); } // The block being written shimmers; the ones above it are done. export function AgentTraceStreaming() { return (
Explore - 2 files Updating layout
); } ``` ### Controlled `isExpanded` with `onExpandedChange` leaves the state to the host. ```tsx "use client"; import {ChainOfThought} from "@peakui-pro/react"; import {useState} from "react"; export function Controlled() { const [isExpanded, setIsExpanded] = useState(true); return (
Thought for 2s Read the layout and the global styles.

The host says: {isExpanded ? "open" : "closed"}.

); } ``` ### Disabled `isDisabled` on the trigger leaves the trail as it is. ```tsx import {ChainOfThought} from "@peakui-pro/react"; export function Disabled() { return ( Thought for 2s Read the layout and the global styles. ); } ``` ### Step Shapes A `Step` draws a header only with a `label` and a body only with children. ```tsx import {ChainOfThought} from "@peakui-pro/react"; export function StepShapes() { return ( Thought for 2s Read layout and globals. A body with no label of its own. ); } ``` ## Customization ### Tailwind CSS ```tsx Thought for 2s Mapped the structure. ``` ### Global CSS ```css @layer components { .chain-of-thought { --chain-of-thought-steps-gap: 1rem; --chain-of-thought-steps-inset: 1rem; --chain-of-thought-line-color: var(--color-border); --chain-of-thought-label-color: var(--color-foreground); } } ``` ## Styling Reference PeakUI follows the [BEM](https://getbem.com/) methodology, so variants and states are plain class names you can target. ### CSS Classes The ChainOfThought component uses these CSS classes ([view source styles](https://github.com/peakui-dev/peakui-pro/blob/main/packages/styles/components/chain-of-thought.css)): #### Base Classes - `.chain-of-thought` - Root, beside the core `.disclosure` #### Modifier Classes - `.chain-of-thought--complete` - The trail is finished - `.chain-of-thought--streaming` - The trail is still being written #### Element Classes - `.chain-of-thought__trigger` - Trigger, beside the core `.button` - `.chain-of-thought__indicator` - Trigger chevron, beside the core `.disclosure__indicator` - `.chain-of-thought__content` - Panel, beside the core `.disclosure__content` - `.chain-of-thought__steps` - Timeline with the rule down its start edge - `.chain-of-thought__step` - One step - `.chain-of-thought__step-header` - Marker and label row - `.chain-of-thought__step-indicator` - Marker dot - `.chain-of-thought__step-label` - Step label - `.chain-of-thought__step-content` - Step body ### Slots - `[data-slot="chain-of-thought"]` - `[data-slot="chain-of-thought-trigger"]` - `[data-slot="chain-of-thought-content"]` - `[data-slot="chain-of-thought-steps"]` - `[data-slot="chain-of-thought-step"]` - `[data-slot="chain-of-thought-step-header"]` - `[data-slot="chain-of-thought-step-indicator"]` - `[data-slot="chain-of-thought-step-label"]` - `[data-slot="chain-of-thought-step-content"]` The core parts inside keep their own slots: `disclosure-heading`, `disclosure-indicator`, `disclosure-body` and `disclosure-body-inner`. ### CSS Variables | Variable | Purpose | | ------------------------------------ | ------------------------------------------------------------------------ | | `--chain-of-thought-indicator-size` | Chevron width and height; defaults to `0.875rem` | | `--chain-of-thought-trigger-gap` | Space between the label and the chevron; defaults to `0.5rem` | | `--chain-of-thought-steps-gap` | Space between steps; defaults to `0.75rem` | | `--chain-of-thought-steps-inset` | Space between the rule and the steps; defaults to `0.75rem` | | `--chain-of-thought-line-color` | Color of the rule; defaults to `var(--color-separator)` | | `--chain-of-thought-step-gap` | Space between a step's header and body; defaults to `0.25rem` | | `--chain-of-thought-step-header-gap` | Space between the marker and the label; defaults to `0.5rem` | | `--chain-of-thought-marker-size` | Marker dot diameter; defaults to `0.375rem` | | `--chain-of-thought-marker-color` | Marker dot color, drawn at 40% opacity; defaults to `var(--color-muted)` | | `--chain-of-thought-label-color` | Step label color; defaults to `var(--color-muted)` | ### Interactive States The trigger is the core button and takes its states: - **Hover**: `:hover` or `[data-hovered]`, the label comes forward from the muted tone - **Pressed**: `:active` or `[data-pressed]`, scaled to `0.97` by the core button - **Focus**: `:focus-visible` or `[data-focus-visible]` - **Disabled**: `:disabled`, `[data-disabled]` or `[aria-disabled="true"]`, dimmed by the core button - **Expanded**: `[data-expanded="true"]` on the root, the panel and the chevron - **Streaming**: `[data-streaming="true"]` on the root - **Forced colors**: `@media (forced-colors: active)` paints the chevron and a control inside a step label in `ButtonText`, the marker in `CanvasText`, and keeps the core's padding so the system's border clears the label ## API Reference ### ChainOfThought | Prop | Type | Default | Description | | ------------------ | ------------------------------------------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------- | | `isStreaming` | `boolean` | `false` | The trail is still being written: the trigger label shimmers and the root gets `--streaming` instead of `--complete` | | `defaultExpanded` | `boolean` | - | Open on first render, for an uncontrolled root | | `isExpanded` | `boolean` | - | The expanded state, for a controlled root; pair it with `onExpandedChange` | | `onExpandedChange` | `(isExpanded: boolean) => void` | - | Handler called when the expanded state changes | | `isDisabled` | `boolean` | `false` | Whether the disclosure is disabled | | `children` | `ReactNode \| ((values: DisclosureRenderProps) => ReactNode)` | - | Content to render, or a function of the render props | | `className` | `string \| ((values: DisclosureRenderProps) => string)` | - | Additional classes, or a function of the render props | | `render` | `DOMRenderFunction<'div', DisclosureRenderProps>` | - | Replaces the rendered `
`; receives the props with `data-slot` set | | `...rest` | `ComponentProps` | - | Every other core Disclosure prop | ### ChainOfThought.Trigger | Prop | Type | Default | Description | | ------------ | --------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `level` | `1 \| 2 \| 3 \| 4 \| 5 \| 6` | `3` | Level of the heading that holds the trigger. A trail sits inside chat messages and cannot know the outline of the page, and every block as an `h3` makes heading navigation noisy, so set the level your page needs | | `children` | `ReactNode \| ((values: ButtonRenderProps) => ReactNode)` | - | The label. While `isStreaming` is on, `TextShimmer` renders it twice, so an interactive element or an `id` in it would be duplicated: keep it to text and inline markup | | `variant` | `'primary' \| 'secondary' \| 'tertiary' \| 'outline' \| 'ghost' \| 'danger' \| 'danger-soft'` | `'ghost'` | Core button style | | `size` | `'sm' \| 'md' \| 'lg'` | `'sm'` | Core button size | | `isDisabled` | `boolean` | `false` | Whether the trigger is disabled | | `onPress` | `(e: PressEvent) => void` | - | Handler called when the trigger is pressed | | `className` | `string \| ((values: ButtonRenderProps) => string)` | - | Additional classes, or a function of the button's state | | `render` | `DOMRenderFunction<'button', ButtonRenderProps>` | - | Replaces the rendered element; receives the props with `data-slot` set | | `...rest` | `ButtonProps` | - | Every other core Button prop | ### ChainOfThought.Content | Prop | Type | Default | Description | | ----------- | ------------------------------------------------------------ | ------- | --------------------------------------------------------------------------------------------------------------- | | `children` | `ReactNode` | - | The panel's body. Nodes only: a render function is not supported, because the core's panel draws one as nothing | | `className` | `string \| ((values: DisclosurePanelRenderProps) => string)` | - | Additional classes, or a function of the render props | | `render` | `DOMRenderFunction<'div', DisclosurePanelRenderProps>` | - | Replaces the rendered panel; receives the props with `data-slot` set | | `...rest` | `ComponentProps` | - | Every other core panel prop | ### ChainOfThought.Steps | Prop | Type | Default | Description | | ----------- | ------------------------------------- | -------- | ---------------------------------------------------------------------------------------------- | | `role` | `string` | `"list"` | The steps are a list in substance: a screen reader announces the count and the item boundaries | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | | `...rest` | `ComponentProps<'div'>` | - | Native `
` attributes | ### ChainOfThought.Step | Prop | Type | Default | Description | | ----------- | ----------------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------- | | `label` | `ReactNode` | - | A short name for the step, drawn above its body beside a marker | | `children` | `ReactNode` | - | The step's body. A `Step` is a `listitem` and belongs inside `Steps`: outside it, an accessibility audit flags the orphaned item | | `role` | `string` | `"listitem"` | Item boundary for a screen reader | | `className` | `string` | - | Additional classes | | `render` | `DOMRenderFunction<'div', undefined>` | - | Replaces the rendered `
` with your own element | | `...rest` | `Omit, 'children'>` | - | Native `
` attributes | ### Render Props | Prop | Type | Description | | ---------------------- | --------- | --------------------------------------------------------------- | | `isExpanded` | `boolean` | Whether the trail is open (`ChainOfThought`, `Content`) | | `isDisabled` | `boolean` | Whether the control is disabled (`ChainOfThought`, `Trigger`) | | `isFocusVisibleWithin` | `boolean` | Whether a keyboard focus is inside the trail (`ChainOfThought`) | | `isPending` | `boolean` | Whether the trigger is waiting on an operation (`Trigger`) | | `isPressed` | `boolean` | Whether the trigger is currently pressed (`Trigger`) | | `isHovered` | `boolean` | Whether the trigger is hovered (`Trigger`) | | `isFocused` | `boolean` | Whether the trigger is focused (`Trigger`) | | `isFocusVisible` | `boolean` | Whether the trigger is focused by keyboard (`Trigger`) | # ChatAttachment > File previews and drag-and-drop input for chat **Category**: components **URL**: https://peakui.pro/en/docs/react/components/chat-attachment **Source**: https://raw.githubusercontent.com/peakui-dev/peakui-pro/refs/heads/main/apps/docs/content/docs/en/react/components/(ai)/chat-attachment.mdx ## Usage ```tsx import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput} from "@peakui-pro/react"; ``` ```tsx import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react"; // A picture that needs no network: a diagonal wash between two colours. const picture = `data:image/svg+xml,${encodeURIComponent( '', )}`; export function Basic() { return ( ); } ``` ### Anatomy ```tsx import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput} from "@peakui-pro/react"; export default () => ( <> {/* Without children: Preview, then Info. An image or video with a `src` is a thumbnail. */} {/* The picker. An icon alone needs `isIconOnly` or an `aria-label` to be named. */} {/* The drop target is your element: spread the props, and render `props.children`. */}
}> {content} ); ``` ## Examples ### Grouped `ChatAttachmentGroup` wraps attachments in a row that wraps. ```tsx import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react"; const picture = `data:image/svg+xml,${encodeURIComponent( '', )}`; export function Grouped() { return ( ); } ``` ### Formats `mimeType` picks the icon, then the extension of `name`; `generic` is last. ```tsx import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react"; export function Formats() { return ( ); } ``` ### Removable `Remove` sits in the row of a card and in the corner of a thumbnail. ```tsx "use client"; import {ChatAttachment, ChatAttachmentGroup} from "@peakui-pro/react"; import {useState} from "react"; const picture = `data:image/svg+xml,${encodeURIComponent( '', )}`; const files = [ {mimeType: "application/pdf", name: "project-brief.pdf", size: 824_120}, {mediaType: "image", name: "screenshot.png", size: 248_320, src: picture}, ] as const; export function Removable() { const [removed, setRemoved] = useState([]); return ( {files .filter(({name}) => !removed.includes(name)) .map((file) => ( setRemoved((current) => [...current, file.name])} /> ))} ); } ``` ### Composer Revoke each `blob:` URL on removal, on clear and on unmount. ```tsx "use client"; import {ArrowUp, Paperclip} from "@gravity-ui/icons"; import {Button, TextArea} from "@peakui/react"; import {ChatAttachment, ChatAttachmentGroup, ChatAttachmentInput} from "@peakui-pro/react"; import {useEffect, useRef, useState} from "react"; type Attached = {file: File; id: number; url?: string}; export function Composer() { const [attached, setAttached] = useState([]); const urls = useRef(new Set()); const count = useRef(0); // The object URLs are created here, so they are revoked here: on removal, on clear and on unmount. const revoke = (url?: string) => { if (url && urls.current.delete(url)) URL.revokeObjectURL(url); }; useEffect(() => { const held = urls.current; return () => { for (const url of held) URL.revokeObjectURL(url); held.clear(); }; }, []); const add = (files: File[]) => setAttached((current) => [ ...current, ...files.map((file) => { const url = /^(image|video)\//.test(file.type) ? URL.createObjectURL(file) : undefined; if (url) urls.current.add(url); count.current += 1; return {file, id: count.current, url}; }), ]); const remove = (item: Attached) => { revoke(item.url); setAttached((current) => current.filter(({id}) => id !== item.id)); }; const clear = () => { for (const item of attached) revoke(item.url); setAttached([]); }; return ( ( // Merge `className`: it carries `chat-attachment-dropzone`, which draws the drag outline.
{/* Keeps RAC's hidden drop button, which keyboards and screen readers drop onto. */} {props.children}
)} > {attached.length > 0 && ( {attached.map((item) => ( remove(item)} /> ))} )}