# Collapsible

The one disclosure: a header with an action, details, a figure beside them and a chevron, over an animated panel; a section of rows under a heading that folds them; the rest of a list under Show more.

Live variants: https://design.arcadia.is/components/collapsible

```tsx
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, CollapsibleHold,
} from "@arcadia/ui";
```

## When to use

- A standalone fold that opens content in place
- A settings section whose switches open in place
- A group of rows under a quiet heading that folds them, with `variant=&quot;section&quot;`
- The rest of a long list, folded under a Show more press after it, with `variant=&quot;more&quot;`

## When not to use

- An activity, tool or state timeline: use `Status`
- A pane's plain list of rows that each open: use `DisclosureList`
- A full-width row of a card that opens under itself: use `DisclosureRow`

## In context

In Act, an agent's conversation keeps its work folded behind these rows, each closed until opened.

```tsx
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, ScrollArea,
} from "@arcadia/ui";

<Collapsible tone="muted">
  <CollapsibleHeader action="Ran" details="1 command, read chats" />
  <CollapsiblePanel>
    <span {...sx("cmp-detail", cmp.detail)}>Ran git status</span>
    <span {...sx("cmp-detail", cmp.detail)}>Read recent chats</span>
  </CollapsiblePanel>
</Collapsible>
<Collapsible tone="muted">
  <CollapsibleHeader
    action="Edited"
    details="src/math.ts"
    figure={<span {...sx("cmp-add", cmp.add)}>+10</span>}
  />
  <CollapsiblePanel>
    <ScrollArea orientation="horizontal" scrollbar="hidden" label="Code">
      <pre {...sx("cmp-code", cmp.code)}>
        {"export const clamp = (v: number, lo: number, hi: number) =>\n"}
        {"  Math.min(hi, Math.max(lo, v));"}
      </pre>
    </ScrollArea>
  </CollapsiblePanel>
</Collapsible>
<Collapsible loading>
  <CollapsibleHeader action="Running" details="make test" />
  <CollapsiblePanel>
    <span {...sx("cmp-detail", cmp.detail)}>12 pass so far</span>
  </CollapsiblePanel>
</Collapsible>
```

## Usage

```tsx
import { Collapsible, CollapsibleHeader, CollapsiblePanel } from "@arcadia/ui";

<Collapsible>
  <CollapsibleHeader action="Thought" details="12s" />
  <CollapsiblePanel>
    The user wants clamp and lerp in src/math.ts, with tests.
  </CollapsiblePanel>
</Collapsible>
```

Thinking rows, tool lines, step groups, the work summary, notices and settings sections: every disclosure is this one. The header reads action, details, the chevron, then an optional figure (what the step came to: a count, a time, line changes). The figure stands a small step after the chevron in `--text-3` with tabular figures, never at the line's far end; long details end in an ellipsis and keep the figure whole. The chevron follows the words, appears on hover or focus and turns 90° when open; it holds its room at rest, so the figure never moves. Where nothing can hover (a touch screen) it stands at rest, as under the pointer. The panel is the kit's one fold, `Unfold`: it opens over 200ms and closes over 160ms on `--ease-enter` while its content fades, and the chevron turns on the same clock both ways, out over 200ms and back over 160ms, so the two end together.

A press answers as a row does, at once: the header shows no ground, so its ink steps to text-1, the words and the chevron, and nothing scales. Let go, it eases back on the colour beat.

## Examples

### A settings section

Use `sm` for UI text. `chevron="end"` stretches the header across the row and places the chevron at the far edge.

```tsx
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, Switch,
} from "@arcadia/ui";

<Collapsible size="sm">
  <CollapsibleHeader icon="settings" action="Advanced" details="3 settings" chevron="end" />
  <CollapsiblePanel>
    <Switch label="Send anonymous usage data" defaultChecked />
    <Switch label="Check for updates on launch" defaultChecked />
    <Switch label="Show the developer menu" />
  </CollapsiblePanel>
</Collapsible>
```

### A header that fills its card

`--collapsible-header-px` sets where the header's words start inside the box it fills: here a card's fold, its words on the card's own inset, with `--collapsible-ring-pad` at 0 so it hangs out by nothing.

```tsx
import { Card, Collapsible, CollapsibleHeader } from "@arcadia/ui";

<Card>
  <Collapsible size="sm" rootStyle={framed.fold}>
    <CollapsibleHeader action="To do" details="3 of 5 done" chevron="end" />
  </Collapsible>
</Card>
```

### A figure after the chevron

An inline chevron stands right after the words, so a figure (what the step came to) follows it and never pushes it along: the fold's mark keeps its place as the figure changes.

```tsx
import { Collapsible, CollapsibleHeader } from "@arcadia/ui";

<Collapsible tone="muted" rootStyle={framed.rest}>
  <CollapsibleHeader action="Worked for" figure="53.3s, 1 file" />
</Collapsible>
```

