Skip to content

Media upload grid

Pro

The photos someone is adding: upload progress and errors, remove and retry, drag to reorder (mouse, touch or keyboard), an add tile and file drop. Not an M3 component (@windmorph/react-pro).

import { MediaUploadGrid } 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 27 props below

MediaUploadGrid 27 props

  • itemstype readonly MediaUploadItem[]Required

    The photos, in order.

  • itemActionstype readonly MediaUploadGridAction[] | ((item: MediaUploadItem, index: number) => readonly MediaUploadGridAction[])

    A menu on every photo (e.g. "Add description", "Move earlier"), or a function giving each photo its own entries (an empty list shows no menu). A failed photo with a retry button shows Retry in the menu's corner instead, so the tile's touch targets don't overlap.

  • accepttype readonly string[]

    MIME types, wildcards (image/*) or extensions to take, as FileTrigger's, e.g. ['image/jpeg', 'image/png']. A file's type comes from the system and can differ from the one you expect (a CSV is application/vnd.ms-excel where a spreadsheet app owns the extension), so list the extensions too: ['text/csv', '.csv'].

  • maxItemstype number

    The most photos the grid takes: the add tile goes there, and a drop on a full grid is taken only to report its files as room (onFileReject).

  • layouttype "grid" | "row"default "grid"

    A grid that fills the width (2 to 5 columns, so tiles stay at least 88px), or one scrolling row.

  • disabledtype boolean

    Stops adding, dropping, reordering and every button, as while a post is being sent.

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

    Replaces the remove buttons' icon.

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

    Replaces the Retry buttons' icon.

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

    Replaces the action menu buttons' icon.

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

    Replaces the add tile's icon.

  • reftype Ref<HTMLDivElement>

    The outermost element.

  • idtype string

    The outermost element's id.

Events

  • onReordertype ((keys: string[]) => void)

    Called with every key in the new order after a photo is dragged (mouse, touch or keyboard). Without it, photos can't be dragged.

  • onRemovetype ((key: string) => void)

    Adds a remove button to every photo.

  • onRetrytype ((key: string) => void)

    Adds a retry button to failed photos, in the tile's start corner.

  • onItemActiontype ((key: string, actionId: string) => void)

    Called with the photo's key and the chosen action's id.

  • onFilePicktype ((pick: FilePick) => void)

    Called once for each pick from the add tile or drop on the grid, with every file it brought: the files taken and the files refused with their reasons (type, room), in the order they came (accepted is empty when every file was refused, rejected when none was). Called first, then onFileAccept and onFileReject, all in the same task, so an app can treat a pick as one thing: add what fits and say once what was left out. A pick that brings no files (a closed dialog) calls nothing.

  • onFileAccepttype ((files: File[]) => void)

    Called with files chosen from the add tile or dropped on the grid: only those matching accept, and no more than fit under maxItems. Without it or onFilePick there's no add tile or drop. A folder dropped on the grid is passed over (drop the photos in it instead).

  • onFileRejecttype ((rejections: FileRejection[]) => void)

    Called with the files a pick or drop brought that the grid didn't take, in the order they came, after onFileAccept: type for one off accept, room for one past maxItems (a full grid still takes a drop, to report it). Never with an empty list, so an app can say why a photo didn't appear. A drag whose types can't match accept is refused while it's over the grid, so it's never dropped.

Text

  • labelstype Partial<MediaUploadGridLabels>

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

  • aria-describedbytype string

    More ids describing the grid, e.g. a hint about the accepted files.

  • aria-detailstype string

    The id of an element with more details about the grid.

  • aria-labeltype string

    Names the grid for screen readers, e.g. "Photos". Required unless aria-labelledby is given.

  • aria-labelledbytype string

    The id of a visible heading that names the grid. Required unless aria-label is given.

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

Types

MediaUploadItem 6 fields

One photo in a MediaUploadGrid.

  • keytype stringRequired

    Identifies the photo in onReorder, onRemove, onRetry and onItemAction.

  • previewUrltype stringRequired

    The thumbnail: an object URL of the chosen file, or the uploaded photo's URL.

  • alttype stringRequired

    What the photo shows. It names the tile and its buttons ("Remove …"), so it can't be empty.

  • statustype MediaUploadStatusRequired

    uploading shows the progress, done the photo alone, and error the photo faded with the reason in a strip (and Retry, with onRetry).

  • progresstype number

    Upload progress from 0 to 1, shown while status is uploading. Leave it out when it isn't known: a loading indicator shows instead.

  • errortype string

    Why the upload failed (status: 'error'), e.g. "Too large (max 10 MB)".

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.

  • Grid layout

    Built

    Variant · Composer

  • Row layout

    Built

    Variant · Row

  • Upload progress, error and retry

    Built

    Configuration · Composer

  • Reordering and a menu per photo

    Built

    Configuration · Composer

  • A limit on photos (maxItems)

    Built

    Configuration · Composer, Row

  • Disabled

    Built

    Configuration · Disabled

M3 Expressive specs

Shape
rounded-corner-medium

Theming & tokens

  • Tiles have medium corners (--wm-media-upload-grid-corner) on surface-container-highest while a photo loads; the row's tile size is --wm-media-upload-grid-tile-size.
  • Nothing relies on a photo's colours: the corner buttons sit on surface-container-highest (--wm-media-upload-grid-control-container and -content), progress on a circle of the same, and errors on an error-container strip. The add tile is secondary-container.
  • A dragged photo dims, and a primary bar marks where it lands. Files dragged over the grid show a dashed primary outline and the drop message. Photos show the pressed state and ripple as they're picked up. Tiles slide to their new places on the default spatial spring and new ones grow in on the fast one; with reduced motion nothing moves, but a new photo still fades in. An uploading photo isn't dimmed. Disabled and drag opacities use the system --md-sys-state-disabled-* tokens. Forced colours draw the edges, bars and outline in system colours.
  • The corner buttons stay at density 0 in a dense theme, as the tiles keep their size.
  • classNames styles the root, grid, each item, image and status, the remove, retry and actions buttons, the add tile and the drop overlay. removeIcon, retryIcon, actionsIcon and addIcon replace the icons.
  • Set the tokens below on the grid (className) or any ancestor; the root is marked data-tokens="wm-media-upload-grid".
Media upload grid tokens
VariableDefaultPaints
--wm-media-upload-grid-cornervar(--md-sys-shape-corner-medium)Each tile’s corners, and the files drop overlay’s.
--wm-media-upload-grid-tile-size112pxEach tile’s width in the scrolling row.
--wm-media-upload-grid-control-containervar(--md-sys-color-surface-container-highest)The corner buttons’ container (Remove and the action menu), over the photo.
--wm-media-upload-grid-control-contentvar(--md-sys-color-on-surface)The corner buttons’ icon colour.