PeakUIPro

ChatTool

Collapsible tool-call card with states and approval

Usage

ChatTool is imported from its own subpath: it renders a CodeBlock, which needs the optional shiki peer.

npm install shiki
import {ChatTool, ChatToolGroup} from "@peakui-pro/react/chat-tool";

Anatomy

import {ChatTool, ChatToolGroup} from "@peakui-pro/react/chat-tool";

export default () => (
  <ChatToolGroup>
    <ChatToolGroup.Trigger>2 tool calls</ChatToolGroup.Trigger>
    <ChatToolGroup.Content>
      {/* Without children, a ChatTool renders all of the parts below from its props. */}
      <ChatTool state="approval-requested" toolName="sendEmail">
        {/* An h3 holding the core disclosure trigger; `level` sets the heading level. */}
        <ChatTool.Trigger>
          <ChatTool.StatusIcon />
          Approval needed: sendEmail
        </ChatTool.Trigger>
        <ChatTool.Content>
          <ChatTool.Args input={{to: "team@acme.com"}} label="Input" />
          <ChatTool.Result label="Result" value={{sent: true}} />
          <ChatTool.Error>Request timed out</ChatTool.Error>
          <ChatTool.Approval>
            <ChatTool.ApprovalActions>
              <ChatTool.Reject />
              <ChatTool.Approve />
            </ChatTool.ApprovalActions>
          </ChatTool.Approval>
        </ChatTool.Content>
      </ChatTool>
    </ChatToolGroup.Content>
  </ChatToolGroup>
);

Examples

Streaming

argsText shows partial input as it is while the label shimmers.

Error State

Approval

An uncontrolled card opens whenever its state becomes approval-requested; a request takes one decision, and focus returns to the trigger.

Grouped

Composable

Custom Approval

States

Customization

Tailwind CSS

<ChatTool
  className="[--chat-tool-radius:0.5rem] [--chat-tool-padding:1rem]"
  output={{sent: true}}
  state="output-available"
  toolName="sendEmail"
/>

Global CSS

