const receiptSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="480" height="640" viewBox="0 0 480 640">
<rect width="480" height="640" fill="white"/>
<text x="240" y="100" font-family="sans-serif" font-size="28" text-anchor="middle">Receipt</text>
<text x="240" y="420" font-family="sans-serif" font-size="24" text-anchor="middle">Total 42.00</text>
</svg>`
render(
<div style={{width: '100%', height: '60vh'}}>
<ImageViewer
imageURL={`data:image/svg+xml;utf8,${encodeURIComponent(receiptSvg)}`}
imageAlt="Receipt with a total of 42.00"
loadingText="Loading receipt…"
/>
</div>,
)When to use
Use an image viewer to preview an image when users need to inspect details, such as a receipt. It lets users zoom, pan and rotate the image without leaving the preview.
Zooming and panning
Users can zoom with the plus and minus buttons, the zoom slider or the mouse wheel. They can drag the image when zoomed in to inspect details outside the visible area.
Give the viewer enough space for both the image and its controls. It fills its container, so the container needs a height.
Rotation
Rotation is enabled by default. The rotate button turns the image clockwise in 90-degree steps. Holding Ctrl or Cmd while clicking the button rotates it in the opposite direction. This helps users read images uploaded in the wrong orientation.
Loading
The viewer shows a loading indicator and the supplied loading text until the image has loaded. Use a short, translated message that describes what is loading, such as “Loading receipt…”.
Accessibility
Provide meaningful alternative text for images that convey information. Describe the image in the context of the task rather than relying on its filename. Purely decorative images should have empty alternative text.
The zoom and rotate controls have accessible labels supplied by the Telescope translations.