### Nested

A work summary holding its steps. `expandable={false}` keeps the anatomy without a toggle, for a step with nothing to show.

```tsx
import { Collapsible, CollapsibleHeader, CollapsiblePanel } from "@arcadia/ui";

<Collapsible tone="muted" defaultOpen>
  <CollapsibleHeader action="Worked for" details="2m 14s" />
  <CollapsiblePanel>
    <Collapsible tone="muted">
      <CollapsibleHeader action="Explored" details="4 files, 2 searches" />
      <CollapsiblePanel>Read README.md</CollapsiblePanel>
    </Collapsible>
    <Collapsible tone="muted" expandable={false}>
      <CollapsibleHeader action="Checked" details="to-do list" />
    </Collapsible>
  </CollapsiblePanel>
</Collapsible>
```

### Sections that fold

`variant="section"` puts rows under a quiet heading that folds them: the name in Caption and the quietest ink, its count (the header's `figure`) after it, the chevron at rest at the heading's far end, on the edge the rows' trailing controls end on.

```tsx
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, ListRow, ListRows,
} from "@arcadia/ui";

function Sections() {
  return (
    <div {...sx("cmp-rows", cmp.rows)} data-width="pane">
      <ListRows>
        {TEAMS.map((t, i) => (
          <Collapsible key={t.name} variant="section" later={i > 0}>
            <CollapsibleHeader action={t.name} figure={t.agents.length} />
            <CollapsiblePanel>
              {t.agents.map(([name, when]) => <ListRow key={name} leading="agent" label={name} meta={when} onClick={() => {}} />)}
            </CollapsiblePanel>
          </Collapsible>
        ))}
      </ListRows>
    </div>
  )
```

The name stands at the row inset, where a `RowSectionLabel` stands, and inside a `DisclosureList` at the list's own, so a section heads its rows wherever they are drawn. Sections start open; a later one opens a step under the rows above it with `later`. Closed, its rows stay in the page, so find in page reaches them and opens it.

```tsx
import {
  Button, Collapsible, CollapsibleHeader, CollapsiblePanel, ListRow, ListRows,
} from "@arcadia/ui";

function SectionsEnd() {
  const lines = [
    ["Atlas finished the upload retries", "Deployed to production, with 14 new tests", "6h"],
    ["Quill wrote the release notes for 2.4", "In docs/releases, ready to publish", "8h"],
    ["The export test timed out again", "On slow machines, twice this week", "9h"],
  ] as const;
  return (
    <div {...sx("cmp-rows", cmp.rows)} data-width="pane">
      <ListRows>
        <Collapsible variant="section">
          <CollapsibleHeader action="Launch week" figure={8} end={<Button size="xs" variant="ghost" onClick={open}>Mark all read</Button>} />
          <CollapsiblePanel>
            {lines.map(([title, line, when]) => (
              <ListRow key={title} leading="agent" label={title} sub={line} meta={when} emphasis onClick={open} />
            ))}
          </CollapsiblePanel>
        </Collapsible>
      </ListRows>
    </div>
  );
}
```

The header's `end` puts the section's one press at the end of its heading, at rest, a step before the chevron: a quiet button such as Mark all read. The heading still folds from its own words, and the press is a stop of its own after them.

### A section on a lane's edge

`--collapsible-section-px` sets where a section's words and chevron stand, so it can head rows that start 4 in: here a lane's head above it, its cards' inset. Default: the row inset.

```tsx
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, ListRow, ListRows,
} from "@arcadia/ui";

<div {...sx("cmp-rows", cmp.rows)} data-width="pane">
  <span {...stylex.props(lanes.head)}>Doing</span>
  <ListRows>
    <Collapsible variant="section" rootStyle={lanes.inset}>
      <CollapsibleHeader action="Tasks" figure={3} />
      <CollapsiblePanel>
        {[["Move the upload test to the staging runner", "2m"], ["Write the release notes", "1h"], ["Pin the fixture server's port", "3d"]].map(([name, when]) => (
          <ListRow key={name} leading="task" label={name} meta={when} onClick={() => {}} />
        ))}
      </CollapsiblePanel>
    </Collapsible>
  </ListRows>
</div>
```

### Show more

`variant="more"` folds the rest of a list under a quiet press that stands after it, its chevron turning as it opens. The root draws no box, so the panel and the press lay out as the list's own items, on its gaps.

```tsx
import { useState } from "react";
import {
  Collapsible, CollapsibleHeader, CollapsiblePanel, ListRow, ListRows,
} from "@arcadia/ui";

function More() {
  const [shown, setShown] = useState(false);
  return (
    <div {...sx("cmp-rows", cmp.rows)} data-width="pane">
      <ListRows>
        {TOOLS.slice(0, FEW).map(name => <ListRow key={name} label={name} onClick={open} />)}
        <Collapsible variant="more" open={shown} onOpenChange={setShown}>
          <CollapsiblePanel>
            {TOOLS.slice(FEW).map(name => <ListRow key={name} label={name} onClick={open} />)}
          </CollapsiblePanel>
          <CollapsibleHeader action={shown ? "Show fewer" : `Show ${TOOLS.length - FEW} more`} />
        </Collapsible>
      </ListRows>
    </div>
  );
}
```

### Small

`sm` is Body, for cards and trays; `md`, the default, is Headline, conversation text; `xs` is Caption, a disclosure that ends a quiet line, as a settings row's `fold` does.

```tsx
import { Collapsible, CollapsibleHeader, CollapsiblePanel } from "@arcadia/ui";

<Collapsible size="sm" tone="muted" defaultOpen>
  <CollapsibleHeader icon="todo" action="3 of 3 to-dos" details="Completed" />
  <CollapsiblePanel>
    <span {...sx("cmp-detail", cmp.detail)}>Read the code</span>
    <span {...sx("cmp-detail", cmp.detail)}>Add clamp and lerp</span>
    <span {...sx("cmp-detail", cmp.detail)}>Run the tests</span>
  </CollapsiblePanel>
</Collapsible>
```

## Matrix

Tone and state

Rows: Neutral, Muted, Loading, Static. Columns: Rest, Open, Hover, Focus.

## Customising

`rootStyle` on the root takes where the disclosure sits and these knobs, which its header and panel read; tones and sizes only reassign them, and hover reads its own (`--collapsible-action-hover`), so a colour you set never drops it. Set `data-instant` on any ancestor to still every transition inside it.

- `--collapsible-gap` (`Ref<Space> | Ref<"--stream-gap"> | "0px"`, default `var(--space-1)`): Gap between the panel's children (and above the first).
- `--collapsible-figure-gap` (`Ref<Space>`, default `var(--space-1)`): Gap between the figure's items.
- `--collapsible-icon` (`Paint`, default `var(--icon-3)`): The leading glyph.
- `--collapsible-icon-hover` (`Paint`, default `var(--icon-1)`)
- `--collapsible-action` (`Paint`, default `var(--text-2)`): The verb ("Explored").
- `--collapsible-action-hover` (`Paint`, default `var(--text-1)`): The verb under the pointer.
- `--collapsible-details` (`Paint`, default `var(--text-3)`): The object ("4 files, 2 searches").
- `--collapsible-details-hover` (`Paint`, default `var(--text-1)`): The object under the pointer.
- `--collapsible-figure` (`Paint`, default `var(--text-3)`)
- `--collapsible-figure-hover` (`Paint`, default `var(--text-1)`)
- `--collapsible-ring-pad` (`Ref<Space> | "0px"`, default `var(--space-0-5)`): How far the header and panel hang past the start edge: room for the inset focus ring.
- `--collapsible-header-px` (`Ref<Space> | "0px"`, default `var(--collapsible-ring-pad)`): The header's inline padding, where its words start inside the box it fills (a header that fills its card). Default `--collapsible-ring-pad`, which it hangs out by, so its words stay on the text edge.
- `--collapsible-header-min-h` (`Ref<Control> | "0px"`, default `0px`): Least height of a header, interactive or static. The default keeps the transcript's line geometry.
- `--collapsible-chevron-rest` (`0 | 1`, default `0`): Keep the disclosure chevron visible at rest (0 by default; use 1 for reference navigation).
- `--collapsible-chevron-slot` (`Ref<Space> | "auto"`, default `auto`): With `chevron="start"`: the column the leading chevron is centred in (`auto`: the glyph's own box).
- `--collapsible-chevron-gap` (`Ref<Space>`, default `var(--icon-gap)`): With `chevron="start"`: from that column to the words.
- `--collapsible-end-room` (`Ref<Space> | "0px"`, default `0px`): With `chevron="end"`: the room the words leave free before the chevron, where a control of the line stands over the header's end (a section's one action): `0px` by default.
- `--collapsible-section-px` (`Ref<Space> | Ref<Measure>`): `section`: where its heading words start and its chevron, at the heading's far end, ends: over the row inset, and over a `DisclosureList`'s own.

Set `--collapsible-chevron-rest` to 1 when the disclosure should advertise itself before hover, as these reference sections do. Use `--collapsible-header-min-h` to give any header its control height, a static header included, without changing compact transcript rows. Set `wrapAction` on a header without a secondary detail label when its action must stay readable in a narrow column. With `chevron="end"`, `--collapsible-end-room` keeps the words clear of a control that stands over the line's end, before the chevron, as a section's `end` does.

## Accessibility

The header is a `<button>` with `aria-expanded`, controlling the panel. Closed panels stay in the DOM as `hidden="until-found"`, so find in page reaches collapsed output and opens it. A `loading` header's shimmer is decorative; announce the work in a live region around the stream.

A section's header sits in a heading of its `level` (3 by default), so a reader can jump between sections: the button is named with the count after a pause, "Arcadia, 6".

- Enter + Space: Toggles the panel

## API reference

### Collapsible

- `open` (`boolean`): Controlled open state.
- `defaultOpen` (`boolean`, default `variant === "section"`): Initial open state when uncontrolled. a `section` starts open.
- `variant` (`"line" | "section" | "more"`, default `"line"`): What it folds: `line`, `section` or `more` (see `CollapsibleVariant`).
- `later` (`boolean`, default `false`): `section`: not the first section of its list, so it opens a step under the rows above it.
- `onOpenChange` (`(open: boolean, details: OpenChangeDetails) => void`): Called when the header toggles it (`details.reason`: `trigger-press`) or a find-in-page match opens it.
- `disabled` (`boolean`, default `false`): Blocks toggling.
- `tone` (`"neutral" | "muted"`, default `variant === "section" ? "muted" : "neutral"`): muted: completed process rows (action and details at text-3; hover text-1 / text-2). A `section` is muted.
- `size` (`"xs" | "sm" | "md"`, default `variant === "section" ? "xs" : "md"`): The header's text style (a `section`'s is `xs`): `md` Headline, conversation text; `sm` Body, for cards and trays; `xs` Caption, a small disclosure that ends a quiet line (a settings row's `fold`).
- `expandable` (`boolean`, default `true`): false: a static line (no chevron, no toggle), same anatomy.
- `loading` (`boolean`, default `false`): Live: the action shimmers (Shimmer secondary, tertiary when muted).
- `step` (`boolean`, default `false`): A step's line (see `Steps`): the verb stays quiet and its object reads a rank up (`--text-2`).
- `instant` (`boolean`): Skip every height/opacity/rotation transition (hydration, bulk collapse, live → ended).
- `rootStyle` (`RootStyle<CollapsibleKnobs>`): Typed StyleX override: where the disclosure sits and its `--collapsible-*` knobs.

Rest props go to `<div>` props.

### CollapsibleHeader

- `action` (`ReactNode`, required): The verb: "Explored", "Thought", "Worked for". Pass a node for custom content.
- `wrapAction` (`boolean`): Wrap the action instead of fading its end when there is no secondary detail label.
- `details` (`ReactNode`): The object: "4 files, 2 searches", "12s", a path. Gives way first: long details end in an ellipsis.
- `icon` (`IconName | ReactElement`): Optional leading glyph (icon-3). The glass transcript mostly has none.
- `figure` (`ReactNode`): What the step came to ("4 results", "exit 1", "+10 −1", a live line's `Elapsed`): a small step after the words and an inline chevron, in `--text-3` with tabular figures. The words give way to it.
- `chevron` (`"inline" | "end" | "start"`, default `"inline"`): Where the chevron stands: `inline` right after the words, before a `figure`, `end` at the header's far end, `start` before the words in a column of its own (`--collapsible-chevron-slot`, a timeline's rail).
- `tone` (`"neutral" | "muted"`): Overrides the root's tone for this header only.
- `loading` (`boolean`): Overrides the root's loading state for this header only.
- `level` (`2 | 3 | 4 | 5 | 6`): `section`: the heading's rank, 3 by default; under a settings group's label, 4.
- `end` (`ReactNode`): `section`: one control at the heading's end, at rest, a step before the chevron: the section's one press (a "Mark all read"). The heading folds as it did.
- `title` (`string`): The header's hover hint. Shown as the kit Tooltip beside the row, never the native `title` attribute: a browser tooltip opens under the pointer and lands on the next line, which in a transcript covers the row below.
- `render` (`RenderProp<{ disabled: boolean }>`): Replace the rendered element, e.g. `render={<a href="/settings" />}`, or a function of props and state.
- `disabled` (`boolean`): Native disabled: no pointer events, no tooltip, skipped by Tab.
- `focusableWhenDisabled` (`boolean`): Keep a disabled control focusable and hoverable (`aria-disabled`), so a tooltip can say why.
- `nativeButton` (`boolean`): Button semantics, inferred from what renders: a `<button>` is native, an `<a>` stays a link, anything else gets `role="button"` and key handling. `false` forces button semantics on whatever renders (a link acting as a button).

Rest props go to `<button>` props.

### CollapsiblePanel

- `hiddenUntilFound` (`boolean`, default `true`): Closed panels stay in the DOM as `hidden="until-found"`, so ⌘F finds collapsed output (and opens it). `false`: the content unmounts once the fold has closed.
- `bare` (`boolean`, default `false`): Open, no header yet: no gap above, no clip. It only closes at once.

Rest props go to `<div>` props.