@layer components {
  .chat-tool {
    --chat-tool-border-color: var(--color-separator);
  }

  .chat-tool--output-error {
    --chat-tool-border-color: var(--color-danger);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ChatTool component uses these CSS classes (view source styles):

Base Classes

  • .chat-tool - Card root, beside the core .disclosure
  • .chat-tool-group - Group root, beside the core .disclosure

State Classes

  • .chat-tool--input-streaming
  • .chat-tool--input-available
  • .chat-tool--approval-requested - Outlined in the warning tone
  • .chat-tool--approval-responded
  • .chat-tool--output-available
  • .chat-tool--output-error
  • .chat-tool--output-denied
  • .chat-tool--interrupted

Element Classes

  • .chat-tool__trigger - Trigger row, beside the core .disclosure__trigger
  • .chat-tool__trigger-label - Status glyph, prefix and name
  • .chat-tool__tool-name - Tool name in the preset label
  • .chat-tool__indicator - Chevron, beside the core .disclosure__indicator
  • .chat-tool__status - Status glyph wrapper
  • .chat-tool__status-icon - Status glyph
  • .chat-tool__content - Panel, beside the core .disclosure__content
  • .chat-tool__content-body - Column of sections
  • .chat-tool__args - Input section
  • .chat-tool__args-label - Input label
  • .chat-tool__result - Output section
  • .chat-tool__result-label - Output label
  • .chat-tool__error - Error details
  • .chat-tool__approval - Approval section
  • .chat-tool__approval-actions - Approval button row
  • .chat-tool__approve - Approve button, beside the core .button
  • .chat-tool__reject - Reject button, beside the core .button
  • .chat-tool-group__trigger - Group trigger
  • .chat-tool-group__trigger-label - Group label
  • .chat-tool-group__indicator - Group chevron
  • .chat-tool-group__content - Group panel
  • .chat-tool-group__content-body - Column of cards

Slots

  • [data-slot="chat-tool"]
  • [data-slot="chat-tool-trigger"]
  • [data-slot="chat-tool-trigger-label"]
  • [data-slot="chat-tool-tool-name"]
  • [data-slot="chat-tool-status"]
  • [data-slot="chat-tool-status-icon"]
  • [data-slot="chat-tool-content"]
  • [data-slot="chat-tool-content-body"]
  • [data-slot="chat-tool-args"]
  • [data-slot="chat-tool-args-label"]
  • [data-slot="chat-tool-result"]
  • [data-slot="chat-tool-result-label"]
  • [data-slot="chat-tool-error"]
  • [data-slot="chat-tool-approval"]
  • [data-slot="chat-tool-approval-actions"]
  • [data-slot="chat-tool-approve"]
  • [data-slot="chat-tool-reject"]
  • [data-slot="chat-tool-group"]
  • [data-slot="chat-tool-group-trigger"]
  • [data-slot="chat-tool-group-trigger-label"]
  • [data-slot="chat-tool-group-content"]
  • [data-slot="chat-tool-group-content-body"]

The core parts inside keep their own slots: disclosure-heading, disclosure-indicator, disclosure-body and disclosure-body-inner.

CSS Variables

VariablePurpose
--chat-tool-border-colorCard outline; defaults to var(--color-border), the warning tone while approval is requested
--chat-tool-radiusCard corner radius; defaults to var(--radius-xl)
--chat-tool-paddingCard inset; defaults to 0.75rem
--chat-tool-gapSpace between sections and inside the trigger; defaults to 0.5rem
--chat-tool-status-sizeStatus glyph and chevron size; defaults to 0.875rem
--chat-tool-success-colorGlyph of a finished call; defaults to var(--color-success)
--chat-tool-danger-colorGlyph and text of a failed call; defaults to var(--color-danger-soft-foreground)
--chat-tool-warning-colorGlyph and outline of a call awaiting approval; defaults to var(--color-warning)
--chat-tool-muted-colorGlyph of every other state; defaults to var(--color-muted)
--chat-tool-group-gapSpace between grouped cards; defaults to 0.5rem

Interactive States

  • Hover: :hover or [data-hovered] on a trigger brings the label forward from the muted tone
  • Focus: :focus-visible or [data-focus-visible] on a trigger, the core ring
  • Expanded: [data-expanded="true"] on the root, the panel and the chevron
  • State: [data-state] on the root, the normalized state
  • Active: [data-active="true"] while the call is in flight (input-streaming, input-available, approval-responded)
  • Decided: [data-decided="true"] on Approve and Reject once a decision is taken, until the state moves on
  • Expandable: [data-expandable="false"] when there is nothing to open; the trigger is disabled but keeps its colour
  • Forced colors: @media (forced-colors: active) draws the card in CanvasText and paints glyphs in the text colour

API Reference

ChatTool

PropTypeDefaultDescription
state'input-streaming' | 'input-available' | 'approval-requested' | 'approval-responded' | 'output-available' | 'output-error' | 'output-denied' | 'interrupted' | 'requires-action'-Where the call is; requires-action is another name for approval-requested
toolNamestring-Tool display name in the preset trigger
triggerPrefixReactNodeper stateReplaces the prefix: "Running tool: ", "Approval needed: ", "Used tool: ", "Failed tool: ", "Denied tool: ", "Interrupted tool: "
inputunknown-Tool input, shown as JSON (a string as it is)
outputunknown-Tool output, shown as JSON (a string as it is)
argsTextstring-Raw input text, for partial JSON while streaming; shown when input is absent
errorTextstring-Error details for a failed call
onApprove() => void-Called by the approve action
onReject() => void-Called by the reject action
defaultExpandedbooleantrue while approval is requestedOpen on first render, for an uncontrolled card
isExpandedboolean-The expanded state, for a controlled card
onExpandedChange(isExpanded: boolean) => void-Handler called when the expanded state changes
childrenReactNode-Your own parts; without children the card renders the preset
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

ChatTool.Trigger

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 63Level of the heading that holds the trigger
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)status glyph, prefix and toolNameThe label. While the call is active it shimmers and is rendered twice, so keep it to text and inline markup
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes
renderDOMRenderFunction<'button', ButtonRenderProps>-Replaces the rendered element; receives the props with data-slot set
...restButtonProps-Every other React Aria Button prop

ChatTool.StatusIcon

PropTypeDefaultDescription
childrenReactNodethe state's glyphReplaces the glyph; hidden from assistive technology
classNamestring-Additional classes
renderDOMRenderFunction<'span', undefined>-Replaces the rendered <span>
...restComponentProps<'span'>-Native <span> attributes

ChatTool.Content

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

ChatTool.Args

PropTypeDefaultDescription
inputunknownthe root's input, then argsTextValue shown as JSON (a string as it is)
labelReactNode-Heading above the value
childrenReactNodea CodeBlockReplaces the code block
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restOmit<ComponentProps<'div'>, 'children'>-Native <div> attributes

ChatTool.Result

PropTypeDefaultDescription
valueunknownthe root's outputValue shown as JSON (a string as it is)
labelReactNode-Heading above the value
childrenReactNodea CodeBlockReplaces the code block
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restOmit<ComponentProps<'div'>, 'children'>-Native <div> attributes

ChatTool.Error

PropTypeDefaultDescription
childrenReactNodethe root's errorTextError details
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restComponentProps<'div'>-Native <div> attributes

ChatTool.Approval

PropTypeDefaultDescription
childrenReactNodeApprovalActions with Reject and ApproveYour copy and the actions
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restComponentProps<'div'>-Native <div> attributes

ChatTool.ApprovalActions

PropTypeDefaultDescription
childrenReactNode-The buttons, aligned to the end
classNamestring-Additional classes
renderDOMRenderFunction<'div', undefined>-Replaces the rendered <div>
...restComponentProps<'div'>-Native <div> attributes

ChatTool.Approve and ChatTool.Reject

PropTypeDefaultDescription
childrenReactNode'Approve' / 'Reject'Button label
onPress(e: PressEvent) => voidthe root's onApprove / onRejectReplaces the root's handler. Either way, only the first press of Approve or Reject per approval request runs; later presses are ignored until the state changes. If the approval unmounts while one of them has focus, focus moves to the card's trigger
variant'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'danger' | 'danger-soft''primary' / 'secondary'Core button style
size'sm' | 'md' | 'lg''sm'Core button size
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes
renderDOMRenderFunction<'button', ButtonRenderProps>-Replaces the rendered element; receives the props with data-slot set
...restButtonProps-Every other core Button prop

ChatToolGroup

PropTypeDefaultDescription
defaultExpandedboolean-Open on first render
isExpandedboolean-The expanded state, for a controlled group
onExpandedChange(isExpanded: boolean) => void-Handler called when the expanded state changes
classNamestring | ((values: DisclosureRenderProps) => string)-Additional classes
renderDOMRenderFunction<'div', DisclosureRenderProps>-Replaces the rendered <div>; receives the props with data-slot set
...restComponentProps<typeof Disclosure>-Every other core Disclosure prop

ChatToolGroup.Trigger

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 63Level of the heading that holds the trigger
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-The label, such as "2 tool calls"
renderDOMRenderFunction<'button', ButtonRenderProps>-Replaces the rendered element; receives the props with data-slot set
...restButtonProps-Every other React Aria Button prop

ChatToolGroup.Content

PropTypeDefaultDescription
childrenReactNode-The grouped ChatTool cards
renderDOMRenderFunction<'div', DisclosurePanelRenderProps>-Replaces the rendered panel; receives the props with data-slot set
...restComponentProps<typeof Disclosure.Content>-Every other core panel prop

Render Props

PropTypeDescription
isExpandedbooleanWhether the card or group is open (root, Content)
isDisabledbooleanWhether the control is disabled (root, Trigger)
isFocusVisibleWithinbooleanWhether a keyboard focus is inside (root)
isPressedbooleanWhether the trigger is pressed (Trigger)
isHoveredbooleanWhether the trigger is hovered (Trigger)
isFocusVisiblebooleanWhether the trigger is focused by keyboard (Trigger)

On this page