Media upload grid
ProThe 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
MediaUploadGrid 27 props
The photos, in order.
itemActionstypereadonly 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.
MIME types, wildcards (
image/*) or extensions to take, asFileTrigger'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 isapplication/vnd.ms-excelwhere a spreadsheet app owns the extension), so list the extensions too:['text/csv', '.csv'].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).A grid that fills the width (2 to 5 columns, so tiles stay at least 88px), or one scrolling row.
Stops adding, dropping, reordering and every button, as while a post is being sent.
Replaces the remove buttons' icon.
Replaces the Retry buttons' icon.
Replaces the action menu buttons' icon.
Replaces the add tile's icon.
The outermost element.
The outermost element's id.
Events
Called with every key in the new order after a photo is dragged (mouse, touch or keyboard). Without it, photos can't be dragged.
Adds a remove button to every photo.
Adds a retry button to failed photos, in the tile's start corner.
Called with the photo's key and the chosen action's id.
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 (acceptedis empty when every file was refused,rejectedwhen none was). Called first, thenonFileAcceptandonFileReject, 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.Called with files chosen from the add tile or dropped on the grid: only those matching
accept, and no more than fit undermaxItems. Without it oronFilePickthere's no add tile or drop. A folder dropped on the grid is passed over (drop the photos in it instead).Called with the files a pick or drop brought that the grid didn't take, in the order they came, after
onFileAccept:typefor one offaccept,roomfor one pastmaxItems(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 matchacceptis refused while it's over the grid, so it's never dropped.
Text
Every word the grid shows or announces, from the app's translations. English by default. A
LabelsProvidersets them for the whole app.The add tile.
A photo's remove button.
The retry button of a failed photo.
labels.uploadingtype(percent: number | undefined) => stringdefault (percent) => (percent === undefined ? "Uploading" :Uploading, ${percent}%)A photo that's uploading;
percentis undefined when progress isn't known.A failed photo, before its reason.
A photo's action menu button.
Shown while files are dragged over the grid.
More ids describing the grid, e.g. a hint about the accepted files.
The id of an element with more details about the grid.
Names the grid for screen readers, e.g. "Photos". Required unless
aria-labelledbyis given.The id of a visible heading that names the grid. Required unless
aria-labelis given.
Classes on the outermost element; merged with
classNames.root.Inline styles on the outermost element, e.g.
--wm-media-upload-grid-*token values.Classes for each part, merged over the library's.
The outermost element; merged with
className.The grid (or the scrolling row).
Every photo tile.
The
<img>of each photo.The progress indicator and error strip of a photo.
The remove buttons.
The Retry buttons of failed photos.
The action menu buttons.
The add tile.
The overlay shown while files are dragged over the grid.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Types
MediaUploadItem 6 fields
One photo in a MediaUploadGrid.
Identifies the photo in
onReorder,onRemove,onRetryandonItemAction.The thumbnail: an object URL of the chosen file, or the uploaded photo's URL.
What the photo shows. It names the tile and its buttons ("Remove …"), so it can't be empty.
uploadingshows the progress,donethe photo alone, anderrorthe photo faded with the reason in a strip (and Retry, withonRetry).Upload progress from 0 to 1, shown while
statusisuploading. Leave it out when it isn't known: a loading indicator shows instead.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.
| Item | Status | Details |
|---|---|---|
| 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) onsurface-container-highestwhile 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-containerand-content), progress on a circle of the same, and errors on anerror-containerstrip. The add tile issecondary-container. - A dragged photo dims, and a
primarybar marks where it lands. Files dragged over the grid show a dashedprimaryoutline 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.
classNamesstyles theroot,grid, eachitem,imageandstatus, theremove,retryandactionsbuttons, theaddtile and thedropoverlay.removeIcon,retryIcon,actionsIconandaddIconreplace the icons.- Set the tokens below on the grid (
className) or any ancestor; the root is markeddata-tokens="wm-media-upload-grid".
| Variable | Default | Paints |
|---|---|---|
--wm-media-upload-grid-corner | var(--md-sys-shape-corner-medium) | Each tile’s corners, and the files drop overlay’s. |
--wm-media-upload-grid-tile-size | 112px | Each tile’s width in the scrolling row. |
--wm-media-upload-grid-control-container | var(--md-sys-color-surface-container-highest) | The corner buttons’ container (Remove and the action menu), over the photo. |
--wm-media-upload-grid-control-content | var(--md-sys-color-on-surface) | The corner buttons’ icon colour. |