Media viewer
ProA full-screen viewer for a set of photos: swipe between them, zoom, and read each caption and position. Not an M3 component (@windmorph/react-pro).
import { MediaViewer } 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
MediaViewer 21 props
The photos, in order.
The open photo (controlled).
The photo to open on when uncontrolled.
Whether the viewer is open (controlled).
Whether the viewer starts open when uncontrolled.
What the viewer grows out of as it opens and shrinks back into as it closes, the M3 container transform (the core
Dialog'sorigin): usually the thumbnail that was tapped, or a box in window coordinates. Keep it on the open photo's thumbnail as the viewer moves, so it closes into the right one. Reduced motion keeps only the fades. Left out, the viewer slides up and fades in, as a full-screen dialog does.Extra controls at the end of the top bar, before nothing else: usually icon buttons or a menu ("Open post", "Download"). They're shown on black in the dark colour scheme, and their icon buttons are
standardunless they set avariant, as in a top app bar.Replaces the close button's icon.
Replaces the Previous button's icon (mirrored in right-to-left layouts).
Replaces the Next button's icon (mirrored in right-to-left layouts).
Replaces the zoom-in button's icon.
Replaces the zoom-out button's icon.
The panel (the element with
role="dialog"), as the coreDialog'sref.
Events
Called with the new photo's index when the viewer moves to another photo.
Called when the viewer opens or closes.
Text
Every word the viewer shows or announces, from the app's translations. English by default. A
LabelsProvidersets them for the whole app.Names the close button.
Names the Previous button.
Names the Next button.
Names the zoom-in button.
Names the zoom-out button.
labels.positiontype(current: number, total: number) => stringdefault (current, total) =>Photo ${current} of ${total}The position, shown in the toolbar and announced when it changes: "Photo 2 of 7".
Names the button that expands a cut caption when the caption is the photo's alt text (there's no caption), so screen readers don't read the alt text a second time.
Shown in place of a photo that can't be loaded.
Names the viewer's dialog for screen readers, e.g. "Photos from Alex's post". Required unless
aria-labelledbyis given.The id of a visible element that names the viewer's dialog. Required unless
aria-labelis given.
Goes on the outermost element, the full-window layer around the panel (as on the core
Dialog), so a layout class never hides, clips or moves the viewer. Style the panel withclassNames.panel.Classes for each part, merged over the library's.
The full-screen dialog panel that holds everything (the core
Dialog'spanel): transparent over the backdrop.classNamegoes on the full-window layer around it.The black layer behind the photos, which fades as a swipe down closes the viewer.
The top bar with the close button, the position, zoom and
actions.The position text in the top bar ("Photo 2 of 7").
The group at the end of the top bar: the zoom buttons and
actions.The area that holds the photos and takes swipes, pinches and drags.
The Previous button (a tonal icon button).
The Next button (a tonal icon button).
The caption under the photo.
Goes on the outermost element, with
className(as on the coreDialog).
Also accepts the root element's HTML attributes (id, data-*, event handlers).
Types
MediaViewerItem 8 fields
One photo in a MediaViewer.
Identifies the photo across renders, e.g. its id.
The photo's URL.
Responsive sources, as on
<img>; the viewer is as wide as the window.The image's display sizes for
srcSet, as on<img>.Describes the photo; read by screen readers, and shown when there is no caption.
The photo's width (its aspect ratio is what matters), so it's laid out before it loads.
The photo's height, with
width.Shown under the photo, cut to 2 lines until tapped. Line breaks are kept.
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 |
|---|---|---|
| Opened from thumbnails, at the pressed photo | Built | Use case · Gallery |
Growing out of the thumbnail tapped (origin, the M3 container transform) | Built | Configuration · Gallery |
| Captions, cut to two lines until tapped | Built | Configuration · Gallery |
Actions in the top bar (actions) | Built | Configuration · Actions |
Translated words (labels) | Built | Configuration · Actions |
Opened from thumbnails, at the pressed photo
BuiltUse case · Gallery
Growing out of the thumbnail tapped (
Builtorigin, the M3 container transform)Configuration · Gallery
Captions, cut to two lines until tapped
BuiltConfiguration · Gallery
Actions in the top bar (
Builtactions)Configuration · Actions
Translated words (
Builtlabels)Configuration · Actions
Theming
- It is the core's full-screen
Dialog(roledialog), so it takes the dialog's focus handling, Escape and motion: without anoriginit slides up and fades in as a full-screen dialog does; with one it grows out of it. Its panel joins the core dialog's tokens (md-comp-dialog wm-media-viewer). - Photos read best on black, so the viewer fills the window with a black backdrop and shows its controls in the theme's dark colour scheme, in light and dark mode alike. The top bar is the full-screen header's 56px, with the position in
title-large; its icon buttons arestandardand keep density 0, and Previous and Next are tonal so they stay visible over a bright photo. A menu passed inactionsmatches. - With reduced motion it only fades, and photos change and zoom without moving.
- As on the core
Dialog,classNameandstylego on the outermost, full-window layer, so a layout class never hides or clips the viewer;refand other attributes go on the panel.classNamesreaches thepanel, thebackdrop, thetoolbar, itspositionandactions, themediaarea,previous,nextand thecaption. closeIcon,previousIcon,nextIcon,zoomInIconandzoomOutIconreplace the built-in icons (Previous and Next are mirrored in right-to-left layouts). Forced colours keep every control and the focus ring visible.