Skip to Content
dimah-s3v2.8.1

Custom UI

Build your own upload, download, and delete controls on the headless hooks, or add parts to the component families.

When the components do not fit your design, build on the same hooks. Pick the level that matches how much you want to change.

You want toUse
Restyle a partclassName, variant, children, and theme tokens
Add a control next to the built-in partsA part of your own with useUploadContext() and friends
Change a component's markupThe shadcn registry, then edit the copied source
Design everything yourselfThe @dimah-s3/react hooks, without @dimah-s3/ui

A part of your own

Inside a root, a context hook returns the root's hook. Your part sits next to the built-in ones and reads the same state.

"use client";

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

export function UploadCount() {
  const { upload } = useUploadContext();
  const done = upload.files.filter((file) => file.phase === "success").length;

  if (upload.files.length === 0) return null;
  return (
    <p className="text-muted-foreground text-sm">
      {done} of {upload.files.length} uploaded
    </p>
  );
}
<Upload upload={upload}>
  <UploadTrigger />
  <UploadCount />
</Upload>
RootContext hookReturns
UploaduseUploadContext()upload, isFull, hideUploaded
UploadFielduseUploadFieldContext()value, items, remaining, remove
DownloaduseDownloadContext()download
DeleteuseDeleteContext()delete, confirmation, request, confirm, dismiss
ObjectListuseObjectListContext()list, selection, the hooks, view, commands

Use FileAttachment and its building blocks to match the look of the built-in cards.

Your own toasts

To report a hook through another toast library, replace UploadToasts, DownloadToasts, or DeleteToasts with a component that calls useToastOwner. It returns true for one owner per hook, and the ObjectList built-in toasts step aside while it is mounted.

"use client";

import { useEffect } from "react";
import { toast } from "sonner";
import { useFormatError, type UseUploadReturn } from "@dimah-s3/react";
import { useToastOwner } from "@dimah-s3/ui";

export function SonnerUploadToasts({ upload }: { upload: UseUploadReturn }) {
  const active = useToastOwner(upload.instanceId);
  const formatError = useFormatError();

  useEffect(() => {
    if (active && upload.error) toast.error(formatError(upload.error));
  }, [active, upload.error, formatError]);

  return null;
}

Pass { weak: true } for an owner that should step aside for another one.

Fully headless

The hooks hold every state the components show. This picker uses useUpload and shadcn Attachment directly:

The core of it:

"use client";

import { useUpload } from "@dimah-s3/react";
import { Button } from "@/components/ui/button";

export function CustomFilePicker() {
  const upload = useUpload({ route: "avatar" });

  return (
    <div className="flex items-center gap-4">
      <input {...upload.getInputProps()} />
      <Button type="button" onClick={() => upload.open()}>
        {upload.isPending
          ? `Uploading ${upload.progress.percent}%`
          : "Choose file"}
      </Button>
    </div>
  );
}

upload.progress holds the bytes sent across the queue, and each entry of upload.files has its own phase, progress, and error. See useUpload, useDownload, and useDelete for everything the hooks return.

On this page