Components · Messages
MessageAttachment
Files, images and video attached to a message — a file is a card with its name, size and an action; images and video show inline.
import { MessageAttachment } from "@botiverse/raft-ui";What is attached to a message. A file is a card: its name, its size and one or two actions such as Download. Images show inline in a gallery, and a video shows in a player. Attachments sit under the message body, in MessageItemAttachments (MessageItem).
When to use
Anatomy
A file card:
MessageAttachmentGroup: holds the cards, at most 360px wide.MessageAttachmentCard: one file. Required.MessageAttachmentTitle: the file name. It can start with the file's type icon. Required.MessageAttachmentSummary: an optional line about the contents, withMessageAttachmentCommentSummaryfor a comment count orMessageAttachmentDiffSummary,MessageAttachmentDiffAdditionandMessageAttachmentDiffDeletionfor changed lines.MessageAttachmentMeta: the bottom line, withMessageAttachmentMetaStart(size and type) andMessageAttachmentMetaEnd(actions).MessageAttachmentAction: an icon button, such as Download or Preview.
Images: MessageImageGallery, its rows (MessageImageGalleryRow, laid out by buildMessageImageGalleryRows), and in each MessageImageGalleryItem the MessageImageGalleryMedia, a MessageImageGalleryPreview button that opens the image, an optional MessageImageGalleryAction and a MessageImageGalleryOverlay while it is pending.
Video: MessageVideoPreview, with MessageVideoPreviewMedia, MessageVideoPreviewAction, MessageVideoPreviewFallback and the MessageVideoPreviewFailure* parts.
Variants
States
Behavior
- The whole card is clickable: the file name is the link, and it covers the card. The action buttons sit above it and work on their own.
- The card is read, so it hovers with the subtle tier, like a file row or a comment card, and presses with the medium tier; its action buttons hover medium (Hover and press).
- Selecting an image or a file opens it in the file viewer (Built from existing parts).
- An image hovers with
ink-8over the whole picture, the media hover (Hover and press). - The gallery's action button shows on hover and on keyboard focus.
- An action in a card's or a medium's corner (a file card's Download, a video's or an image's action) is a control embedded in its frame: it sits 6px from the corner and wears
radius-chip(Shape).
Content
- Show the file name as it is, on one line, truncated when it doesn't fit.
- Write the size and type in Space Mono: "2.4 MB · PDF".
- In a failure, say why and give the limit: "Larger than 25 MB. Remove it, or compress it and try again." Label the buttons Remove and Retry.
- Say what is happening while a file is busy, such as "Uploading · 64%"; don't write "Processing…" (Writing).
Accessibility
- Don't put a button inside the file name's
<a>: lay the actions over the link instead, so each is its own control. - Give every
MessageAttachmentActionanaria-labelwith the action and the file name: "Download release-notes.pdf". - Give the upload progress
role="progressbar", labeled with the file it uploads. - Set
aria-busyon a card while it uploads or opens. - Give every image an
altthat says what it shows. GiveMessageImageGalleryPreviewanaria-label, such as "Open onboarding-step-2.png".
Rules
- Keep a file card at most 360px wide.
- Show images at most 360px wide, with
radius-containerand aline-hairlineborder, and never wider than the column: a gallery and a video aremin(360px, 100%)of the column, not the window less a guess at the chrome. A gallery's rows are 8rem tall (7rem with three images) below its full 360px and 9rem (8rem) at it, by the gallery's own width, so a thread beside a conversation lays out as a phone does (Switch on the region's width). A row of three images sits three across at every width, never two over one: two over one laid six images out 2, 1, 2, 1, which reads as an F rather than a set. Put it in a parent with a definite width (a block, a stretched flex or grid item, or a set width), not one that shrinks to its content (inline-block,w-fit, an absolutely positioned box or floating layer with no width, a flex item withflex-basis: autoand no width): as its own container it takes no width from what it holds and would collapse to nothing.
API
MessageAttachmentAction, MessageAttachmentCard, MessageAttachmentCommentSummary, MessageAttachmentDiffAddition, MessageAttachmentDiffDeletion, MessageAttachmentDiffSummary, MessageAttachmentGroup, MessageAttachmentMeta, MessageAttachmentMetaEnd, MessageAttachmentMetaStart, MessageAttachmentSummary, MessageAttachmentTitle, MessageImageGallery, MessageImageGalleryAction
Also takes the attributes of its element.
MessageImageGalleryItem
Also takes the attributes of its element.
MessageImageGalleryMedia, MessageImageGalleryOverlay, MessageImageGalleryPreview
Also takes the attributes of its element.
MessageImageGalleryRow
Also takes the attributes of its element.
MessageVideoPreview, MessageVideoPreviewAction, MessageVideoPreviewFallback, MessageVideoPreviewFailureAction, MessageVideoPreviewFailureContent, MessageVideoPreviewFailureIcon, MessageVideoPreviewFailureTitle, MessageVideoPreviewMedia
Also takes the attributes of its element.
Related
Changes
- 0.80.0 · FixedA gallery row of three images sits three across:
MessageImageGalleryRowwith three images (count: 3) lays them out three across at every width, on the shorter rows already sized for three, where it used to put two over one.