react-medium-image-zoom

Accessible medium.com-style image zoom for React, built on the native dialog element with zero dependencies

Library
npm
v5.4.9
2,119 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
80 /100 Excellent
Development Activity 84
Maintenance 88
Community 48
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 78
Code Quality 90
Innovation 62
Learning Curve 70

react-medium-image-zoom is a lightweight React component that recreates the click-to-enlarge image zoom popularized by Medium.com, letting any image, background-image div, picture, figure, or SVG expand into a full-screen, dismissible view. It ships as both an Uncontrolled component that manages its own open/closed state and a Controlled component for apps that need to drive the zoom state externally, such as syncing with a gallery’s active-slide index.

Rather than reimplementing modal and focus-management logic, the library builds on the native dialog element and ResizeObserver, giving it built-in accessibility (focus trapping, Escape-to-close) and screen-reader support that’s been tested against JAWS, NVDA, VoiceOver, and TalkBack. It has zero runtime dependencies beyond React itself, supports swipe-to-unzoom gestures, and exposes a ZoomContent prop for fully custom modal content such as captions.

What You Get

  • Uncontrolled and Controlled component variants for self-managed or externally-driven zoom state
  • Support for img, background-image div/span, picture, figure, and svg elements out of the box
  • Built-in accessibility via the native dialog element, tested against JAWS, NVDA, VoiceOver, and TalkBack
  • Customizable zoom modal content via the ZoomContent render prop, plus swipe-to-unzoom gesture support

Common Use Cases

  • Blog and documentation sites letting readers zoom into screenshots or diagrams without leaving the page
  • Product and portfolio galleries where thumbnails expand to full-size on click
  • Photography sites needing an accessible lightbox-style viewer without a heavyweight gallery dependency
  • Next.js and Gatsby image pipelines (gatsby-plugin-image, next/image) that need zoom added on top of optimized images

Under The Hood

Architecture The component is built around a single core class-based ControlledBase (in controlled.tsx) that manages a state machine (ModalState: LOADED/LOADING/UNLOADED/UNLOADING) for the dialog lifecycle, wrapped by two public entry points: Controlled (a thin wrapper around ControlledBase) and Uncontrolled (a functional component holding its own isZoomed state via useState/useCallback that delegates rendering to Controlled). It renders into a native <dialog> element found or created via getDialogContainer() (a singleton [data-rmiz-portal] div appended to document.body) using ReactDOM.createPortal, and observes the original element via ResizeObserver and DOM queries against an IMAGE_QUERY selector that matches <img>, <svg>, [role="img"], and [data-zoom] children. All positioning math is factored into pure utility functions under src/utils/ (get-style-modal-img.ts, compute-positioned-style.ts, get-scale.ts, get-target-dimension.ts, get-modal-img-transform.ts), so controlled.tsx handles DOM refs and lifecycle while geometry calculations stay isolated and testable.

Tech Stack TypeScript makes up the vast majority of the codebase, targeting ES2021 and built via tsc through tsconfig.build.json. The only runtime dependencies are React and ReactDOM, declared as peer dependencies supporting a wide range of React versions. It relies on native <dialog> and ResizeObserver browser APIs rather than polyfills. Development tooling is modern: oxlint/oxlint-tsgolint for linting, oxfmt for formatting, vitest with happy-dom for testing, storybook for the interactive documentation site, and changesets for versioned releases via pnpm. It ships as ESM only, with a dedicated script that verifies server-side-render safety before publishing.

Code Quality Test coverage is extensive: nearly every utility function has a co-located test file, alongside a substantial test suite for the main controlled component covering interactive behavior, all run via vitest with a happy-dom DOM environment. Types are strict throughout, with fully documented exported prop interfaces. Error handling is necessarily light for a presentational UI library, but defensive checks guard DOM queries. Naming is consistent and descriptive, and a combined CI script enforces linting, formatting, type-checking, tests, and build together before publish.

What Makes It Unique The library’s distinguishing choice is building the zoom/dialog behavior on the native <dialog> element and ResizeObserver instead of a hand-rolled modal-and-portal stack with manual resize listeners, which gives it built-in focus-trapping, Escape-to-close, and top-layer stacking directly from the browser. It supports zooming a wide range of content shapes through one shared detection layer, and offers fully swappable modal content via a render-prop for custom captions or UI, a level of customization most comparable libraries don’t expose. It also carries zero runtime dependencies beyond React.

Used by 7 apps in this directory

TypeScript
100%
Other

Dub

Analytics · Marketing

24,835

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
81
Repo Health
78
Technical
62
Dependency
Built with
TypeScript 100%
Updated 4 days ago
TypeScript
53%
Apache 2.0

Flowsint

Automation · Developer Tools

8,978

A privacy-first, graph-based OSINT investigation platform with 30+ automated enrichers for mapping relationships between domains, IPs, people, and organizations.

View details
84
Repo Health
71
Technical
67
Dependency
Built with
TypeScript 53%
Python 45%
Updated 1 weeks ago
TypeScript
96%
Other

LLM Gateway

AI Development · Devops

1,663

One API endpoint for 25+ LLM providers — route, track costs, enforce compliance, and switch models without changing your code.

View details
86
Repo Health
80
Technical
68
Dependency
Built with
TypeScript 96%
Updated 5 days ago
TypeScript
88%
MIT

medusa

Ecommerce

36,494

The most flexible open-source commerce platform — build B2C, B2B, and marketplace applications with modular, composable commerce primitives.

View details
93
Repo Health
87
Technical
63
Dependency
Built with
TypeScript 88%
JavaScript 12%
Updated 1 weeks ago
TypeScript
97%
GPL 3.0

OpenKnowledge

Code Editors · Knowledge Management · Note Taking

4,337

A beautiful, local-first markdown IDE that turns any git repo into a live collaborative workspace for humans and AI coding agents like Claude, Codex, and OpenCode.

View details
79
Repo Health
89
Technical
64
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
82%
AGPL 3.0

OpenStatus

Devops · Monitoring

9,143

Open-source status pages and uptime monitoring with global synthetic checks, monitoring-as-code, and AI agent integration via MCP.

View details
77
Repo Health
82
Technical
69
Dependency
Built with
TypeScript 82%
MDX 15%
Updated 5 days ago
TypeScript
72%
Apache 2.0

Supabase

Authentication · Databases · Developer Tools

110,828

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript 72%
MDX 26%
Updated 4 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers