Avatar Upload
Image button that shows the current picture and uploads a new one, round or square.
A profile picture or logo that the user can replace. AvatarUpload shows the
stored image; a click or a drop uploads a new one, with a progress ring over
the preview.
Click or drop an image.
Installation
import { AvatarUpload } from "@dimah-s3/ui";Complete Installation first: the package or registry
setup, the stylesheet, and one <Toaster /> in your layout.
Usage
"use client";
import { useUpload } from "@dimah-s3/react";
import { AvatarUpload, UploadToasts } from "@dimah-s3/ui";
export function ProfilePhoto({
avatarKey,
saveAvatar,
}: {
avatarKey: string | null;
saveAvatar: (key: string) => void;
}) {
const upload = useUpload({ route: "avatar", accept: ["image/*"] });
return (
<>
<AvatarUpload
upload={upload}
route="avatar"
objectKey={avatarKey}
label="Change profile photo"
onUploaded={(result) => saveAvatar(result.key)}
/>
<UploadToasts upload={upload} />
</>
);
}Save result.key in onUploaded, and pass it back as objectKey. route
signs the image URL, so it needs download turned on.
Examples
Sizes and shapes
size sets the width and height in pixels. shape="square" rounds the
corners instead of the whole image, for logos and covers.
64 px
96 px
Square, for logos
Accessibility
labelis required: it is the button's accessible name.- A polite live region announces the upload's progress and errors.
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
upload | UseUploadReturn | required | The useUpload return that uploads the picked image |
route | string | required | Route that signs the image URL for objectKey |
label | string | required | Accessible name of the button, such as "Change profile photo" |
objectKey | string | null | — | Key of the current image. Without one, a placeholder shows |
onUploaded | (result: UploadResult) => void | — | Runs once for each image that uploads |
size | number | 96 | Width and height in pixels |
shape | "circle" | "square" | "circle" | Round image, or rounded corners for logos and covers |
api | S3Api | — | Signs the image URL. Optional inside S3Provider |
className | string | — | Classes for the button |