ChainOfThought
Collapsible reasoning trail with a timeline of steps
Usage
import {ChainOfThought} from "@peakui-pro/react";Anatomy
import {ChainOfThought} from "@peakui-pro/react";
export default () => (
<ChainOfThought>
{/* An h3 holding the core button; `level` sets the heading level. */}
<ChainOfThought.Trigger level={3}>Thought for 4 seconds</ChainOfThought.Trigger>
{/* Nodes only: a render function draws nothing. */}
<ChainOfThought.Content>
{/* role="list" */}
<ChainOfThought.Steps>
{/* role="listitem": a Step belongs inside Steps. */}
<ChainOfThought.Step label="Search">Looked up the layout patterns.</ChainOfThought.Step>
</ChainOfThought.Steps>
</ChainOfThought.Content>
</ChainOfThought>
);Examples
Streaming
isStreaming shimmers the trigger label; the trail stays open and closable.
Agent Trace
Stack several blocks; a step's label can hold your own collapsible button.
Agent Trace Streaming
isStreaming on the block being written leaves the finished ones plain.
Controlled
isExpanded with onExpandedChange leaves the state to the host.
Disabled
isDisabled on the trigger leaves the trail as it is.
Step Shapes
A Step draws a header only with a label and a body only with children.
Customization
Tailwind CSS
<ChainOfThought className="[--chain-of-thought-steps-gap:1rem] [--chain-of-thought-indicator-size:1rem]">
<ChainOfThought.Trigger>Thought for 2s</ChainOfThought.Trigger>
<ChainOfThought.Content>
<ChainOfThought.Steps>
<ChainOfThought.Step label="Plan">Mapped the structure.</ChainOfThought.Step>
</ChainOfThought.Steps>
</ChainOfThought.Content>
</ChainOfThought>Global 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 methodology, so variants and states are plain class names you can target.
CSS Classes
The ChainOfThought component uses these CSS classes (view source styles):
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:
:hoveror[data-hovered], the label comes forward from the muted tone - Pressed:
:activeor[data-pressed], scaled to0.97by the core button - Focus:
:focus-visibleor[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 inButtonText, the marker inCanvasText, 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 <div>; receives the props with data-slot set |
...rest | ComponentProps<typeof Disclosure> | - | 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<typeof Disclosure.Content> | - | 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 <div> with your own element |
...rest | ComponentProps<'div'> | - | Native <div> 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 <div> with your own element |
...rest | Omit<ComponentProps<'div'>, 'children'> | - | Native <div> 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) |