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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-image-marker

v1.2.0

Published

Allows to add markers to an image

Downloads

9,490

Readme

react-image-marker makes it easy to add markers and tags to any image.

Why ?

Adding markers to images seems something really simple, isn't it? You just need to do some hacks with CSS to position your marker where it was clicked and it is done, right? NO!

There is a bunch of edge cases that need to be addressed:

  • When the screen size is changed, the markers need to keep the same reference.
  • When the image is half shown on the screen (let's suppose the user has scrolled down), clicking on the image should position the marker correctly.
  • Much more.

Install

Install with npm, or Yarn:

# via npm
npm install react-image-marker --save

# or Yarn (note that it will automatically save the package to your `dependencies` in `package.json`)
yarn add react-image-marker

Props

| Prop | Value | Required | | :-------------- | :-----------------------: | :------: | | src | image path | Yes | | markers | Array | Yes | | onAddMarker | Function (Marker) => void | No | | markerComponent | Component | No | | bufferLeft | Number | No | | bufferTop | Number | No | | alt | String | No | | extraClass | String | No |

Usage

First, you will need to import the ImageMarker. If you are using typescript on your project you can also import the type Marker.

// import the dependencies
import ImageMarker, { Marker } from 'react-image-marker';

Now you will need to provide an array of Markers. In this example, we are storing them with useState. top and left are numbers that represent the PERCENTAGE the marker is positioned in relation to the image size.

//Define the markers
const [markers, setMarkers] =
    useState <
    Array <
    Marker >>
        [
            {
                top: 10, //10% of the image relative size from top
                left: 50, //50% of the image relative size from left
            },
        ];

Now you just need to use the ImageMarker to render your markers

<ImageMarker
    src="my-image-path"
    markers={markers}
    onAddMarker={(marker: Marker) => setMarkers([...markers, marker])}
/>

It is going to render something like this

Usage - Custom Markers

You can also use a custom marker if you want. First, you will need to create a custom marker component.

// import the dependencies
import ImageMarker, { Marker, MarkerComponentProps } from 'react-image-marker';

const CustomMarker = (props: MarkerComponentProps) => {
    return (
        <p className="custom-marker">My custom marker - {props.itemNumber}</p>
    );
};

Now you just need to pass it through the prop markerComponent

<ImageMarker
    src="my-image-path"
    markers={markers}
    onAddMarker={(marker: Marker) => setMarkers([...markers, marker])}
    markerComponent={CustomMarker}
/>