Attachment
File cards, status rows, progress rings, and type glyphs for upload, download, and delete feedback.
FileAttachment and StatusAttachment are the cards the upload family
renders, built on shadcn Attachment.
Use them, with the smaller pieces on this page, when you build your own
parts.
Preview
Install
Complete UI Setup first: the stylesheet and one
<Toaster />. Then add this component:
import { FileAttachment, StatusAttachment } from "@dimah-s3/ui";Usage
UploadStatus, UploadFileList, and UploadFieldValue already render
these cards. Reach for them when you render a file yourself:
"use client";
import { UploadFileList, FileAttachment } from "@dimah-s3/ui";
export function CompactFiles() {
return (
<UploadFileList className="flex-row flex-wrap">
{(file) => (
<FileAttachment
className="w-32"
state={
file.phase === "success"
? "done"
: file.phase === "error"
? "error"
: "uploading"
}
fileName={file.fileName}
fileSize={file.fileSize}
contentType={file.contentType}
previewUrl={file.previewUrl}
percent={file.progress.percent}
error={file.error}
/>
)}
</UploadFileList>
);
}Render UploadFileList inside Upload.
UploadFileItem maps every phase and adds cancel for you.
Layout
Set the width with className. The card is a size container: below a 9rem
content width, such as className="w-32", the media stacks above the text.
Wider, it is a row. StatusAttachment is always a row and fills its parent
unless you set a width.
state is idle, uploading, processing, done, or error. The ring
shows percent while the card is idle or uploading; processing shows a
spinner instead.
Actions
onCanceladds aCancel {name}action while the card isidle(queued),uploading, orprocessing.onRetryadds aRetry {name}action while it iserror. It is the same button as cancel, so focus stays on it when the file goes back in flight.onDismissadds aDismiss {name}action once it isdoneorerror.actionstakes your ownAttachmentActions, placed before those.
The title is a FileName: a long name ends its stem in an ellipsis and keeps
the extension visible, and title holds the whole name.
triggertakes anAttachmentTriggerthat makes the whole card one control, such as opening the file. Give it an accessible name.
<FileAttachment
state="done"
fileName={file.name}
fileSize={file.size}
trigger={
<AttachmentTrigger aria-label={`Open ${file.name}`} onClick={open} />
}
actions={
<AttachmentAction aria-label={`Share ${file.name}`} onClick={share}>
<Share2Icon />
</AttachmentAction>
}
/>Wrap several cards in AttachmentGroup for a scrolling row.
Examples
Every state
FileAttachment for one file in each state, and StatusAttachment for a
result that has no single file.
FileAttachment
StatusAttachment
Glyphs and progress
FileTypeGlyph picks a colored glyph from the content type, else the
extension. FolderGlyph is the object list's folder, and CircleProgress
the ring a card shows while its file uploads.
- Folder
- report.pdf
- notes.docx
- budget.xlsx
- slides.pptx
- data.csv
- archive.zip
- photo.jpg
- song.mp3
- clip.mp4
- app.ts
- README.md
- unknown.bin
Building blocks
| Export | Renders |
|---|---|
CircleProgress | A progress ring with role="progressbar", named Progress for {name} |
FileName | A name that fits its width and keeps the extension (report-for-q….pdf) |
FileTypeGlyph | A colored glyph for the file type, from the content type or the extension |
FolderGlyph | The folder glyph the object list uses |
DismissAttachmentAction | The dismiss icon button. label sets its accessible name |
AttachmentGroup | A horizontal, scrolling group of cards, from shadcn Attachment |
AttachmentAction | An icon button in the card's actions, from shadcn Attachment |
AttachmentTrigger | A button over the whole card, from shadcn Attachment |
For chrome that does not fit these, compose shadcn Attachment with the headless hooks; see Custom UI.
Props
import type {
FileAttachmentProps,
StatusAttachmentProps,
CircleProgressProps,
FileNameProps,
FileTypeGlyphProps,
DismissAttachmentActionProps,
} from "@dimah-s3/ui";FileAttachment
Prop
Type
StatusAttachment
Prop
Type
CircleProgress
Prop
Type
FileName
Prop
Type
FileTypeGlyph
Prop
Type
DismissAttachmentAction
Prop
Type