Skip to content
EspañolEnglish
All components (204)

Conversation

Data · Conversation · .amset-thread

What it is and when to use it

A thread of messages: a support ticket, a chat with the store, the notes of an order. One's own on one side, other people's on the other and system notices in the middle; each message with its author, its time and, if needed, its status.

When to use it

  • To show an exchange between people. Messages come out in the order they arrive in messages: it does not sort them by date.
  • side: custom (whoever is looking at the screen), other (default) or system (assignments, status changes).
  • state on a message for "Sending" or "Could not send"; extra for attachments or quick replies.
  • maxHeight when the thread is long and has to scroll inside its box. empty is what is shown with no messages.

When not to

  • For comments with nested replies: Comments.
  • For a record of what has happened, without dialog: History.

Keyboard: the thread is one Tab stop, so that it can be scrolled with the arrow keys when it does not fit in its maxHeight. After that, Tab continues through whatever is inside the messages (the extra buttons).

Accessibility: it is an ordered list (ol) with a name (label), so you hear how many messages there are. Each message says who writes it with one word (the author, "You" for one's own without an author —customName changes it— or "System"): the side and the color are not heard. The avatar (with the message's photo, or the initials) is decorative, because the name is already written next to it. The time is relative ("5 minutes ago") and carries the exact date in its datetime.

Fine-tuning: CSS variables --amset-thread-*: -author, -bubble, -footer, -gap, -radius, -text, -width. The size moves the gap, the padding of the bubble and how wide a message can get.

What it looks like

  1. Ada

    I'm not receiving the order receipt.
  2. Support

    We're resending it right now.

<Conversation
  label="Conversation with support"
  messages={[
    { key: '1', author: 'Ada', text: 'I'm not receiving the receipt.', date: '10:02' },
    { key: '2', author: 'Support', text: 'We're resending it.', date: '10:05', side: 'custom' },
  ]}
/>

Props

Import it with import { Conversation } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstringWhat the conversation is about: "Ticket 1042", "Chat with support".
messagesrequiredreadonly Message[]—
classNamestringMerged with the library classes; it does not replace them.
customNamestringWhat the person writing the user's own messages is called. By default, "You".
emptyReactNodeWhat shows with no messages: a text, or a node with its illustration and its call to action.
loadingbooleanThe thread is arriving: three skeleton bubbles instead of the messages, and the thread is marked busy.
loadingOlderbooleanEarlier messages are arriving: a row with its text at the top of the thread.
maxHeightstringMaximum height before scrolling inside the thread.
onReachStart() => voidCalled ONCE on reaching the very top, to ask for the earlier messages. It is not repeated until `loadingOlder` goes from `true` to `false` -or the reader moves away and comes back.
revealKeystringBrings the message with this `key` into view every time it changes: the next match of a search. It moves the thread's scroll, not the page's.
size"sm" | "md" | "lg"—
stickToBottombooleanFollows the end: every new message, and every letter of one being typed, takes the thread down ONLY if the reader was already at the bottom. Whoever has moved away to reread is not dragged.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-thread-gapvar(--amset-space-3)
--amset-thread-bubblevar(--amset-space-2) var(--amset-space-3)
--amset-thread-radiusvar(--amset-radius-lg)
--amset-thread-textvar(--amset-text-sm)
--amset-thread-authorvar(--amset-text-xs)
--amset-thread-footervar(--amset-text-xs)
--amset-thread-width85%

How to change it

.amset-thread {
  --amset-thread-gap: ...;
  --amset-thread-bubble: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at ui.amset.tech: