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-js-element-picker

v0.2.0

Published

React TypeScript library for selecting elements on a web page

Readme

react-js-element-picker

React TypeScript library for selecting elements on a web page.

Installation

Install with npm:

npm install react-js-element-picker

Or yarn:

yarn add react-js-element-picker

Basic JavaScript/TypeScript library

This library is based on another JavaScript/TypeScript library js-element-picker. If you need to use pure JS/TS or want to write a wrapper for another framework, you can get the library here

ElementPickerArea

Library contain React component ElementPickerArea. When you create it, it allows you to pick any child of this component

Simple example

import { ElementPickerArea } from 'react-js-element-picker';

const MyComponentWithPickingArea = () => {
  const [picking, setPicking] = useState<boolean>(true);
  
  <ElementPickerArea
    picking={picking}
    onClick={(target) => {
      console.log('Goal target is: ', target?.tagName);
      setPicking(false);
    }}
  >
    <div>
      <h1>First item</h1>
      <h1>Second item</h1>
    </div>
  </ElementPickerArea>;
};

Props

| Name | Type | Default | Description |-------------|-------------|---------|-------------| | picking | boolean | |if true, starts picking, if false, stops picking| | overlayDrawer | Function | Default overlay |See type below. If overlayDrawer was passed, it will be drawn instead of default overlay on the hovering element| | onTargetChange | (target?: Element, event?: MouseEvent) => void; | |callback that will fire every time when hovering target was changed| | onClick | (target: Element, event?: MouseEvent) => void; | |callback that fires when user clicks on the picked element|

overlayDrawer type:

overlayDrawer?: (
    position: {
      x: number;
      y: number;
      width: number;
      height: number;
    } | null,
    event: MouseEvent | null
  ) => JSX.Element;

Examples

In this example you create ElementPickerArea component which starts picking immediately after initialization and after click on target logs it in console and stops picking

import { ElementPickerArea } from 'react-js-element-picker';

const MyComponentWithPickingArea = () => {
const [picking, setPicking] = useState<boolean>(true);

<ElementPickerArea
  picking={picking}
  onClick={(target) => {
    console.log('Goal target is: ', target?.tagName);
    setPicking(false);
  }}
>
  <div>
    <h1>First item</h1>
    <h1>Second item</h1>
  </div>
</ElementPickerArea>;
};

If you want to start picking on any event (for example, button click), you can use picking prop

import { ElementPickerArea } from 'react-js-element-picker';

const MyComponentWithPickingArea = () => {
const [picking, setPicking] = useState<boolean>(true);

<>
    <button onClick={() => setPicking(true)}>Start picking</button>
    <ElementPickerArea
      picking={picking}
      onClick={(target) => {
        console.log('Goal target is: ', target?.tagName);
        setPicking(false);
      }}
    >
      <div>
        <h1>First item</h1>
        <h1>Second item</h1>
      </div>
    </ElementPickerArea>
</>
};

If you want to make something while user is picking elements, you can use onTargetChange prop. That is function which will fire every time when target was updated

import { ElementPickerArea } from 'react-js-element-picker';

const MyComponentWithPickingArea = () => {
const [picking, setPicking] = useState<boolean>(true);

<ElementPickerArea
  picking={picking}
  onClick={(target) => {
    console.log('Goal target is: ', target?.tagName);
    setPicking(false);
  }}
  onTargetChange={(target) => {
    console.log('Hovering target is: ', target?.tagName);
  }}
>
  <div>
    <h1>First item</h1>
    <h1>Second item</h1>
  </div>
</ElementPickerArea>;
};

If you want to create custom overlay for hovering element, you need to pass overlayDrawer() prop. It gets position and event as arguments and must return an JSX.Element. Result element will appear inside of overlay, so you don't need to think about positioning. Actually position is some fields from event just to make it easier to get.

So first you need to create a component for overlay drawer:

const HoveringOverlay = ({
  position,
  event,
}: {
  position: { x: number; y: number } | null;
  event: MouseEvent | null;
}) => {
  const target = event ? (event.target as Element) : null;

  return (
    <div className="hovering-overlay">
      {target ? <span>{target?.tagName}</span> : null}
      {position ? <span>{`${position.x}, ${position.y}`}</span> : null}
    </div>
  );
};
.hovering-overlay {
  height: 100%;
  width: 100%;
  background-color: rgba(255, 0, 166, 0.504);
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  align-items: center;
  color: white;
  font-family: monospace;
}

And then you can use it:

import { ElementPickerArea } from 'react-js-element-picker';

const MyComponentWithPickingArea = () => {
const [picking, setPicking] = useState<boolean>(true);

<ElementPickerArea
  picking={picking}
  onClick={(target) => {
    console.log('Goal target is: ', target?.tagName);
    setPicking(false);
  }}
  overlayDrawer={(position, event) => (
      <HoveringOverlay position={position} event={event} />
  )}
>
  <div>
    <h1>First item</h1>
    <h1>Second item</h1>
  </div>
</ElementPickerArea>;
};

As a result you'll see something like this: