Attachment
A compact card that shows users an attached file and the state of its upload.
An attachment presents a file with an icon or a thumbnail, a title and a description, and it can carry actions such as removing the file. Its state follows the upload, so users see whether a file is waiting, in progress, failed or complete.
Usage
Examples
Horizontal
Invoices and price lists are usually recognized by their name. With orientation set to "horizontal", which is also the default, the media sits beside the name and the details of the file, so users identify the file at a glance by its name.
Vertical
Photos and scans say more through their content than through their name. Set to "vertical", orientation places the media above the name and gives it the full width of the attachment, so users recognize a picture before they read anything.
Extra Small
Space is scarce where files travel along with a message, for example in the input of a conversation. At size "xs", an attachment claims the least room, so the text that users write stays in the foreground.
Small
Side panels and comment threads show files beside content that matters more. An attachment with size set to "sm" keeps the file recognizable in less space, so it does not outweigh that content.
Default Size
In forms and upload areas, users check each file before they submit it. Unless a size is set, an attachment takes the size "default", so files keep one scale across every product.
Icon Media
Spreadsheets and text documents rarely offer a picture that tells them apart. For such files, the media holds an icon with variant set to "icon", its default, and users identify the file by its name and details.
Image Media
Pictures from the shop floor carry information that no file name can, such as the condition of a delivery. With variant set to "image", the picture fills the media and stays muted while the file is still uploading or being processed or after it has failed, so users tell a ready photo from one that is not.
With Trigger
Users often check a file before they send it or work with it. Placed inside the attachment, AttachmentTrigger turns its whole surface into one target for the pointer and the keyboard, for example to open a preview. The actions keep responding on their own, so removing a file never opens it by mistake.
Trigger as Link
Some files already have an address of their own, such as a document in the archive. Through render, the trigger becomes a real link to that address, so users can open the file in a new tab or pass the link on.
Group
A message or a form often carries several files at once. Inside AttachmentGroup they share one row that users scroll sideways once it runs out of width, and scrolling comes to rest at the start of a file rather than in the middle of one.
Uploading
While a file is on its way, users should not mistake it for a complete one. With state set to "uploading", the attachment signals ongoing work, and users see at once which files are still in transfer.
Processing
Once a file has arrived, the system often has to read or check it before users can work with it. Set to "processing", state keeps the activity visible through that step, so the file stays marked as not ready although its transfer has finished.
Error
An upload can fail, for example when the connection drops. Marked with state set to "error", the attachment shows the failure on the file itself, so users find it among the others and decide what to do with it.
Done
Finished files are ready for whatever users do next, such as sending them with a message. Nothing about the attachment signals work in progress once state is set to "done". This value is also the default, so an attachment without a state of its own counts as finished.
Disabled Action
Removing a file is sometimes not possible, for example while the form that carries it is being submitted. An action marked as disabled accepts no interaction and exposes its state to assistive technology, while the pointer shows users that the action is unavailable for now.
API Reference
Attachment
| Prop | state |
|---|---|
| Type | "idle" | "uploading" | "processing" | "error" | "done" |
| Default | "done" |
| Description | Sets the stage of the upload. Idle draws a dashed border, uploading and processing animate the title, and error colors the border, the media and the description as destructive. |
| Prop | size |
|---|---|
| Type | "default" | "sm" | "xs" |
| Default | "default" |
| Description | Controls the padding, gap and text size of the attachment and the width of its media. |
| Prop | orientation |
|---|---|
| Type | "horizontal" | "vertical" |
| Default | "horizontal" |
| Description | Controls the layout. Horizontal places the media beside the content, vertical stacks the media above the content and moves the actions to the top right corner. |
AttachmentMedia
| Prop | variant |
|---|---|
| Type | "icon" | "image" |
| Default | "icon" |
| Description | Sets the kind of media. Icon centers an icon on a muted background. Image fits a child img to the square and dims it while the state is uploading, processing or error. |
AttachmentContent
AttachmentContent has no props of its own. It accepts the props of a native div.
AttachmentTitle
AttachmentTitle has no props of its own. It accepts the props of a native span.
AttachmentDescription
AttachmentDescription has no props of its own. It accepts the props of a native span.
AttachmentActions
AttachmentActions has no props of its own. It accepts the props of a native div.
AttachmentAction
| Prop | variant |
|---|---|
| Type | "default" | "outline" | "secondary" | "ghost" | "destructive" | "link" |
| Default | "ghost" |
| Description | Controls the visual emphasis and semantic role of the action. |
| Prop | size |
|---|---|
| Type | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" |
| Default | "icon-xs" |
| Description | Controls the action dimensions and spacing. |
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native element or composes the action with another component. |
| Prop | nativeButton |
|---|---|
| Type | boolean |
| Default | true |
| Description | Declares whether the rendered element is a native button. Set it to false when render returns a different element. |
| Prop | disabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Prevents interaction and exposes the disabled state to assistive technology. |
| Prop | focusableWhenDisabled |
|---|---|
| Type | boolean |
| Default | false |
| Description | Keeps the action in the tab order while it is disabled, so keyboard users can still reach it. |
AttachmentTrigger
| Prop | render |
|---|---|
| Type | ReactElement | render function |
| Default | – |
| Description | Replaces the native button or composes the trigger with another component, such as a link. |
| Prop | type |
|---|---|
| Type | "submit" | "reset" | "button" |
| Default | "button" |
| Description | Sets the type of the native button. With render, the trigger passes type on only when it is set. |
AttachmentGroup
AttachmentGroup has no props of its own. It accepts the props of a native div.