# Comment thread

One comment's frame: its state, its selection's lines and its acts at the head, the product's messages and composer under them.

Live variants: https://design.arcadia.is/components/comment-thread

```tsx
import { CommentThread } from "@arcadia/ui";
```

Mark done, then write a reply: a done comment sends with Reopen and send.

```tsx
import { useState } from "react";
import { Button, CommentState, CommentThread } from "@arcadia/ui";

function Thread() {
  const [words, setWords] = useState<readonly { readonly text: string; readonly animate: boolean }[]>([]);
  const [done, setDone] = useState(false);
  return (
    <div {...stylex.props(CommentThreadStyles.thread)}>
      <CommentThread
        rootStyle={CommentThreadStyles.card}
        state={done
          ? <CommentState state="done" opener={CommentThreadMAYA} holder={CommentThreadSCOUT} done={{ by: CommentThreadMAYA, at: CommentThreadAT }} />
          : <CommentState state="agent" opener={CommentThreadMAYA} holder={CommentThreadSCOUT} working />}
        selection={COMMENT_SELECTION}
        actions={done
          ? <Button size="sm" variant="secondary" onClick={() => setDone(false)}>Reopen</Button>
          : <Button size="sm" variant="secondary" onClick={() => setDone(true)}>Mark done</Button>}
        composer={<Composer send={done ? "Reopen and send" : "Send"} onSend={(text, animate) => { setWords((old) => [...old, { text, animate }]); setDone(false); }} />}
      >
        <Messages words={words} />
      </CommentThread>
    </div>
  );
}
```

## Keyboard

- Tab: Reaches Close, the selection, the acts, then the product's messages and composer
- Enter + Space: On the selection, folds its lines

## Accessibility

The thread is a region named Comment. The selection is a button that says whether it is expanded, and its lines are inert while folded. The close button is named Close. What the product puts in the frame keeps its own names and its own announcements.

## API reference

### CommentThread

- `state` (`ReactNode`, required): Whose turn it is, in the kit's CommentState.
- `selection` (`{ lines: readonly string[]; elements: number; found?: number }`): Its selection's lines, which fold. Left out for a comment on a frame, a mark or a point.
- `actions` (`ReactNode`): The comment's acts, as buttons: Give to, Take, Mark done, Reopen.
- `composer` (`ReactNode`): The product's composer, at the foot.
- `onClose` (`() => void`): Shows the close button.
- `title` (`string`, default `"Comment"`): Its name for assistive technology.
- `rootStyle` (`RootStyle`): Typed StyleX override: where the thread sits (layout only).
- `children` (`ReactNode`): The product's messages: its chat for the comment's thread, which scrolls itself in the room the frame leaves it.

Rest props go to `<section>` props.
