Attachment
Attachment shows one file and the state of its upload, before or after you send it.
<Attachment state="uploading" progress={0.62} icon={fileIcon} meta="2.4 MB" onRemove={remove}> quarterly-report.pdf</Attachment>An attachment shows one file as a small tile with the file name, an optional second line such as the size, an icon and an optional remove button. It also shows what is happening to the file: ready, uploading, being processed on the server, or failed.
Use it wherever a file appears: in a Composer before you send a message, in the message after you send it, or under a form field. A file that is about to be sent and a file that is already sent use the same tile, which is why the tile is a separate component from the Composer.
Your app keeps the file, and the tile only shows what you tell it. It never reads a File, starts a timer or creates a URL. Set state, progress and meta from the data that your upload code already has.
Set state="uploading" with a progress from 0 to 1 to fill a ring around the icon. Without progress, and in the processing state, a short segment moves around the ring instead. For the error state, the tile turns red, and you should write the reason in meta, because colour alone does not tell people what went wrong. Without an icon, the tile shows a generic file icon.
The remove button appears only when you pass onRemove, and your app then removes the file from its own list. The button's accessible name is "Remove" followed by the file name, and you can set removeLabel to translate the first word.
size sets the padding, the corner, the icon, the remove button and the text size of the name. Set backdrop when content passes behind the tile, so the tile uses your Theme's material. A screen reader hears the file name as the tile's name, the second line as its description, and a busy state while the file uploads or is processed.
Props
Generated from the types. It lists what this component DECLARES: a prop that arrives from a shared type or from the platform is real and is not repeated here.
| Prop | Type | What it does |
|---|---|---|
backdrop? | boolean | Set backdrop when the tile sits over other content, such as an image. |
children | string | The file name. |
className? | string | Your classes, appended to the ones this component resolves rather than replacing them. |
icon? | React.ReactNode | An icon or a thumbnail for the file. |
meta? | React.ReactNode | A second line of text, such as the file size, the file type or an error message. |
onRemove? | () => void | Called when the user presses the remove button. |
progress? | number | The upload progress, from 0 to 1. |
removeLabel? | string | The accessible name of the remove button. |
size? | "1" | "2" | "3" | "4" | The size step of the tile, from 1 to 4. |
state? | "idle" | "uploading" | "processing" | "error" | What is happening to the file: idle, uploading, processing or error. |
style? | React.CSSProperties | Inline styles, merged last, so your value wins over anything the component resolved. |
- A done state — A file that is sent looks the same as a file that is ready to send. To show the difference, change what is in the tile, such as a remove button before sending and a download link after.
tone— The tile'sstatealready sets its colour, and theerrorstate shows it in red. A separatetonewould let a failed upload show as a success.- Holding the file — The tile never reads a file, uploads it or creates a URL for it, because your app already manages the file. Give the tile a name, a state and an icon.
- A built-in preview — The tile does not load or decode images. To show a thumbnail, create it in your app and pass it as an
imgin theiconslot. emphasis— Every tile has the same strength, because no file is more important than another. Only anerrorstate makes a tile stand out.- A shadow — A tile is content inside another surface, such as a composer or a message, so it draws no shadow. Its border marks its edge instead.
render— The tile is made of several elements, including the name and the remove button, so there is no single element thatrendercould replace.