# Reply quote

What a reply answers: one quiet line over its bubble or nested in it, which jumps to it or is saved as text, and the composer's strip while the reply is written.

Live variants: https://design.arcadia.is/components/reply-quote

```tsx
import { ReplyQuote, firstLine } from "@arcadia/ui";
```

```tsx
import { useState } from "react";
import {
  MessageGroup, Bubble, ReplyQuote, MessageParts, ImageAlbum,
} from "@arcadia/ui";

function ReplyQuoteConversation() {
  const [held, setHeld] = useState<string | null>(null);
  const jump = (id: string) => {
    const el = document.getElementById(id);
    el?.scrollIntoView({ block: "nearest" });
    el?.focus({ preventScroll: true });
    setHeld(id);
  };
  return (
    <div {...sx("cmp-reply-quote-stream", ReplyQuoteStyles.stream)}>
      <MessageGroup side="start" author="nora">
        <Bubble side="start" id="rq-asked" tabIndex={-1} flash={held === "rq-asked"} onAnimationEnd={() => setHeld(null)}>{ASKED}</Bubble>
      </MessageGroup>
      <MessageGroup side="start" author="Scout">
        <MessageParts side="start" id="rq-picture" tabIndex={-1} flash={held === "rq-picture"} onAnimationEnd={() => setHeld(null)} label="Picture from Scout">
          <ImageAlbum images={[HARBOUR]} />
        </MessageParts>
      </MessageGroup>
      <MessageGroup side="end">
        <ReplyQuote side="end" author={NORA} text={ASKED} onJump={() => jump("rq-asked")} />
        <Bubble side="end">Yes: the glyph takes the opaque ink, and the ground tells whose it is.</Bubble>
      </MessageGroup>
      <MessageGroup side="end">
        <ReplyQuote side="end" author={MessageActionsSCOUT} text="Photo" onJump={() => jump("rq-picture")} />
        <Bubble side="end">That one is the harbour at noon.</Bubble>
      </MessageGroup>
    </div>
  );
}
```

## In the composer

```tsx
import { useState, useRef } from "react";
import {
  ComposerFrame, IconButton, ComposerField, ReplyQuote, Img,
} from "@arcadia/ui";

function ComposerPicture() {
  const [replying, setReplying] = useState(true);
  const field = useRef<HTMLTextAreaElement>(null);
  const setReply = (next: boolean) => {
    setReplying(next);
    field.current?.focus();
  };
  return (
    <ComposerFrame
      aria-label="Reply to Scout"
      above={replying && (
        <ReplyQuote
          placement="composer"
          author={MessageActionsSCOUT}
          text="The harbour at noon."
          picture={<Img src={HARBOUR.original as string} alt="" placeholder={null} />}
          onCancel={() => setReply(false)}
        />
      )}
      start={<IconButton icon="reply" label="Reply to photo" aria-expanded={replying} onClick={() => setReply(!replying)} />}
    >
      <ComposerField ref={field} aria-label="Reply" placeholder="Write a reply"
        onKeyDown={(event) => {
          if (event.key === "Escape" && replying) {
            event.preventDefault();
            setReply(false);
          }
        }}
      />
    </ComposerFrame>
  );
}
```

## Keyboard

- Tab: A quote that jumps is a stop before its reply, and a saved quote is none. In the composer, Cancel reply is a stop beside the field.
- Enter + Space: Jumps to the message answered, and focus goes there. On Cancel reply, drops the reply.
- Esc: In the composer's quote, and in the field where the product passes it, drops the reply.

## Accessibility

A quote that jumps is a button: a reader hears "In reply to Scout, for maya: The build is green.", the first words heard only; the name pauses as `ActorName`'s does. The message jumped to takes focus, so the next key goes on from there. A saved quote gives the reader the sender and excerpt in reading order.

In the composer the quote is a group named Reply; a reader hears "Replying to Scout, for maya" and the first line. Cancel reply is a button named by `cancelLabel`.

## API reference

### ReplyQuote

- `author` (`Actor | OutsideActor | undefined`): Who wrote what is answered. Every quote has one; only `asked` stands without.
- `asked` (`Actor | OutsideActor | "you" | undefined`): In the quote's seat over a message that puts an `Ask` and answers none: "Asked" and the person asked, one quiet line that every reader sees, `"you"` for the person asked. The ask then leaves out its own `askedOf`, so it is said once. Not with `composer` or `nested`, and with no `author`, words or jump.
- `text` (`string | undefined`): What is answered, as written: its first line shows, fading where it is cut, and a saved quote above its bubble shows all of it. A message of pictures alone passes the words for them ("Photo"). Optional when `preview` is provided.
- `preview` (`ReactNode`): Rendered excerpt shown in place of the raw text. Pass inline phrasing content only, so a quote that jumps stays valid interactive HTML.
- `picture` (`ReactNode`): The quoted image's thumbnail, before the words: a 20px square, clipped, with a hairline inside. Drawn for the eye only, so a reader hears the words passed for it ("Photo").
- `band` (`boolean`)
- `onJump` (`(() => void) | undefined`): Jumps to the message answered: the product scrolls it into view, focuses it and holds it (`flash`). Given, the quote is a button; left out, it is saved: the sender and excerpt as text, and nothing takes focus. Not with `composer`.
- `onCancel` (`(() => void) | undefined`): With `composer`, and only there: drops the reply. The product takes the quote down and gives focus back to its field. Cancel reply runs it, and Escape inside the quote; the product runs it on Escape in its field too.
- `cancelLabel` (`string | undefined`, default `"Cancel reply"`): With `composer`: Cancel reply's name.
- `side` (`BubbleSide | undefined`, default `start`): The reply's side: above its bubble, the quote stands on the bubble's text edge. Not with `composer`.
- `bare` (`boolean | undefined`): Over words with no bubble round them, such as a list of messages: the line takes no inline inset, so its first letter stands on the words' own edge, and a jump's ring stands just outside it. Over a bubble, leave it out: the line stands on the bubble's text edge. Not with `composer` or `nested`.
- `placement` (`ReplyQuotePlacement | undefined`, default `above`): Where the quote stands: `above` is one quiet line over its bubble; `nested` is a two-row inner container inside the bubble with concentric corners; `composer` is the strip over the composer's field while the reply is written, "Replying to" with Cancel reply.
- `rootStyle` (`RootStyle | undefined`): Typed StyleX override: layout.
- `ref` (`Ref<HTMLElement> | undefined`): The quote's root: the button, the saved quote or the composer's group.

Rest props go to `HTMLAttributes<HTMLElement>`.
