# Composer frame

The frame a composer's field stands in: a short draft on one row, what is answered or attached above it, the controls under it, and a quiet line for a limit or an error.

Live variants: https://design.arcadia.is/components/composer-frame

```tsx
import {
  ComposerFrame, ComposerField, ComposerAttachments, validComposerMentions,
} from "@arcadia/ui";
```

The composer stays below the scrollable thread. Enter sends a sample message, and Shift+Enter adds a line.

```tsx
import { useState, useEffect, useRef } from "react";

function Usage() {
  const [draft, setDraft] = useState("");
  const [messages, setMessages] = useState<string[]>([]);
  const [attached, setAttached] = useState(false);
  const stream = useRef<HTMLDivElement>(null);

  useEffect(() => {
    if (messages.length > 0 || attached) stream.current?.scrollTo({ top: stream.current.scrollHeight });
  }, [attached, messages.length])
```

## Keyboard

- Tab: Reaches the start controls, then the field, then the end controls, in both forms. The frame itself is not a stop.
- Tab in the strip: Reaches each tile's remove control, and a tile that opens is a press before it. A remove control is drawn while the focus is in its tile.

Enter and Shift+Enter are the field's rule, not the frame's: a composer that sends on Enter says so in its own field.

## Accessibility

The frame is a `div`. Given `aria-label`, it becomes a group named for the composer as a whole; the field inside keeps its own label, since a placeholder is not one.

`ComposerField` is a `Textarea`: its label, its value and its keys are the platform's. The mirror under it is `aria-hidden`, so a reader hears the value once, not a second copy. Mention chips keep the same text spacing. An agent's avatar fits inside the space for the at sign without moving the caret.

`ComposerAttachments` names each picture tile for its file, and every remove control says Remove and the file's name. A file's open press is a button around its content, an upload is a spinner named for its file, and an error is the tile's own words. A picture's error also joins its name and its title.

`busy` sets `aria-busy`. `invalid` draws the danger edge of an invalid field and the status takes the danger ink; the words are the product's, and a status that arrives live, such as an error after a send, is a `role="alert"` node of the product's, as `Field`'s error is.

When the field needs a visible focus ring, the composer draws it around the whole frame. The other controls keep their own rings.

## API reference

### ComposerFrame

- `above` (`ReactNode`): Above the field, the composer's top strip: attachments, a reply, or a chat's work line (`AgentPlan frame="line"`), which stands first. Left out, the region takes no room.
- `start` (`ReactNode`): The controls at the start: attach, modes, a picker. In the compact form they stand before the field.
- `end` (`ReactNode`): The controls at the end: send, stop. In the compact form they stand after the field.
- `status` (`ReactNode`): A quiet line in the foot, above the controls (in the compact form, under the row): a limit or an error.
- `compact` (`boolean`): A short message stands on one row: `start`, the field, `end`. The product sets it while the draft is one line; with `above` present the part draws the two rows whatever this says. It stays while the draft is one line and nothing stands above, leaves as soon as the text wraps or holds a newline, or a reply or an attachment is added, and comes back only when the field is emptied.
- `disabled` (`boolean`): The composer takes no input: the frame marks itself disabled, and the field and the controls inside take their own disabled look.
- `busy` (`boolean`): A send is in flight: said to a reader with `aria-busy`, and nothing in the frame moves.
- `invalid` (`boolean`): The words are wrong: the frame draws an invalid field's danger edge and the status takes the danger ink.
- `aria-label` (`string`): Names the composer for a reader, which makes it a group of that name. The field inside keeps its own label.
- `rootStyle` (`RootStyle`): Typed StyleX override: layout.
- `children` (`ReactNode`): The product's own field, flush in its seat: a `Textarea` in the `ghost` form at `lg`.

Rest props go to `<div>` props.
