npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-image-maps

v0.1.2

Published

Responsive HTML image maps for React

Readme

React Image Maps

Responsive HTML image maps for React with automatic coordinate scaling

npm version Downloads/week License: MIT

A simple React component for HTML image maps with the key feature that native <map> lacks: automatic responsive coordinate scaling.

Perfect for interactive image maps that need to work at any screen size, in fluid layouts, or on mobile — without any CSS tricks.

Installation

npm install react-image-maps

Quick Start

import React from 'react'
import ReactImageMaps, { Area } from 'react-image-maps'

const areas: Area[] = [
  {
    shape: 'rect',
    coords: [34, 44, 270, 350],
    alt: 'Computer',
    href: 'https://example.com/computer',
  },
  {
    shape: 'circle',
    coords: [337, 300, 44],
    alt: 'Coffee cup',
    onClick: (area) => console.log('clicked', area.alt),
  },
]

function App() {
  return (
    <ReactImageMaps
      src="/office.jpg"
      alt="Office scene"
      mapName="office-map"
      areas={areas}
      originalWidth={800}
    />
  )
}

The originalWidth should match the natural pixel width of the source image (or whatever coordinate space your coords were defined in). The component scales all coordinates proportionally as the image resizes.

API Reference

<ReactImageMaps />

Props

| Prop | Type | Required | Description | | --- | --- | --- | --- | | src | string | Yes | URL of the image to display | | alt | string | No | Alt text for the <img> element | | mapName | string | Yes | Unique name for the <map> element | | areas | Area[] | Yes | Array of clickable area definitions | | originalWidth | number | Yes | Pixel width the coordinates were defined at |

Area object

| Property | Type | Required | Description | | --- | --- | --- | --- | | shape | 'rect' \| 'circle' \| 'poly' | No | Shape of the area. Defaults to 'rect' | | coords | number[] | Yes | Coordinates in original image pixel space, scaled automatically at render time | | alt | string | No | Alt text for the area | | href | string | No | Link target. Defaults to '#' when onClick is provided | | onClick | (area: Area) => void | No | Click handler. Prevents default navigation automatically |

TypeScript Support

The component is fully typed and exports the following types:

import ReactImageMaps, { type Area, type ReactImageMapsProps } from 'react-image-maps'

const areas: Area[] = [
  { shape: 'rect', coords: [0, 0, 100, 100], alt: 'Top left region' }
]

Examples

Click Handlers

const areas: Area[] = [
  {
    shape: 'rect',
    coords: [34, 44, 270, 350],
    alt: 'Product A',
    onClick: (area) => {
      console.log('Clicked:', area.alt)
    },
  },
]

Mixed Shapes

const areas: Area[] = [
  // Rectangle: [x1, y1, x2, y2]
  { shape: 'rect', coords: [0, 0, 200, 150], alt: 'Header region' },

  // Circle: [cx, cy, radius]
  { shape: 'circle', coords: [300, 200, 50], alt: 'Logo' },

  // Polygon: [x1, y1, x2, y2, x3, y3, ...]
  { shape: 'poly', coords: [100, 0, 200, 100, 0, 100], alt: 'Triangle' },
]

With Navigation

const areas: Area[] = [
  {
    shape: 'rect',
    coords: [34, 44, 270, 350],
    alt: 'Go to products',
    href: '/products',
  },
]

Why This Component?

  • Native <map> limitation: Coordinates are fixed pixel values — they break when the image scales
  • This component solves that: Uses ResizeObserver to track rendered width and scales coordinates live
  • React-friendly: Manages the observer lifecycle with useEffect
  • Simple API: Familiar <area> shape and coord conventions, just pass arrays
  • TypeScript: Full type safety out of the box

License

MIT License. See LICENSE for details.