The original medium.com-inspired image zooming library for React.
View the storybook examples to see various usages.
Features:
<img />, including allobject-fitvalues, anyobject-position, andloading="lazy"<div>and<span>with anybackground-image,background-size, andbackground-position<picture>with<source />and<img /><figure>with<img /><svg>- Custom zoom modal content (👇)
- Accessibility:
- JAWS in Chrome, Edge, and Firefox (Windows)
- NVDA in Chrome, Edge, and Firefox (Windows)
- VoiceOver in Safari (macOS, iOS)
- TalkBack in Chrome (Android)
- Supports popular tools:
- Zero
dependencies
Requirements to know about:
<dialog>element (caniuse dialog)ResizeObserver(caniuse ResizeObserver)- Package build target is
ES2021. If you need to support older environments, run this package through your build system.
Media and Tutorials
- 2024-08-2024 — React Round Up — "Building a Seamless Image Zoom Feature"
- Build a React.js Image Zoom Feature with react-medium-image-zoom Library and State Management
Quickstart
npm install --save react-medium-image-zoom
import React from 'react' import Zoom from 'react-medium-image-zoom' import 'react-medium-image-zoom/dist/styles.css' export const MyImg = () => ( <Zoom> <img alt="That Wanaka Tree, New Zealand by Laura Smetsers" src="/path/to/thatwanakatree.jpg" width="500" /> </Zoom> )
API
You can pass these options to either the Uncontrolled (default) or
Controlled components.
"export interface UncontrolledProps {
// Accessible label text for when you want to unzoom.
// Default: 'Minimize image'
a11yNameButtonUnzoom?: string
// Accessible label text for when you want to zoom.
// Default: 'Expand image'
a11yNameButtonZoom?: string
// Allow swipe gesture to unzoom.
// Default: true
canSwipeToUnzoom?: boolean
// Your image (required).
children: ReactNode
// Custom CSS className to add to the zoomed .
classDialog?: string
// Provide your own unzoom button icon.
// Default: ICompress
IconUnzoom?: ElementType
// Provide your own zoom button icon.
// Default: IEnlarge
IconZoom?: ElementType
// Disables the zoom/unzoom behavior.
// Default: false
isDisabled?: boolean
// First argument: boolean value of a new zoomed state (Uncontrolled
// component) or a suggested new state (Controlled component).
// Second argument: object containing the event that triggered the change.
// Default: undefined
onZoomChange?: (
value: boolean,
data: { event: React.SyntheticEvent | Event },
) => void
// Swipe gesture threshold after which to unzoom.
// Default: 10
swipeToUnzoomThreshold?: number
// Specify what type of element should be used for
// internal component usage. This is useful if the
// image is inside a
or