Attachment
A file as a compact chip: its name, kind and size, upload progress, and Remove or open.
When to use it: For files on a prompt and in a sent message. A form that collects documents uses FileUpload.
Example
Guidelines
- Give every button, link and icon button a name, every image alt text (alt="" for decoration), and every SVG aria-hidden or role="img" with a name.
a11y.accessible-name - Give every status and meaning a word, an icon or a pattern as well as colour.
colour.not-alone
Add it to your project
It’s included in turtlekit.css and the turtlekit package: install it.
Your AI will also copy only this component, and what it needs, into your project. That comes with Turtlekit Pro, opening soon. Hear when it opens.
In detail
A file as a compact chip, in a prompt or a sent message: a thumbnail for an image (preview), else the file's icon; the name on one line and its kind and size ("PDF · 2.4 MB", the kit's number format); while uploading, "Uploading 40%" and a bar along its foot; on failure the error in words, the chip's edge in the danger tone. onRemove shows Remove named for the file; href (a link) or onOpen (a button) opens it, named by the file's name and described by its kind and size. AttachmentList is the row of them PromptBox and Message use: items (FileUpload's file shape plus type, kind, preview and href), label, onRemove(id) or onOpen(id); it says once each that a file was removed, uploaded or failed, and after a remove moves focus to the next Remove. Every string is a prop.
Styles: css/attachment.css.
How it’s built
The engineering patterns inside Attachment, each explained in Turtlekit Editorial.
Lifting state up
The app owns the files and their upload state; the list reports removes and opens and renders what it is given.
Partial rendering
A thumbnail only with a preview, Remove only with onRemove, a link or a button only when the file opens, the bar only while uploading.
Deriving state
The kind comes from the name's extension or the type, and the words from the status, during render.
