EdgeStore

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.json

Usage

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

PropTypeDefaultDescription
labelstring"Profile photo"Label shown next to the image and used in accessible labels.
descriptionReactNodeHelp text under the label. Defaults to a summary of the limits.
shape"circle" | "square""circle"Shape of the image.
sizenumber88Size of the image in pixels.
minDimensionnumberMinimum width and height of the image in pixels.
placeholderReactNodeuser iconShown when there is no image.
maxSizenumberMaximum file size in bytes.
acceptAcceptPNG, JPG, WEBP, GIFAccepted file types, in react-dropzone's format.
typesLabelstring"PNG, JPG, WEBP or GIF"Human-readable list of accepted types, shown in the hint and in error messages.
disabledbooleanfalseDisables the component.

On this page