Avatar
A single image in a fixed shape, for profile photos and logos.
Profile photo
PNG, JPG, WEBP or GIF, at least 128×128px, up to 2 MB
Click or drop onto the image to replace it. With minDimension, the image's pixel size is checked in the browser before it is uploaded.
Installation
Use the shadcn CLI to add the component to your project.
npx shadcn@latest add https://edgestore.dev/r/avatar-dropzone.jsonUsage
Install or copy the component from Installation before using this example.
'use client';
import { AvatarDropzone } from '@/components/upload/avatar-dropzone';
import {
UploaderProvider,
type UploadFn,
} from '@/components/upload/uploader-provider';
import { useEdgeStore } from '@/lib/edgestore';
import * as React from 'react';
export function AvatarDropzoneUsage() {
const { edgestore } = useEdgeStore();
const uploadFn: UploadFn = React.useCallback(
async ({ file, onProgressChange, signal }) => {
const res = await edgestore.publicImages.upload({
file,
signal,
onProgressChange,
});
// you can run some server action or api here
// to add the necessary data to your database
console.log(res);
return res;
},
[edgestore],
);
return (
<UploaderProvider uploadFn={uploadFn} autoUpload>
<AvatarDropzone
label="Profile photo"
maxSize={1024 * 1024 * 2} // 2 MB
minDimension={128}
/>
</UploaderProvider>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | "Profile photo" | Label shown next to the image and used in accessible labels. |
description | ReactNode | Help text under the label. Defaults to a summary of the limits. | |
shape | "circle" | "square" | "circle" | Shape of the image. |
size | number | 88 | Size of the image in pixels. |
minDimension | number | Minimum width and height of the image in pixels. | |
placeholder | ReactNode | user icon | Shown when there is no image. |
maxSize | number | Maximum file size in bytes. | |
accept | Accept | PNG, JPG, WEBP, GIF | Accepted file types, in react-dropzone's format. |
typesLabel | string | "PNG, JPG, WEBP or GIF" | Human-readable list of accepted types, shown in the hint and in error messages. |
disabled | boolean | false | Disables the component. |