Skip to Content
dimah-s3v2.8.1

Object Card

Card for one stored file, with download and delete actions and their progress.

Show a file you already stored, such as an attachment on a record. ObjectCard renders its name, size, and type, with a download action and a delete action. It shows the progress of each.

For a whole folder of files, use Object List.

quarterly-report.pdf8.0 MB
brand-assets.zip24.0 MB
avatar.png175.8 KB

Installation

import { ObjectCard } from "@dimah-s3/ui";

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

Usage

"use client";

import { useDelete, useFetchDownload } from "@dimah-s3/react";
import { DeleteToasts, DownloadToasts, ObjectCard } from "@dimah-s3/ui";

type Attachment = { key: string; size: number; type: string };

export function Attachments({
  files,
  onRemoved,
}: {
  files: Attachment[];
  onRemoved: (key: string) => void;
}) {
  const download = useFetchDownload({ route: "attachments" });
  const remove = useDelete({ route: "attachments" });

  return (
    <>
      {files.map((file) => (
        <ObjectCard
          key={file.key}
          objectKey={file.key}
          fileSize={file.size}
          contentType={file.type}
          download={download}
          delete={remove}
          onDeleted={(result) => {
            if (result.deleted.includes(file.key)) onRemoved(file.key);
          }}
        />
      ))}
      <DownloadToasts download={download} />
      <DeleteToasts delete={remove} />
    </>
  );
}
  • Pass only the hooks for the actions you want. Many cards share one hook.
  • The card stays after a delete. Remove it in onDeleted.
  • Mount DownloadToasts and DeleteToasts once for the hooks.
  • With useFetchDownload, the card shows the download progress and the action cancels.

Examples

Your own actions

actions render before the built-in ones. This Copy link action signs a URL with the same download hook.

price-list.pdfUpdated Oct 30 · 500 KB

API Reference

Also accepts the FileAttachment props it does not set itself, such as description, previewUrl, actions, and trigger.

PropTypeDefaultDescription
objectKeystringrequiredKey of the stored object
fileNamestringLast segment of keyName shown, and the name the browser saves
fileSizenumber | null—Size in bytes, shown on the second line
contentTypestring | null—MIME type. Picks the type glyph without a preview
previewUrlstring | null—Image thumbnail in place of the glyph
downloadAnyDownloadReturn—A useDownload or useFetchDownload return. Adds the download action
deleteUseDeleteReturn—Adds the delete action and its confirm dialog
onDeleted(result: DeleteResult) => void—Runs once a confirmed delete settles
descriptionReactNodeThe sizeReplaces the second line
actionsReactNode—Your own AttachmentActions, before the built-in ones

On this page