Media grid
ProSquare photo tiles, a sideways row on compact windows and a grid from medium up; a press on a tile reports it (`onAction`), for the app to open the viewer. Not an M3 component (@windmorph/react-pro).
import { MediaGrid } 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
MediaGrid 11 props
The photos, in order.
How many tiles show.
Columns from medium windows up.
sizestypestringdefault "auto, (min-width: 600px) calc(100vw / 3), 112px", withcolumnsin place of 3How wide a tile shows, as
sizeson<img>, for the items with asrcSetin widths. Left out, the grid says it from its own layout:auto, the tile's laid-out width, for the browsers that read it on a lazy image, then for the others the row's 112px tile on compact windows and an equal share of the window from medium up (the widest a tile can be). Pass your own when the tile's width or the columns are set in CSS, for the browsers that fall back.The icon of a tile whose photo couldn't be loaded. Such a tile keeps its square, in a container colour (
--wm-media-grid-fallback-color), with this icon in place of the photo; it hasdata-status="error", is still a button named by the photo'saltand still callsonAction. A newsrcorsrcSetis a new try: the placeholder goes at once.The list. Its other props (
id,aria-*,data-*) go to it too.
Events
Called with the pressed tile's index and the tile itself, e.g. to open
MediaViewerthere, growing out of the tile (itsorigin).
Classes on the list; merged with
classNames.root.Classes for each part, merged over the library's.
The list (the row or the grid); merged with
className.Each list item.
Each tile's button.
Each photo.
The placeholder of a tile whose photo couldn't be loaded: its square and its icon.
Inline styles on the list, e.g.
--wm-media-grid-*token values.
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Types
MediaGridItem 4 fields
Identifies the photo across renders, e.g. its id.
The photo's URL.
Responsive sources, as on
<img>. With widths (photo-640.webp 640w) the browser picks the smallest file that fills the tile, from the grid'ssizes.Names the tile for screen readers.
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 |
|---|---|---|
| A row that scrolls sideways on compact windows | Built | Configuration · Viewer, Columns |
Some of the photos (max), opening the viewer out of the pressed tile | Built | Use case · Viewer |
Columns from medium windows up (columns) | Built | Configuration · Columns |
Photos stored at several widths (srcSet, sizes) | Built | Configuration · Sources |
A photo that can’t be loaded (fallbackIcon) | Built | Use case · Failed |
Theming & tokens
Set the tokens below on a grid or any ancestor. Style the parts with classNames (root, item, tile, image, and fallback for the placeholder of a photo that can't be loaded).
| Variable | Default | Paints |
|---|---|---|
--wm-media-grid-gap | 4px | Between tiles. |
--wm-media-grid-columns | 3 | Columns from medium windows up (`columns`). |
--wm-media-grid-corner | var(--md-sys-shape-corner-medium) | The grid’s outer corners, from medium windows up. |
--wm-media-grid-tile-corner | var(--md-sys-shape-corner-small) | Each tile’s corners in the compact row. |
--wm-media-grid-tile-width | 112px | Each tile’s width in the compact row. |
--wm-media-grid-fallback-color | var(--md-sys-color-surface-container-highest) | The square of a tile whose photo couldn’t be loaded. |
--wm-media-grid-fallback-icon-color | var(--md-sys-color-on-surface-variant) | The icon of a tile whose photo couldn’t be loaded. |
--wm-media-grid-fallback-icon-size | 24px | That icon’s size. |