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.3.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

npm install react-js-element-picker
yarn add react-js-element-picker

Peer dependencies: react and react-dom (18+).

Under the hood

This package wraps js-element-picker. Use that if you need vanilla JS/TS or a non-React integration.

Usage

import { useState } from 'react';
import {
  ElementPickerArea,
  type ElementPickerAreaProps,
} from 'react-js-element-picker';

function InspectorPanel() {
  const [picking, setPicking] = useState(true);

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

TypeScript types

import type {
  ElementPickerAreaProps,
  ElementPickerOverlayPosition,
} from 'react-js-element-picker';

const props: ElementPickerAreaProps = {
  picking: true,
  children: null,
};

ElementPickerOverlayPosition is { x, y, width, height } | null — the position argument passed to overlayDrawer.

ElementPickerArea

Renders a container; while picking is true, the user can hover and click to select a child element inside this area.

Props

| Name | Type | Description | |------|------|-------------| | picking | boolean | If true, picking is active; if false, it stops. | | overlayDrawer | See below | Custom hover overlay; omit for the default overlay. | | onTargetChange | (target?: Element, event?: MouseEvent) => void | Fires when the hovered target changes while picking. | | onClick | (target?: Element, event?: MouseEvent) => void | Fires when the user clicks a target while picking. |

overlayDrawer

import type { ReactElement } from 'react';

overlayDrawer?: (
  position: ElementPickerOverlayPosition,
  event: MouseEvent | null
) => ReactElement;

position mirrors geometry from the hover event for convenience. The returned JSX is rendered to static markup for the overlay (no React hooks inside this subtree).


Examples

Basic: pick once, then stop

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

export function BasicExample() {
  const [picking, setPicking] = useState(true);

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

Start picking after a button click

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

export function StartOnButtonExample() {
  const [picking, setPicking] = useState(false);

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

onTargetChange while hovering

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

export function HoverPreviewExample() {
  const [picking, setPicking] = useState(true);

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

Custom overlay (overlayDrawer)

overlayDrawer must return JSX. The library renders it via react-dom/server for the native picker overlay, so treat it as static markup (avoid relying on hooks inside this inner component).

import { useState } from 'react';
import {
  ElementPickerArea,
  type ElementPickerOverlayPosition,
} from 'react-js-element-picker';

function HoveringOverlay({
  position,
  event,
}: {
  position: ElementPickerOverlayPosition;
  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>
  );
}

export function CustomOverlayExample() {
  const [picking, setPicking] = useState(true);

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