Skip to content

Forms

AvatarDropzone

tsx
"use client";
import { AvatarDropzone, Field } from "@cherry-design-system/react";

export function ProfilePicture({ setAvatar }: { setAvatar: (file: File | null) => void }) {
  return (
    <Field label="Profile picture">
      <AvatarDropzone name="avatar" accept="image/*" onFileChange={setAvatar} />
    </Field>
  );
}

A round profile picture picker. Click it, press Enter or Space, or drop an image on it. The preview scales in, the remove badge pops, and removing fades the picture out before the empty state returns. Use Dropzone for general file uploads.

Examples

Existing picture

defaultSrc shows the current avatar until the user picks a new one or removes it.

tsx
"use client";
import { AvatarDropzone, Field } from "@cherry-design-system/react";

export function EditAvatar({ url }: { url: string }) {
  return (
    <Field label="Profile picture" hint="Square images look best.">
      <AvatarDropzone size="lg" defaultSrc={url} accept="image/png,image/jpeg" />
    </Field>
  );
}

Size limit and rejection

tsx
"use client";
import { useState } from "react";
import { AvatarDropzone, Field } from "@cherry-design-system/react";

export function LimitedAvatar() {
  const [error, setError] = useState<string>();
  return (
    <Field label="Team logo" error={error}>
      <AvatarDropzone
        size="sm"
        accept="image/*"
        maxBytes={1_000_000}
        label="Upload team logo"
        removeLabel="Remove team logo"
        onFileChange={() => setError(undefined)}
        onFileRejected={(r) => setError(r.reason === "size" ? "Use an image under 1 MB." : "Use an image file.")}
      />
    </Field>
  );
}

Properties

size"sm" | "md" | "lg"

64 / 96 / 128 px. Defaults to "md".

defaultSrcstring

Picture shown before anything is picked (an existing avatar URL).

iconReactNode

Icon shown while empty. Defaults to an image-plus glyph.

maxBytesnumber

Maximum file size, in bytes.

invalidboolean

Error state; set automatically inside a <Field error>.

labelstring

Accessible name of the picker. Defaults to "Upload profile picture".

removeLabelstring

Accessible name of the remove button. Defaults to "Remove profile picture".

onFileChange(file: File | null) => void

The picked picture, or null once it is removed.

onFileRejected(rejection: DropzoneRejection) => void

A file refused for its type or size. DropzoneRejection is { file: File; reason: "type" | "size" | "count" }.

The ref and native <input> attributes (except type, value, children, multiple, size and defaultValue) go to the file <input>.

Styling

Root class cherry-avatar-dropzone with data-size (sm, md, lg) and states data-filled, data-drag-over, data-disabled, data-invalid. Parts: cherry-avatar-dropzone__target, __input, __icon, __image, __remove.

Reads --cherry-bg-subtle, --cherry-border-strong, --cherry-border-focus, --cherry-elevation-sm (remove badge), --cherry-ring and --cherry-ring-danger.

Accessibility

A labelled native file input (label); the remove button is labelled (removeLabel). Translate both for other languages.