Skip to Content
dimah-s3v2.8.1

Attachment

File cards, status rows, progress rings, and file type glyphs for building your own upload, download, and delete UI.

The building blocks the other components render. FileAttachment is the card of one file; StatusAttachment is a row for a result with no single file. Both build on shadcn Attachment. Use them when you render files yourself.

Layout
State
quarterly-report.pdf2.3 MB
avatar.png175.8 KB
budget.xlsx82.0 KB

Installation

import { FileAttachment, StatusAttachment } from "@dimah-s3/ui";

Complete Installation first: the package or registry setup, the stylesheet, and one <Toaster /> in your layout.

Usage

UploadStatus, UploadFileList, UploadFieldValue, and ObjectCard already render these cards. Reach for them when you render a file yourself, such as in a compact upload list:

"use client";

import { FileAttachment, UploadFileList } 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>
  );
}

UploadFileList goes inside Upload. UploadFileItem maps every phase and adds cancel for you.

Examples

Every state

FileAttachment in each state, and StatusAttachment for a result that has no single file.

FileAttachment

waiting-in-queue.pdf1.1 MB
holiday-video.mp448 MB · 9s left
dataset.csvFinishing…
avatar.png175.8 KB
too-large-archive.zipThe file is larger than the 75 MB limit.

StatusAttachment

Preparing 4 files…
All 4 files uploaded12.6 MB
Upload failed2 of 4 files could not be uploaded.

Glyphs and progress

FileTypeGlyph picks a colored glyph from the content type, else the extension. FolderGlyph is the folder of the object list, 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
0%
25%
50%
75%
100%

States

stateShowsActions available
idleQueued, with the ring at percentonCancel
uploadingThe ring at percentonCancel
processingA spinneronCancel
doneThe size, or descriptiononDismiss
errorThe error textonRetry, onDismiss

Each callback adds its action only in the states above. Retry takes the place of cancel, so focus stays on the same button when a file goes back in flight.

Layout

Set the width with className. The card is a size container: below a 9rem content width, such as w-32, the media stacks above the text; wider, it is a row. StatusAttachment is always a row and fills its parent.

Wrap several cards in AttachmentGroup for a horizontal, scrolling row.

Actions and triggers

actions takes your own AttachmentActions, placed before the built-in ones. trigger takes an AttachmentTrigger that makes the whole card one control, such as opening the file.

<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>
  }
/>

Give the trigger and each icon action an accessible name.

Building blocks

ExportRenders
CircleProgressA progress ring with role="progressbar", named Progress for {name}
FileNameA name that shortens to fit and keeps the extension: report-for-q….pdf
FileTypeGlyphA colored glyph for the file type, from the content type or the extension
FolderGlyphThe folder glyph of the object list
DismissAttachmentActionThe dismiss icon button
AttachmentGroupA horizontal, scrolling group of cards
AttachmentActionAn icon button in the card's actions
AttachmentTriggerA button over the whole card, or the element its render prop returns

The last three render shadcn Attachment parts. From npm their props are AttachmentGroupProps, AttachmentActionProps, and AttachmentTriggerProps; with the registry, import them from @/components/ui/attachment.

For chrome these do not cover, compose shadcn Attachment with the hooks. See Custom UI.

API Reference

FileAttachment

Also accepts every div prop except children.

PropTypeDefaultDescription
stateAttachmentStaterequiredidle, uploading, processing, done, or error
fileNamestringrequiredThe title
fileSizenumber | null—Size in bytes
contentTypestring | null—MIME type. Picks the glyph without a preview
previewUrlstring | null—Image thumbnail in place of the glyph
percentnumber0Ring progress from 0 to 100
descriptionReactNodeSize or errorReplaces the second line
errorstring | APIError | null—Error shown in the error state
onCancel() => void—Adds cancel while queued or in flight
onRetry() => void—Adds retry in the error state
retryDisabledbooleanfalseKeeps retry focusable but aria-disabled
onDismiss() => void—Adds dismiss once done or error
actionsReactNode—Your own controls, before cancel and dismiss
triggerReactNode—An AttachmentTrigger over the whole card

StatusAttachment

Also accepts every div prop except children and title.

PropTypeDefaultDescription
stateAttachmentStaterequiredPicks the state icon
titleReactNode—The title
descriptionReactNode—The second line
mediaReactNodeState iconReplaces the icon
actionsReactNode—Your own controls, before dismiss
onDismiss() => void—Adds a dismiss action

CircleProgress

PropTypeDefaultDescription
percentnumberrequiredProgress from 0 to 100
fileNamestring—Names the ring Progress for {fileName}
labelstring—Accessible name. Required without fileName
strokeWidthnumber2.5Ring thickness in a 20 by 20 box
classNamestring"size-5"Sets the size

FileName

Also accepts every span prop except children.

PropTypeDefaultDescription
namestringrequiredThe file name
extensionbooleantrueKeeps a short extension visible. Off for folders
highlightstring—Search text to mark in the name

FileTypeGlyph

PropTypeDefaultDescription
fileNamestringrequiredPicks the glyph by extension
contentTypestring | null—MIME type. Wins over the extension when known
layout"fill" | "icon""fill"Fills a media box, or a fixed icon for lists
classNamestring—Classes for the glyph

DismissAttachmentAction

PropTypeDefaultDescription
onDismiss() => voidrequiredRuns on click
labelstring"Dismiss"Accessible name
classNamestring—Classes

On this page