Reasoning

Slant / People & chat

A model’s thinking: open and shimmering while it thinks, folded away when done.

Demo

Assistant

Usage

@tuttn/slant
import { Reasoning } from '@tuttn/slant'

// Open, with the title shimmering "Thinking…", while the model thinks; folded
// under "Thought for 4 seconds" once thinking turns false.
<Reasoning thinking={streaming} duration={seconds}>{reasoningText}</Reasoning>

// A reader who opens or closes it mid-thought keeps it that way. Controlled,
// open wins, and the folding only reaches onOpenChange.
<Reasoning thinking={streaming} duration={seconds} open={open} onOpenChange={setOpen}>
  {reasoningText}
</Reasoning>

// Your own title. It still shimmers while thinking.
<Reasoning thinking={streaming} title="Planning the migration">{plan}</Reasoning>

Props

PropTypeDefaultDescription
thinkingbooleanfalseWhile true, the title shimmers ("Thinking…") and the panel opens to show the reasoning as it streams in. When it turns false the panel folds itself away, unless the reader opened or closed it meanwhile, or `open` is controlled.
durationnumber—How long the model thought, in seconds, for the title once it is done ("Thought for 4 seconds").
titleReactNodemessages.thinking, then messages.thoughtFor(duration)Replaces the title. It shimmers while thinking.
defaultOpenbooleanthinkingWhether the panel starts open when uncontrolled.
openboolean—Whether the panel is open. Pass it to control the disclosure; leave it out and it keeps its own state.
onOpenChange(open: boolean) => void—Called with the requested state when the toggle is pressed.
heading'h2' | 'h3' | 'h4' | 'div'—The element wrapping the toggle button, so it sits in the page's outline.
disabledboolean—Disables the toggle button: the panel stays as it is, open or closed, and the toggle leaves the tab order.
togglePropsOmit<ButtonHTMLAttributes<HTMLButtonElement>, 'type' | 'disabled' | 'aria-expanded' | 'aria-controls' | 'children'>—Extra attributes for the toggle button, such as `id`, `aria-describedby` or `aria-disabled`. With `aria-disabled` the toggle stays focusable but a press does nothing. Its `onClick` runs first and can call `preventDefault()` to keep the panel as it is.
childrenReactNode—The panel's content. The panel sets a muted body text style, so pass plain text or `Text`.
…restHTMLAttributes<HTMLDivElement>—The ref, className, style and other attributes go on the root div, which carries `data-thinking` while thinking. `heading`, `disabled` and `toggleProps` work as on Disclosure.

Keyboard

Tabfocuses the toggle
Enter / Spaceopens or folds the reasoning

Accessibility

  • The toggle is a button inside a heading (heading, an h3 by default), with aria-expanded and aria-controls on the panel, as Disclosure’s.
  • The title stays real text while it shimmers, so the button is named “Thinking…” and then “Thought for 4 seconds”. The sparkle before it is hidden from screen readers.
  • When thinking ends it announces messages.thoughtFor(duration) once, politely, through the root’s announcer. The reasoning itself is not announced as it streams, so a screen reader is not read every token; open the panel to read it.
  • It folds itself only for a reader who left it alone: open or close it mid-thought and it stays as you left it.

Motion and direction

The title’s sweep is Shimmer’s: under prefers-reduced-motion it rests as plain muted text, and the panel opens without Disclosure’s fade. The hairline beside the reasoning sits at the inline start, so under dir="rtl" it moves to the right and the sweep runs from the right.

Content

The panel sets smaller muted text for the reasoning, so pass plain text, or Text variant="hint", rather than body text.

Full source