# Tray

A composer-docked panel for questions, approvals, queued messages and pickers.

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

```tsx
import {
  Tray, TrayHeader, TrayTitle, TrayBody, TrayFooter, TrayOption, TrayStep,
  TrayAnswer,
} from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import {
  Icon, Button, IconButton, Tray, TrayHeader, TrayTitle, TrayBody, TrayOption,
  TrayFooter,
} from "@arcadia/ui";

function Question() {
  const [picked, setPicked] = useState("a");
  const options = [
    { id: "a", label: "Population (divide by N)", description: "Recommended" },
    { id: "b", label: "Sample (divide by N−1)" },
  ];
  return (
    <Tray aria-label="Questions" role="group">
      <TrayHeader>
        <TrayTitle>Questions</TrayTitle>
        <IconButton icon="minus" label="Minimise" size="xs" tone="muted" />
      </TrayHeader>
      <TrayBody layout="text">
        <span {...sx("cmp-strong", cmp.strong)}>
          Should variance use the population or the sample formula?
        </span>
      </TrayBody>
      <TrayBody role="radiogroup" aria-label="Answer">
        {options.map((o, i) => (
          <TrayOption
            key={o.id}
            badge={String.fromCharCode(65 + i)}
            label={o.label}
            description={o.description}
            selected={picked === o.id}
            onClick={() => setPicked(o.id)}
          />
        ))}
        <TrayOption
          badge={<Icon name="pencil" />}
          label="Other"
          selected={picked === "c"}
          onClick={() => setPicked("c")}
        />
      </TrayBody>
      <TrayFooter start={<Button size="sm" variant="text">Skip</Button>}>
        <Button size="sm" variant="primary" hint="⏎">Next</Button>
      </TrayFooter>
    </Tray>
  );
}
```

## Accessibility

`TrayOption` supplies `role="radio"` or `"checkbox"` with `aria-checked`; the surrounding body owns the group role, as above (`radiogroup`, `group`). A tray is not modal: focus stays where it was when one arrives, so announce a new question with a live region or move focus to it on purpose.

A `readOnly` option is no control: no role, no checked state and no focus, read as its words, the chosen one followed by "chosen".

The keys belong to the flow around the tray. A question flow should handle these:

- 1 to 9: Pick an option by its number
- ↓ + ↑: Move between options
- Space: Toggle a checkbox option
- Enter: Submit the answer

## API reference

### Tray

- `nesting` (`"contained-object"`): Mark an independent tray contained in another surface. A tray docked beside the composer needs no mark.
- `placement` (`"above" | "below" | "drop"`, default `"above"`): Which side of the composer it docks to. `above` rises from below; `below` drops from above. `drop` hangs under the box it stands in with the composer (a positioned dock), over what follows, a popup's shadow under it, so the page under the composer does not move (a home page's pickers).
- `motion` (`"enter" | "static"`, default `"enter"`): `enter`: 120ms rise + fade on mount, 90ms fade on close. Only event-driven trays animate (a question or approval arriving, a message queued). `static`: appears and leaves instantly: hydrated trays and the `+`, `/` and `@` pickers, which open at once.
- `open` (`boolean`): Omit to mount and unmount the tray yourself (no exit motion). Pass it to let the tray keep itself mounted for its exit fade (`data-exiting`, `inert`) and unmount afterwards.
- `rootStyle` (`RootStyle<TrayKnobs>`): Typed StyleX override: where the tray sits (layout) and its `--tray-*` knobs.

Rest props go to `<div>` props and `render`.

### TrayHeader

- `subtitle` (`ReactNode`): Muted continuation or reset text under the title. Omit it when there is no second line.
- `actions` (`ReactNode`): An inline remedy after the title and before Dismiss. Put multiple recovery actions in TrayFooter.
- `onDismiss` (`() => void`): Pass only if this tray can be dismissed. Called by the named Dismiss button; the caller owns its effect.
- `dismissDisabled` (`boolean`, default `false`): The Dismiss button is disabled: drawn, not pressable.
- `dismissProps` (`ButtonAttrs`): The caller's own marks on the Dismiss button: its `data-*` and an accessible name, never a class, a style or a handler.

Rest props go to `<div>` props and `render`.

### TrayTitle

- `wrap` (`boolean`, default `false`): Wrap complete notice copy instead of cutting it to one line.

Rest props go to `<span>` props and `render`.

### TrayBody

- `layout` (`"rows" | "text"`, default `"rows"`): `rows`: ListRows / TrayOptions inset 6px. `text`: prose aligned with the header text.
- `glide` (`boolean`, default `false`): One highlight that glides between the rows (a picker's `+`, `/` or `@` list); see Glide.

Rest props go to `<div>` props and `render`.

### TrayFooter

- `divided` (`boolean`, default `false`): Hairline above the footer.
- `start` (`ReactNode`): Left-aligned group (a pager, a hint, a text button on the text column); the children stay at the end.

Rest props go to `<div>` props and `render`.

### TrayOption

- `kind` (`"single" | "multiple"`, default `"single"`): `single`: a lettered/numbered badge, `role="radio"`. `multiple`: a checkbox, `role="checkbox"`.
- `badge` (`ReactNode`): Badge content for `single` ("1", "A", or an Icon for "Other").
- `selected` (`boolean`, default `false`)
- `label` (`ReactNode`): The option text (or pass it as children).
- `description` (`ReactNode`): Quieter text after the label (text-3).
- `readOnly` (`boolean`, default `false`): Shown, not asked: nothing to press.
- `disabled` (`boolean`, default `false`): Text-4, not selectable.

Rest props go to `<button>` props and `render`.

### TrayStep

- `step` (`number`, required): The step that shows, counted from 0. A change enters from the side it came from.

Rest props go to `<div>` props and `render`.

### TrayAnswer

- `question` (`ReactNode`, required): The question, as it was put.
- `answer` (`ReactNode`, required): What the person chose, or the words they gave.

Rest props go to `<div>` props and `render`.
