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

@hanakla/react-lightbox

v1.0.5

Published

[![npm version](https://img.shields.io/npm/v/@hanakla/react-lightbox.svg?style=flat-square)](https://www.npmjs.com/package/@hanakla/react-lightbox) [![npm downloads](https://img.shields.io/npm/dm/@hanakla/react-lightbox.svg?style=flat-square)](https://www

Readme

@hanakla/react-lightbox

npm version npm downloads bundle size license

A flexible headless lightbox component for React.

Inspired by react-image-viewer-hook, reimagined as a headless component library for maximum flexibility and customization.

Demo

Try it out on CodeSandbox:

Open in CodeSandbox

Features

  • Headless design - Fully customizable UI with complete control over styling
  • Pinch-to-zoom support - Built-in support for touch gestures on mobile devices
  • TypeScript support - Fully typed API for better developer experience
  • Flexible architecture - Compose your own lightbox with provided building blocks
  • Accessible - Keyboard navigation and proper ARIA attributes

Installation

npm install @hanakla/react-lightbox

Anatomy

Import the component and assemble its parts:

import {
  useLightbox,
  Lightbox,
  useLightboxState,
} from "@hanakla/react-lightbox";

function App() {
  const lb = useLightbox({
    LightboxComponent: MyLightbox,
  });

  return (
    <>
      <button onClick={lb.getOnClick(item)}>Open</button>
      <lb.LightboxView />
    </>
  );
}

function MyLightbox() {
  const lbContext = useLightboxState();

  return (
    <Lightbox.Root>
      <Lightbox.Header>
        <Lightbox.Close />
      </Lightbox.Header>
      <Lightbox.Viewport
        $renderItem={(item, index) => (
          <Lightbox.Item $index={index}>
            <Lightbox.Pinchable>{/* Your content */}</Lightbox.Pinchable>
          </Lightbox.Item>
        )}
      />
    </Lightbox.Root>
  );
}

Usage

The lightbox is built with a headless architecture, giving you complete control over the UI while handling the complex interaction logic.

How it works

  1. Initialize the hook - Call useLightbox with your custom lightbox component
  2. Trigger the lightbox - Use lb.getOnClick(item) to open the lightbox with specific content
  3. Render the viewer - Place <lb.LightboxView /> in your component tree
  4. Build your UI - Compose your lightbox interface using the provided building blocks

The library separates concerns:

  • useLightbox manages state and provides methods to control the lightbox
  • useLightboxState provides access to the current state within your lightbox component
  • Lightbox.* components are the building blocks for your custom UI

Basic example

import {
  useLightbox,
  Lightbox,
  useLightboxState,
} from "@hanakla/react-lightbox";

type ImageItem = {
  kind: "image";
  url: string;
};

function App() {
  const lb = useLightbox<ImageItem>({
    onLoadNext: () => {
      console.log("Request to load next");
    },
    LightboxComponent: ImageLightbox,
  });

  const images = [
    { kind: "image", url: "/image1.jpg" },
    { kind: "image", url: "/image2.jpg" },
    { kind: "image", url: "/image3.jpg" },
  ];

  return (
    <div>
      {images.map((img, index) => (
        <img
          key={index}
          src={img.url}
          onClick={lb.getOnClick(img)}
          style={{ cursor: "pointer" }}
        />
      ))}

      <lb.LightboxView />
    </div>
  );
}

function ImageLightbox({ items, defaultIndex }: Lightbox.Props<ImageItem>) {
  const lbContext = useLightboxState<ImageItem>();

  const renderItem = (item: ImageItem, index: number) => {
    if (item.kind === "image") {
      return (
        <Lightbox.Item
          $index={index}
          className="flex items-center justify-center flex-1 p-5"
        >
          <Lightbox.Pinchable onRequestClose={lbContext.close}>
            <img src={item.url} draggable={false} />
          </Lightbox.Pinchable>
        </Lightbox.Item>
      );
    }
    return null;
  };

  return (
    <Lightbox.Root className="fixed inset-0 isolate flex flex-col bg-black/80">
      <Lightbox.Header className="flex items-center justify-end w-full py-2 px-4 bg-black/80 text-white">
        <Lightbox.Close>
          <span className="text-[24px]">&times;</span>
        </Lightbox.Close>
      </Lightbox.Header>

      <Lightbox.Viewport className="flex flex-1" $renderItem={renderItem} />
    </Lightbox.Root>
  );
}

API Reference

useLightbox

const lb = useLightbox<T>(options);

Main hook to create a lightbox.

Type Parameters

| Parameter | Description | | --------- | -------------------------------------------- | | T | The type of items to display in the lightbox |

Parameters

| Prop | Type | Default | Description | | ------------------- | ---------------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------ | | LightboxComponent | React.ComponentType<Lightbox.Props<T>> | — | Custom lightbox component to render when the lightbox is opened | | onLoadNext | () => void | undefined | Callback invoked when the user navigates to the last item. Useful for implementing infinite scroll or lazy loading |

Returns

| Property | Type | Description | | -------------- | -------------------------------------------- | --------------------------------------------------------------------------------------- | | getOnClick | (item: T) => (e: React.MouseEvent) => void | Returns a click handler function that opens the lightbox with the specified item | | LightboxView | React.ComponentType | Component that renders the lightbox modal. Should be placed once in your component tree |


useLightboxState

const lbContext = useLightboxState<T>();

Hook to access the current lightbox state from within lightbox components.

Type Parameters

| Parameter | Description | | --------- | --------------------------------- | | T | The type of items in the lightbox |

Returns

| Property | Type | Description | | ----------------- | ------------------------- | ------------------------------------------------------------------- | | items | T[] | Array of all items currently in the lightbox | | currentIndex | number | Index of the currently displayed item | | currentItem | T \| undefined | The currently displayed item, or undefined if no item is selected | | setCurrentIndex | (index: number) => void | Function to programmatically change the current item by index | | close | () => void | Function to close the lightbox |


Lightbox.Root

<Lightbox.Root className="...">

Root container for the lightbox.


Lightbox.Header

<Lightbox.Header className="...">

Container for header content like close button and actions.


Lightbox.Close

<Lightbox.Close>
  <span>&times;</span>
</Lightbox.Close>

Button to close the lightbox.


Lightbox.Viewport

<Lightbox.Viewport $renderItem={(item, index) => ...} />

Main viewport area that displays the lightbox items.

Props

| Prop | Type | Default | Description | | ------------- | --------------------------------------------- | ------- | --------------------------------------------------------------------------------------------- | | $renderItem | (item: T, index: number) => React.ReactNode | — | Render function called for each item in the lightbox. Must return a Lightbox.Item component |


Lightbox.Item

<Lightbox.Item $index={index}>

Wrapper component for individual lightbox items.

Props

| Prop | Type | Default | Description | | -------- | -------- | ------- | --------------------------------------------------------------------------------- | | $index | number | — | Index of the item being rendered. Used to track which item is currently displayed |


Lightbox.Pinchable

<Lightbox.Pinchable onRequestClose={lbContext.close}>
  <img src="..." />
</Lightbox.Pinchable>

Helper component that adds pinch-to-zoom and pan gestures to its children.

Props

| Prop | Type | Default | Description | | ---------------- | ------------ | ----------- | --------------------------------------------------------------------------------------------------- | | onRequestClose | () => void | undefined | Callback invoked when the user performs a close gesture. Typically connected to lbContext.close() |

Features

  • Pinch-to-zoom gesture support on touch devices
  • Pan gesture when zoomed in
  • Double-tap to zoom
  • Smooth animations and transitions

Credits

This library is based on react-image-viewer-hook by rkusa, reimagined as a headless component library for maximum flexibility and customization.

Original work Copyright (c) Markus Ast (rkusa)

License

MIT

Copyright (c) [Your Name/Organization]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.