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

@brightgoose/react-highlight

v0.1.4

Published

A React highlighter library

Readme

@brightgoose/react-highlight

Highlight text ranges in readonly elements, <input> and <textarea> elements in React.

Works by overlaying a styled copy of contents on top of the native element — preserving all native behavior: selection, IME, undo/redo, accessibility, and scroll.

Theoretically can be used with any UI library that allows passing refs to its input/textarea components, but only tested with native elements and Mantine so far.

Install

npm install @brightgoose/react-highlight

Requires React 19+.

Usage

Highlighted Input

import { useState } from "react";
import {
  useInputHighlight,
  InputOverlay,
  HighlightedText,
  type HighlightedRange,
} from "@brightgoose/highlight";

const ranges: HighlightedRange<{ color: string }>[] = [
  { r: [0, 5], data: { color: "red" } },
  { r: [6, 11], data: { color: "blue" } },
];

const renderRange = (key: string, text: string, data?: { color: string }) => (
  <span key={key} style={{ color: data?.color ?? "inherit" }}>
    {text}
  </span>
);

export function HighlightedInput() {
  const [value, setValue] = useState("Hello world");
  const {
    containerRef,
    inputRef,
    overlayRef,
    overlayStyle,
    displaying,
    onScroll,
  } = useInputHighlight();

  return (
    <div ref={containerRef} style={{ position: "relative" }}>
      <input
        ref={inputRef}
        value={value}
        onChange={(e) => setValue(e.target.value)}
        onScroll={onScroll}
        style={{
          color: displaying ? "transparent" : undefined,
          caretColor: "black",
        }}
      />
      {displaying && (
        <InputOverlay ref={overlayRef} style={overlayStyle}>
          <HighlightedText
            text={value}
            ranges={ranges}
            renderRange={renderRange}
          />
        </InputOverlay>
      )}
    </div>
  );
}

Highlighted Textarea

import { useState } from "react";
import {
  useTextareaHighlight,
  InputOverlay,
  HighlightedText,
  type HighlightedRange,
} from "@brightgoose/highlight";

const ranges: HighlightedRange<{ color: string }>[] = [
  { r: [0, 5], data: { color: "red" } },
];

const renderRange = (key: string, text: string, data?: { color: string }) => (
  <span key={key} style={{ color: data?.color ?? "inherit" }}>
    {text}
  </span>
);

export function HighlightedTextarea() {
  const [value, setValue] = useState("Hello world");
  const {
    containerRef,
    inputRef,
    overlayRef,
    overlayStyle,
    displaying,
    onScroll,
  } = useTextareaHighlight();

  return (
    <div ref={containerRef} style={{ position: "relative" }}>
      <textarea
        ref={inputRef}
        value={value}
        onChange={(e) => setValue(e.target.value)}
        onScroll={onScroll}
        style={{
          color: displaying ? "transparent" : undefined,
          caretColor: "black",
        }}
      />
      {displaying && (
        <InputOverlay ref={overlayRef} style={overlayStyle} textarea>
          <HighlightedText
            text={value}
            ranges={ranges}
            renderRange={renderRange}
          />
        </InputOverlay>
      )}
    </div>
  );
}

Ranges

A HighlightedRange is a character range [start, end] with optional attached data:

type HighlightedRange<D = unknown> = {
  r: [number, number]; // [startIndex, endIndex], exclusive end
  data?: D;
};

Overlapping and nested ranges are supported. When ranges overlap, they are split at the boundary. Your renderRange function receives the split segments.

When ranges overlap or nest, by default the inner (child) range's data wins at overlapping segments. You can control this with the mergeRangesData prop on <HighlightedText>:

API

useInputHighlight()

Hook for <input> elements. Returns { containerRef, inputRef, overlayRef, overlayStyle, displaying, onScroll }.

useTextareaHighlight()

Hook for <textarea> elements. Returns the same shape.

<InputOverlay ref style textarea?>

The overlay container. Pass textarea prop for textarea mode. Forward the overlayRef from the hook.

<HighlightedText text ranges renderRange mergeRangesData?>

Renders text split into ranges. Place inside InputOverlay or use to render readonly text.

  • text — the full string
  • ranges — array of HighlightedRange
  • renderRange(key, text, data?) — called for each segment, highlighted or not
  • mergeRangesData?(parentData, childData) — optional callback to merge data at overlapping segments; default behaviour is for the inner range's data to win

License

MIT