Gathering detailed insights and metrics for react-medium-image-zoom
Gathering detailed insights and metrics for react-medium-image-zoom
Gathering detailed insights and metrics for react-medium-image-zoom
Gathering detailed insights and metrics for react-medium-image-zoom
@types/react-medium-image-zoom
Stub TypeScript definitions entry for react-medium-image-zoom, which provides its own types definitions
@jay./react-medium-image-zoom
Medium.com style image zoom for React
react-medium-image-zoom-fork
Accessible medium.com-style image zoom for React
react-medium-image-zoom-dragos-version-2
Medium.com style image zoom for React
🔎 🏞 The original medium.com-inspired image zooming library for React (since 2016)
npm install react-medium-image-zoom
Typescript
Module System
Node Version
NPM Version
TypeScript (91.1%)
CSS (4.18%)
JavaScript (3.01%)
Nix (0.67%)
MDX (0.5%)
Shell (0.38%)
Dockerfile (0.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-3-Clause License
2,008 Stars
1,645 Commits
106 Forks
10 Watchers
5 Branches
23 Contributors
Updated on Jul 15, 2025
Latest Version
5.3.0
Package Id
react-medium-image-zoom@5.3.0
Unpacked Size
91.40 kB
Size
18.11 kB
File Count
6
NPM Version
11.4.2
Node Version
24.4.0
Published on
Jul 15, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
28
The original medium.com-inspired image zooming library for React.
View the storybook examples to see various usages.
Features:
<img />
, including all object-fit
values, any object-position
,
and loading="lazy"
<div>
and <span>
with any background-image
,
background-size
,
and background-position
<picture>
with <source />
and <img />
<figure>
with <img />
<svg>
dependencies
Requirements to know about:
<dialog>
element (caniuse dialog)ResizeObserver
(caniuse ResizeObserver)ES2021
. If you need to support older environments,
run this package through your build system.1npm install --save react-medium-image-zoom
1import React from 'react' 2import Zoom from 'react-medium-image-zoom' 3import 'react-medium-image-zoom/dist/styles.css' 4 5export const MyImg = () => ( 6 <Zoom> 7 <img 8 alt="That Wanaka Tree, New Zealand by Laura Smetsers" 9 src="/path/to/thatwanakatree.jpg" 10 width="500" 11 /> 12 </Zoom> 13)
You can pass these options to either the Uncontrolled
(default) or
Controlled
components.
1export interface UncontrolledProps { 2 // Accessible label text for when you want to unzoom. 3 // Default: 'Minimize image' 4 a11yNameButtonUnzoom?: string 5 6 // Accessible label text for when you want to zoom. 7 // Default: 'Expand image' 8 a11yNameButtonZoom?: string 9 10 // Allow swipe gesture to unzoom. 11 // Default: true 12 canSwipeToUnzoom?: boolean 13 14 // Your image (required). 15 children: ReactNode 16 17 // Custom CSS className to add to the zoomed <dialog>. 18 classDialog?: string 19 20 // Provide your own unzoom button icon. 21 // Default: ICompress 22 IconUnzoom?: ElementType 23 24 // Provide your own zoom button icon. 25 // Default: IEnlarge 26 IconZoom?: ElementType 27 28 // Disables the zoom/unzoom behavior. 29 // Default: false 30 isDisabled?: boolean 31 32 // Swipe gesture threshold after which to unzoom. 33 // Default: 10 34 swipeToUnzoomThreshold?: number 35 36 // Specify what type of element should be used for 37 // internal component usage. This is useful if the 38 // image is inside a <p> or <button>, for example. 39 // Default: 'div' 40 wrapElement?: 'div' | 'span' 41 42 // Provide your own custom modal content component. 43 ZoomContent?: (props: { 44 img: ReactElement | null; 45 buttonUnzoom: ReactElement<HTMLButtonElement>; 46 onUnzoom: () => void; 47 }) => ReactElement; 48 49 // Higher quality image attributes to use on zoom. 50 zoomImg?: ImgHTMLAttributes<HTMLImageElement> 51 52 // Offset in pixels the zoomed image should 53 // be from the window's boundaries. 54 // Default: 0 55 zoomMargin?: number 56}
You can pass these options to only the Controlled
component.
1export interface ControlledProps { 2 // ...same as UncontrolledProps 3 4 // Tell the component whether or not it should be zoomed 5 // Default: false 6 isZoomed: boolean 7 8 // Listen for hints from the component about when you 9 // should zoom (`true` value) or unzoom (`false` value) 10 onZoomChange?: (value: boolean) => void 11}
Import the component and the CSS, wrap your image with the component, and the component will handle it's own state.
1import React from 'react' 2import Zoom from 'react-medium-image-zoom' 3import 'react-medium-image-zoom/dist/styles.css' 4 5// <img /> 6export const MyImg = () => ( 7 <Zoom> 8 <img 9 alt="That Wanaka Tree, New Zealand by Laura Smetsers" 10 src="/path/to/thatwanakatree.jpg" 11 width="500" 12 /> 13 </Zoom> 14) 15 16// <div> 17export const MyDiv = () => ( 18 <Zoom> 19 <div 20 aria-label="That Wanaka Tree, New Zealand by Laura Smetsers" 21 role="img" 22 style={{ 23 backgroundColor: '#fff', 24 backgroundImage: `url("/path/to/thatwanakatree.jpg")`, 25 backgroundPosition: '50%', 26 backgroundRepeat: 'no-repeat', 27 backgroundSize: 'cover', 28 height: '0', 29 paddingBottom: '56%', 30 width: '100%', 31 }} 32 /> 33 </Zoom> 34) 35 36// <picture> 37export const MyPicture = () => ( 38 <Zoom> 39 <picture> 40 <source media="(max-width: 800px)" srcSet="/path/to/teAraiPoint.jpg" /> 41 <img 42 alt="A beautiful, serene setting in nature" 43 src="/path/to/thatwanakatree.jpg" 44 width="500" 45 /> 46 </picture> 47 </Zoom> 48) 49 50// <figure> 51export const MyFigure = () => ( 52 <figure> 53 <Zoom> 54 <img 55 alt="That Wanaka Tree, New Zealand by Laura Smetsers" 56 src="/path/to/thatwanakatree.jpg" 57 width="500" 58 /> 59 </Zoom> 60 <figcaption>Photo by Laura Smetsers</figcaption> 61 </figure> 62)
Import the Controlled
component and the CSS, wrap your image with the
component, and then dictate the isZoomed
state to the component.
1import React, { useCallback, useState } from 'react' 2import { Controlled as ControlledZoom } from 'react-medium-image-zoom' 3import 'react-medium-image-zoom/dist/styles.css' 4 5const MyComponent = () => { 6 const [isZoomed, setIsZoomed] = useState(false) 7 8 const handleZoomChange = useCallback(shouldZoom => { 9 setIsZoomed(shouldZoom) 10 }, []) 11 12 return ( 13 <ControlledZoom isZoomed={isZoomed} onZoomChange={handleZoomChange}> 14 <img 15 alt="That wanaka tree, alone in the water near mountains" 16 src="/path/to/thatwanakatree.jpg" 17 width="500" 18 /> 19 </ControlledZoom> 20 ) 21} 22 23export default MyComponent
The onZoomChange
prop accepts a callback that will receive true
or false
based on events that occur (like click or scroll events) to assist you in
determining when to zoom and unzoom the component.
You can import the default styles from react-medium-image-zoom/dist/styles.css
and override the values from your code, or you can copy the styles.css
file and alter it to your liking. The latter is the best
option, given rem
s should be used instead of px
to account for different
default browser font sizes, and it's hard for a library to guess at what these
values should be.
An example of customizing the transition duration, timing function, overlay
background color, and unzoom button styles with :focus-visible
can be found in
this story: https://rpearce.github.io/react-medium-image-zoom/?path=/story/img--custom-modal-styles
If you want to customize the zoomed modal experience with a caption, form, or
other set of components, you can do so by providing a custom component to the
ZoomContent
prop.
View the live example of custom zoom modal content.
Below is some example code that demonstrates how to use this feature.
1export const MyImg = () => ( 2 <Zoom ZoomContent={CustomZoomContent}> 3 <img 4 alt="That Wanaka Tree, New Zealand by Laura Smetsers" 5 src="/path/to/thatwanakatree.jpg" 6 width="500" 7 /> 8 </Zoom> 9) 10 11const CustomZoomContent = ({ 12 /** Default unzoom button */ 13 buttonUnzoom, 14 15 /** Current state of the zoom modal: UNLOADED, LOADING, LOADED, UNLOADING */ 16 modalState, 17 18 /** Your image, prepped for zooming */ 19 img, 20 21 /** A state to check if the zoom img is loaded (useful for loading state) */ 22 // isZoomImgLoaded, 23 24 /** 25 * A callback to manually unzoom the image and close the modal if you want to 26 * use your own buttons or listeners in your custom experience. 27 */ 28 //onUnzoom, 29}) => { 30 const [isLoaded, setIsLoaded] = useState(false) 31 32 useLayoutEffect(() => { 33 if (modalState === 'LOADED') { 34 setIsLoaded(true) 35 } else if (modalState === 'UNLOADING') { 36 setIsLoaded(false) 37 } 38 }, [modalState]) 39 40 const classCaption = isLoaded 41 ? 'zoom-caption zoom-caption--loaded' 42 : 'zoom-caption' 43 44 return <> 45 {buttonUnzoom} 46 47 <figure> 48 {img} 49 <figcaption className={classCaption}> 50 That Wanaka Tree, also known as the Wanaka Willow, is a willow tree 51 located at the southern end of Lake Wānaka in the Otago region of New 52 Zealand. 53 <cite className="zoom-caption-cite"> 54 Wikipedia, <a className="zoom-caption-link" href="https://en.wikipedia.org/wiki/That_Wanaka_Tree"> 55 That Wanaka Tree 56 </a> 57 </cite> 58 </figcaption> 59 </figure> 60 </> 61}
Here are the prop changes from v4
to be aware of:
closeText
was renamed to a11yNameButtonUnzoom
openText
was renamed to a11yNameButtonZoom
overlayBgColorStart
was removed and is now controlled via the CSS selector [data-rmiz-modal-overlay="hidden"]
overlayBgColorEnd
was removed and is now controlled via the CSS selector [data-rmiz-modal-overlay="visible"]
portalEl
was removed, for we are using the <dialog>
element nowtransitionDuration
was removed and is now controlled via the CSS selectors [data-rmiz-modal-overlay]
and [data-rmiz-modal-img]
wrapElement
was removed then added back in v5.1.0
wrapStyle
was removedzoomZindex
was removed, for we are using the <dialog>
element nowAnd you can now provide zoomImg
props to specify a different image to load when zooming.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
No vulnerabilities found.
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
30 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
3 existing vulnerabilities detected
Details
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More