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-img-mapper

v2.0.2

Published

A React Component for Creating Interactive and Highlighted Zones on Images

Readme

react-img-mapper

NPM Version NPM Downloads NPM Last Update

A React Component for Creating Interactive and Highlighted Zones on Images

Key Features

  1. Actively Maintained — continuously updated for better performance and compatibility.
  2. Built with TypeScript — ensuring type safety and enhanced developer experience.
  3. Next.js Ready — fully compatible with SSR and Next.js projects.
  4. Lightweight — optimized for minimal bundle size.
  5. Well-Documented — detailed examples and API references.
  6. Toggle & Reset Support — manage single or multiple highlighted areas with ease.
  7. Powerful Callbacks — access image metadata (width, height, etc.) via onLoad.
  8. Responsive by Design — adapt seamlessly to various screen sizes and containers.

Installation

Install using your preferred package manager:

# npm
npm install react-img-mapper

# yarn
yarn add react-img-mapper

# pnpm
pnpm install react-img-mapper

Demo & Examples

Live Demo: react-img-mapper.nishargshah.dev

To explore the example locally:

  1. Clone the repository:

    git clone https://github.com/img-mapper/img-mapper.git
  2. Install dependencies

    pnpm install
  3. Start the playground

    pnpm dev:react
  4. Open http://localhost:3000 in your browser.

To build the package, run:

pnpm build

Usage Example

Integrate react-img-mapper into your React app easily:

import React from 'react';
import ImageMapper from 'react-img-mapper';

const Mapper = () => {
  const url = 'https://react-img-mapper.nishargshah.dev/assets/example.jpg';
  const name = 'my-map';
  // Example JSON data for mapping areas
  const areas = 'https://react-img-mapper.nishargshah.dev/assets/areas.json';

  return <ImageMapper src={url} name={name} areas={areas} />;
};

export default Mapper;

Properties

| Prop | Type | Description | Default | | ---------------- | -------------------------- | ----------------------------------------------------------------- | -------------------------- | | src | string | URL of the image to display | required | | name | string | The name of the map, used to associate it with the image. | required | | areas | array | Array of area objects, please check Area Properties below | required | | areaKeyName | string | Key name used to uniquely identify areas | id | | isMulti | bool | Allows multiple areas to be highlighted | true | | toggle | bool | Enables toggling highlights for selected areas | false | | active | bool | Enables area listeners and highlighting | true | | disabled | bool | Disable highlighting, listeners, and removes area tag | false | | fillColor | string | Fill color of highlighted zones | rgba(255, 255, 255, 0.5) | | strokeColor | string | Border color of highlighted zones | rgba(0, 0, 0, 0.5) | | lineWidth | number | Border thickness of highlighted zones | 1 | | imgWidth | number | Original width of the image | 0 | | width | number | func => number | Image width (can use a function for dynamic sizing) | 0 | | height | number | func => number | Image height (can use a function for dynamic sizing) | 0 | | natural | bool | Use original dimensions for canvas and wrapper | false | | responsive | bool | Enable responsiveness (requires parentWidth) | false | | parentWidth | number | Maximum width of the parent container for responsiveness | 0 | | containerProps | object | Props for the container <div> element | null | | imgProps | object | Props for the <img> element | null | | canvasProps | object | Props for the <canvas> element | null | | mapProps | object | Props for the <map> element | null | | areaProps | object | array | Props for the <area> elements | null |


Callbacks

| Callback | Triggered On | Signature | | ------------------ | ----------------------------------- | ------------------------------- | | onChange | Clicking an area | (selectedArea, areas) => void | | onImageClick | Clicking outside of mapped zones | (event) => void | | onImageMouseMove | Moving the mouse over the image | (event) => void | | onClick | Clicking a mapped zone | (area, index, event) => void | | onMouseDown | Mouse down on a mapped zone | (area, index, event) => void | | onMouseUp | Mouse up on a mapped zone | (area, index, event) => void | | onTouchStart | Touching a mapped zone | (area, index, event) => void | | onTouchEnd | Ending a touch on a mapped zone | (area, index, event) => void | | onMouseMove | Moving the mouse over a mapped zone | (area, index, event) => void | | onMouseEnter | Hovering over a mapped zone | (area, index, event) => void | | onMouseLeave | Leaving a mapped zone | (area, index, event) => void | | onLoad | Image loaded and canvas initialized | (event, dimensions) => void |


Methods

| Method | Description | | ---------- | ------------------------------------------------------------ | | getRefs | Retrieves refs for the container, canvas, and image elements |


Areas Properties

| Property | Type | Description | Default | | -------------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------- | | id | string | A unique identifier for the area. If not provided, an index from the array is used. This can be customized using the areaKeyName property. | based on areaKeyName | | shape | string | Specifies the shape of the area: rect, circle, or poly. | required | | coords | array of number | Coordinates defining the area based on its shape: rect: top-left-X, top-left-Y, bottom-right-X, bottom-right-Ycircle: center-X, center-Y, radiuspoly: List of points defining the polygon as point-X, point-Y, ... | required | | active | bool | Enables or disables event listeners and highlighting for the area. | true | | disabled | bool | Disables all interactions, highlighting, and tag additions/removals for the area. | false | | href | string | A target link for clicks on the area. If an onClick handler is provided, the href will not be triggered. | undefined | | fillColor | string | Fill color of the highlighted zone | rgba(255, 255, 255, 0.5) | | strokeColor | string | Border color of the highlighted zone | rgba(0, 0, 0, 0.5) | | lineWidth | number | Border thickness of the highlighted zone | 1 | | preFillColor | string | Pre filled color of the highlighted zone | undefined |

When triggered by an event handler, an area object includes the following additional properties:

| Property | Type | Description | | -------------- | ----------------- | ------------------------------------------------------------------------ | | scaledCoords | array of number | Scaled coordinates adjusted based on the image's dimensions. | | center | array of number | The center or centroid coordinates of the area, represented as [X, Y]. |