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-media-lightbox

v0.1.1

Published

A lightweight, dependency-free React lightbox for images and video (YouTube, Vimeo, and self-hosted files).

Readme

react-media-lightbox

A lightweight, dependency-free React lightbox for images and video in a single component. Supports YouTube, Vimeo, and self-hosted video files, with keyboard navigation, looping, a loading spinner, image fallbacks, and a clean, responsive UI.

  • Zero runtime dependencies (only react as a peer dependency)
  • One unified <MediaLightbox> for mixed image + video galleries
  • YouTube, Vimeo, and self-hosted (<video>) sources
  • Keyboard nav (←/→/Esc), click-outside-to-close, body-scroll lock
  • ESM + CJS builds with TypeScript types
  • Works with React 18 and 19 (incl. Next.js App Router — ships "use client")

Installation

npm install react-media-lightbox

react and react-dom are peer dependencies (>= 18).

Usage

Import the component and the stylesheet once:

import { useState } from "react";
import { MediaLightbox, type MediaItem } from "react-media-lightbox";
import "react-media-lightbox/styles.css";

const items: MediaItem[] = [
  { type: "image", src: "https://picsum.photos/id/1015/1200/800", title: "A river" },
  { type: "video", src: "https://youtu.be/dQw4w9WgXcQ", title: "YouTube clip" },
  { type: "video", src: "https://vimeo.com/76979871", title: "Vimeo clip" },
  { type: "video", src: "https://example.com/clip.mp4", provider: "file", title: "Self-hosted", poster: "https://picsum.photos/id/1016/1200/800" },
];

export default function Gallery() {
  const [open, setOpen] = useState(false);
  const [index, setIndex] = useState(0);

  return (
    <>
      <button onClick={() => { setIndex(0); setOpen(true); }}>Open gallery</button>

      {open && (
        <MediaLightbox
          items={items}
          initialIndex={index}
          onClose={() => setOpen(false)}
          fallbackSrc="/no_image.png"
        />
      )}
    </>
  );
}

The lightbox is controlled by the parent: render it conditionally and supply an onClose handler. It does not manage its own visibility.

Props

| Prop | Type | Default | Description | | --- | --- | --- | --- | | items | MediaItem[] | — | Media to display (images and videos). | | initialIndex | number | 0 | Index opened first. | | onClose | () => void | — | Called on Esc, close button, or overlay click. | | fallbackSrc | string | — | Image shown when an image fails to load. | | showCounter | boolean | true | Show the N / total counter. | | loop | boolean | true | Wrap navigation at the ends. | | closeOnOverlayClick | boolean | true | Close when the dimmed background is clicked. | | lockBodyScroll | boolean | true | Lock page scroll while open. | | className | string | — | Extra class on the overlay root. | | onIndexChange | (index: number) => void | — | Fired when the active index changes. |

Item shapes

type ImageItem = {
  type: "image";
  src: string;
  title?: string;
  alt?: string; // falls back to title
};

type VideoItem = {
  type: "video";
  src: string;                                   // page/embed URL or direct file URL
  provider?: "youtube" | "vimeo" | "file" | "auto"; // default: "auto" (detected from src)
  title?: string;
  poster?: string;  // for "file" videos
  autoplay?: boolean; // default true
};

type MediaItem = ImageItem | VideoItem;

When provider is omitted or "auto", the provider is detected from the URL:

  • youtube.com / youtu.be / youtube-nocookie.com → YouTube iframe
  • vimeo.com → Vimeo iframe
  • anything else → self-hosted <video>

Helpers

The URL utilities are exported if you need them directly:

import { detectProvider, getEmbedURL, getYouTubeId, getVimeoId } from "react-media-lightbox";

Styling

All class names are prefixed with rml- to avoid collisions. Override them in your own CSS after importing react-media-lightbox/styles.css, or pass className for the overlay root.

License

MIT