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 to | Use |
|---|---|
| Restyle a part | className, variant, children, and theme tokens |
| Add a control next to the built-in parts | A part of your own with useUploadContext() and friends |
| Change a component's markup | The shadcn registry, then edit the copied source |
| Design everything yourself | The @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>| Root | Context hook | Returns |
|---|---|---|
Upload | useUploadContext() | upload, isFull, hideUploaded |
UploadField | useUploadFieldContext() | value, items, remaining, remove |
Download | useDownloadContext() | download |
Delete | useDeleteContext() | delete, confirmation, request, confirm, dismiss |
ObjectList | useObjectListContext() | 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.