PeakUIPro

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

VariablePurpose
--chain-of-thought-indicator-sizeChevron width and height; defaults to 0.875rem
--chain-of-thought-trigger-gapSpace between the label and the chevron; defaults to 0.5rem
--chain-of-thought-steps-gapSpace between steps; defaults to 0.75rem
--chain-of-thought-steps-insetSpace between the rule and the steps; defaults to 0.75rem
--chain-of-thought-line-colorColor of the rule; defaults to var(--color-separator)
--chain-of-thought-step-gapSpace between a step's header and body; defaults to 0.25rem
--chain-of-thought-step-header-gapSpace between the marker and the label; defaults to 0.5rem
--chain-of-thought-marker-sizeMarker dot diameter; defaults to 0.375rem
--chain-of-thought-marker-colorMarker dot color, drawn at 40% opacity; defaults to var(--color-muted)
--chain-of-thought-label-colorStep 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

PropTypeDefaultDescription
isStreamingbooleanfalseThe trail is still being written: the trigger label shimmers and the root gets --streaming instead of --complete
defaultExpandedboolean-Open on first render, for an uncontrolled root
isExpandedboolean-The expanded state, for a controlled root; pair it with onExpandedChange
onExpandedChange(isExpanded: boolean) => void-Handler called when the expanded state changes
isDisabledbooleanfalseWhether the disclosure is disabled
childrenReactNode | ((values: DisclosureRenderProps) => ReactNode)-Content to render, or a function of the render props
classNamestring | ((values: DisclosureRenderProps) => string)-Additional classes, or a function of the render props
renderDOMRenderFunction<'div', DisclosureRenderProps>-Replaces the rendered <div>; receives the props with data-slot set
...restComponentProps<typeof Disclosure>-Every other core Disclosure prop

ChainOfThought.Trigger

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 63Level 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
childrenReactNode | ((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
isDisabledbooleanfalseWhether the trigger is disabled
onPress(e: PressEvent) => void-Handler called when the trigger is pressed
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the button's state
renderDOMRenderFunction<'button', ButtonRenderProps>-Replaces the rendered element; receives the props with data-slot set
...restButtonProps-Every other core Button prop

ChainOfThought.Content

PropTypeDefaultDescription
childrenReactNode-The panel's body. Nodes only: a render function is not supported, because the core's panel draws one as nothing
classNamestring | ((values: DisclosurePanelRenderProps) => string)-Additional classes, or a function of the render props
renderDOMRenderFunction<'div', DisclosurePanelRenderProps>-Replaces the rendered panel; receives the props with data-slot set
...restComponentProps<typeof Disclosure.Content>-Every other core panel prop

ChainOfThought.Steps

PropTypeDefaultDescription
rolestring"list"The steps are a list in substance: a screen reader announces the count and the item boundaries
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div> with your own element
...restComponentProps<'div'>-Native <div> attributes

ChainOfThought.Step

PropTypeDefaultDescription
labelReactNode-A short name for the step, drawn above its body beside a marker
childrenReactNode-The step's body. A Step is a listitem and belongs inside Steps: outside it, an accessibility audit flags the orphaned item
rolestring"listitem"Item boundary for a screen reader
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div> with your own element
...restOmit<ComponentProps<'div'>, 'children'>-Native <div> attributes

Render Props

PropTypeDescription
isExpandedbooleanWhether the trail is open (ChainOfThought, Content)
isDisabledbooleanWhether the control is disabled (ChainOfThought, Trigger)
isFocusVisibleWithinbooleanWhether a keyboard focus is inside the trail (ChainOfThought)
isPendingbooleanWhether the trigger is waiting on an operation (Trigger)
isPressedbooleanWhether the trigger is currently pressed (Trigger)
isHoveredbooleanWhether the trigger is hovered (Trigger)
isFocusedbooleanWhether the trigger is focused (Trigger)
isFocusVisiblebooleanWhether the trigger is focused by keyboard (Trigger)

On this page