Skip to content

Image crop

Pro

Frames a photo before upload: drag, pinch or zoom it behind a fixed frame, and get the crop in the original pixels. Not an M3 component (@windmorph/react-pro).

import { ImageCropDialog, ImageCropper } from '@windmorph/react-pro';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Props

By name or description, across the 29 props below

ImageCropDialog 17 props

  • opentype booleanRequired

    Whether the dialog is open (controlled).

  • srctype stringRequired

    The photo: an object URL of a picked file, or any image URL.

  • aspecttype numberdefault 1

    The frame's width divided by its height.

  • guidetype "circle" | "none"default "none"

    circle draws a dashed circle in the frame, showing what a round avatar shows.

  • maxZoomtype numberdefault 4

    How far the photo can be zoomed past "just covers the frame".

  • pendingtype boolean

    The app is saving after confirm: Save is pending (it keeps focus and announces labels.pending), Cancel and the full-screen Close are disabled, a progress indicator shows, and the dialog can't be dismissed.

  • progresstype number

    Upload progress from 0 to 1 while pending; indeterminate when left out.

  • zoomInIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the zoom-in button's icon.

  • zoomOutIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the zoom-out button's icon.

  • reftype Ref<HTMLDivElement>

    The dialog panel (the element with role="dialog"), as the core Dialog's ref.

  • idtype string

    An id for the dialog panel.

Events

  • onOpenChangetype (open: boolean) => voidRequired

    Called when the dialog asks to open or close; never to close while pending.

  • onConfirmtype (result: ImageCropResult) => voidRequired

    Called with the crop when the person confirms. Keep the dialog open while uploading (pending).

Text

  • labelstype Partial<ImageCropDialogLabels>

    Every word the dialog shows or announces, from the app's translations. English by default. A LabelsProvider sets them for the whole app.

ImageCropper 12 props

  • srctype stringRequired

    The photo: an object URL of a picked file, or any image URL.

  • aspecttype numberdefault 1

    The frame's width divided by its height.

  • guidetype "circle" | "none"default "none"

    circle draws a dashed circle in the frame, showing what a round avatar shows.

  • maxZoomtype numberdefault 4

    How far the photo can be zoomed past "just covers the frame".

  • zoomInIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the zoom-in button's icon.

  • zoomOutIcontype ReactElement<unknown, string | JSXElementConstructor<any>>

    Replaces the zoom-out button's icon.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Events

  • onCropChangetype ((result: ImageCropResult | null) => void)

    Called with the crop whenever it changes, and with null while loading or on error.

Text

  • labelstype Partial<ImageCropperLabels>

    Every word the cropper shows or announces, from the app's translations. English by default. A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.

  • In a dialog (ImageCropDialog)

    Built

    Variant · Avatar

  • Inline (ImageCropper)

    Built

    Variant · Inline

  • Round avatar guide

    Built

    Configuration · Avatar

  • Frame aspect ratio

    Built

    Configuration · Inline

  • Saving with progress (pending, progress)

    Built

    Configuration · Avatar

  • Built on the M3 dialog

    Extension

    Full screen with the M3 full-screen dialog’s header on compact windows, and a basic dialog on larger ones.

M3 Expressive specs

Shape
rounded-corner-medium

Theming

  • The area is surface-container-highest with medium corners; outside the frame the photo is dimmed with scrim at M3's 32%, as a dialog's scrim. In forced colours the dimmed photo around the frame stays visible.
  • The frame is a 2px outline-variant edge, and guide="circle" adds a dashed circle showing what a round avatar shows. Forced colours draw both in the system text colour.
  • classNames styles the cropper's root, area, image, frame, guide, skeleton, error, controls, slider, zoomOut and zoomIn. On ImageCropDialog it also takes the dialog's scrim, panel (its surface) and content, and className goes on the outermost full-window layer, as on the core Dialog.
  • ImageCropDialog's ref, id, aria-* and data-* attributes go on the dialog panel (the element with role="dialog"), as on the core Dialog.
  • zoomInIcon and zoomOutIcon replace the zoom buttons' icons, on both components.
  • The dialog's panel carries the core Dialog's token set (data-tokens="md-comp-dialog wm-image-crop-dialog"), so a --md-comp-dialog-* theme reaches it; the cropper is marked data-tokens="wm-image-cropper".
  • Resetting with 0 eases the photo back on the M3 effects spring, which never uncovers the frame; under reduced motion it jumps there.