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-hotspot-viewer

v0.3.0

Published

A React component to view add and manage hotspots over an image with tooltip. The component is built using [Material UI v5](https://material-ui.com/) and [React](https://reactjs.org/). Supports both desktop and mobile devices.

Downloads

70

Readme

React Image Hotspot Viewer - Material UI v5

View hotspots over an image with tooltip

A React component to view add and manage hotspots over an image with tooltip. The component is built using Material UI v5 and React. Supports both desktop and mobile devices.

Demo

This package supports both desktop and mobile devices. It behaves differently in both the devices.

Desktop View

In Desktop view, the hotspot is displayed on hover of the image. Clicking on the hotspot opens the tooltip.

productionimage

Managing Hotspots

The component supports adding, editing and deleting hotspots. The hotspots can be managed by onClickEvent prop. The prop is called whenever an event is triggered. More details on the prop can be found here.

EditableHotspots

Mobile View

In Mobile view, the hotspot is displayed as a pin on the image. Clicking on the hotspot opens the tooltip. The tooltip can be closed by clicking elsewhere on the image.

Installation

React Image Hotspot Viewer requires Node.js v10+ to run.

npm i react-image-hotspot-viewer@latest

Usage

Import Stylesheet

Import the stylesheet and Icons in your project

  <link href="https://devcdn.extscape.com/css/style.css" rel="stylesheet" />
 <link
    href="https://fonts.googleapis.com/css?family=Material+Icons|Material+Icons+Outlined|Material+Icons+Two+Tone|Material+Icons+Round|Material+Icons+Sharp"
    rel="stylesheet" />
Import Component

Import the component in your project

import { ImageHotspotViewer } from 'react-image-hotspot-viewer'
Add Component

Add the component in your project

 <ImageHotspotViewer
      image="https://devcdn.extscape.com/images/SampleRoom.avif"
      hotspots={hotspots}
      imageStyles={{
          borderRadius: '5px',
      }}
  />

Basic Example

import './App.css';
import { ImageHotspotViewer } from 'react-image-hotspot-viewer'

function App() {
  return (
    <div className="App">
      <div className="App-container">
        <ImageHotspotViewer
          image="https://devcdn.extscape.com/images/SampleRoom.avif"
          hotspots={hotspots}
          imageStyles={{
            borderRadius: '5px',
          }}
        />
      </div>
    </div>
  );
}

export default App;

Hotspots

[{
  id: 1,
  title: 'Sofa',
  description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem.',
  image: "https://devcdn.extscape.com/images/SeatSoftGrey.avif",
  position: {
    top: '80%',
    left: '35%'
  },
  action: {
    hasAction: true,
    type: 'link',
    url: 'https://www.google.com',
    label: 'View Product Details',
    icon: 'open_in_new',
  }
}, {
  id: 2,
  title: 'Lamp',
  description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem. Sed euismod, nunc ut aliquam aliquam, nunc nisl aliquet nisl, eget aliquam nisl nisl sit amet lorem.',
  position: {
    top: '40%',
    left: '82%'
  },
  action: {
    hasAction: false,
  }
}]

Props

| Prop | Type | Default | Description | Required | | ------ | ------ | ------ | ------ | ------ | | image | string | | Image URL | Yes | | hotspots | array | [] | Array of hotspots | Yes | | imageStyles | object | {} | Styles for image | No | | onClickEvent | function | | Function called whenever an event is triggered | No |

Hotspot Props

| Prop | Type | Default | Description | Required | | ------ | ------ | ------ | ------ | ------ | | id | string | | Unique ID for hotspot | Yes | | title | string | | Title for hotspot | Yes | | description | string | | Description for hotspot | No | | position | object | | Position for hotspot | Yes | | position.top | string | | Top position for hotspot in percentage | Yes | | position.left | string | | Left position for hotspot in percentage | Yes | | action | object | | Action for hotspot | No | | action.hasAction | boolean | | Has action for hotspot | Yes if action is present | | action.type | string | | Type of action for hotspot | Yes if action is present | | action.url | string | | URL for hotspot | Yes if action type is URL | | action.label | string | | Label for hotspot | No | | action.icon | string | | Icon for hotspot | No |# react-image-hotspot-viewer

Advanced Implementation

Example code for advanced implementation is available here:

Managing Events

The component supports two events. The events are triggered when the hotspot is clicked and when a new spot is clicked.

 <ImageHotspotViewer
    image={image}
    hotspots={hotspots}
    imageStyles={{
        borderRadius: '10px',
    }}
    onEventChange={onEventChange}
/>

onEventChange Function

onEventChange function is called whenever an event is triggered. The function takes three parameters.

  • event: The event that is triggered. The event can be click.
  • subEvent: The sub event that is triggered. The sub event can be add-hotspot or edit-hotspot
  • data: The data associated with the event. The data is an object with the properties based on the event and sub event. -- add-hotspot: The event is triggered when user clicks on the component. Sample data for this event is provided below. { "top": 78.06841046277665, // Top position of the hotspot in percentage "left": 51.64383561643836, // Left position of the hotspot in percentage "offsetX": 377, // Offset X position of the hotspot "offsetY": 388 // Offset Y position of the hotspot } -- edit-hotspot: The event is triggered when user clicks on the hotspot. { "offsetX": 377, // Offset X position of the hotspot "offsetY": 388 // Offset Y position of the hotspot {...restProps} // All the properties of the hotspot }
const onEventChange = (event, subEvent, data) => {
    switch (event) {
        case 'click':
            switch (subEvent) {
                case 'add-hotspot':
                    //Implement your logic to add hotspot here 
                    break;
                case 'edit-hotspot':
                    //Implement your logic to edit hotspot here
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}

Upcoming Features

Below are the features that are planned to be added in the near future.

  • [x] Add support for adding hotspot from UI
  • [ ] Add support for custom tootip style
  • [ ] Add support for custom pin styles

License

MIT

Free Software, Hell Yeah!