AvatarUpload

Drop or choose a photo, then frame it under a crop circle. The stage shows the whole photo, the circle shows what you keep, and three live previews follow every move. Drag, zoom or use the arrow keys. Inputs.

Open playground

About

AvatarUpload is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { AvatarUpload } from "@ashutoshswamy/smoui" and set onSave, onRemove, size among its 5 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { AvatarUpload } from "@ashutoshswamy/smoui";

<AvatarUpload
  maxSizeMB={5}
  onSave={async (image, url) => {
    await fetch("/api/avatar", { method: "POST", body: image });
  }}
/>

Props 5

onSave

Called with the cropped 512px PNG and an object URL. Return a promise to show the saving state.

(image: Blob, url: string) => void | Promise
onRemove

Called when the photo is removed.

() => void
size

Diameter of the crop circle in px. The stage around it is 1.7 times larger.

numberdefault 168
maxSizeMB

Largest file accepted.

numberdefault 5
label

Accessible name for the file field.

stringdefault "Profile photo"