File Avatar

PNG, JPG or WebP, up to 5 MB

About this component

File Avatar

An avatar uploader: a round or rounded-square avatar with the current photo or the person's initials, and a camera overlay on hover. Click, drop or paste an image and a crop step opens in place: the picture under a circular mask, dragged to frame it, zoomed with the wheel, a slider or a pinch, and moved with the arrow keys, always covering the whole avatar. Save renders the crop to a square canvas and returns a Blob and a data URL; Cancel puts the old avatar back. A ring around the avatar shows upload progress, a remove button clears it, and accepted types and a size limit reject files with an inline message.

Usage

The import and the props worth knowing about, in one place.

import { FileAvatar } from "@/components/beste/component/file-avatar";

<FileAvatar
  name="Björk"
  defaultValue="/avatars/bjork.jpg"
  onChange={async (result) => {
    if (!result) return console.log("removed");
    const body = new FormData();
    body.append("avatar", result.blob, "avatar.png");
    console.log("upload", result.blob.size, "bytes");
  }}
/>

// A rounded square, a smaller JPEG, and progress you drive yourself
<FileAvatar
  name="Nina Simone"
  shape="rounded"           // "circle" (default) | "rounded"
  outputSize={512}          // px of the saved square
  outputType="image/jpeg"
  quality={0.85}
  maxSize={2 * 1024 * 1024} // 2 MB
  progress={0.4}            // 0 to 1, null hides the ring
  size="lg"                 // "sm" | "default" | "lg"
/>

Keyboard and gestures

Every one of these is in the component already. They are listed because a props table cannot mention a gesture, so nothing else on this page can tell you they exist.

Click, drop or pastePick an image and open the crop step
Drag / pinchMove the picture / zoom it inside the crop
Arrows (Shift for bigger steps)Move the picture in the focused crop area
+ / -Zoom in or out
Enter / EscapeSave the crop / cancel it

Props

Read from the component's own type, so this cannot drift from what it accepts.

PropTypeDefaultDescription
valuestring | null—Image shown in the avatar, controlled. `null` shows the initials.
defaultValuestring | null—Image shown at first, uncontrolled.
onChange(result: FileAvatarResult | null) => void—A saved crop, or `null` when the avatar is removed.
namestring—Whose avatar it is: initials when there is no image, and part of every accessible name.
shape"circle" | "rounded"—Round avatar or a rounded square.
outputSizenumber—Width and height of the saved image, in pixels.
outputType"image/png" | "image/jpeg" | "image/webp"—Format of the saved image.
qualitynumber—Quality for jpeg and webp, 0 to 1.
acceptstring—Accepted files, like the native input's `accept`.
maxSizenumber—Largest file in bytes.
progressnumber | null—Upload progress, 0 to 1, drawn as a ring around the avatar. `null` hides it.
removableboolean—Offer a remove button when there is an image.
hintstring—Line under the buttons, e.g. the accepted formats.
disabledboolean—
tone"muted" | "outline" | "ghost"—
size"sm" | "default" | "lg"—
classNamestring—

More File components

View all File
  • setlist-autumn-tour-2026.pdf242 KB · Uploaded
  • stage-plot-barbican.png3.2 MB · Waiting
  • stems-final-mix.zip393 MB · Connection lost