@danielmoraes/yet-another-react-lightbox

中文文档
1.1.0发布于 2024/06/07MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3520

Modern React lightbox component

原始使用文档
文档目录8 节
  1. Overview
  2. Documentation
  3. Examples
  4. Installation
  5. Minimal Setup Example
  6. Recommended Setup
  7. Plugins
  8. License

Yet Another React Lightbox

Modern React lightbox component. Performant, easy to use, customizable and extendable.

Overview

NPM Version Bundle Size License MIT

  • Built for React: works with React 18, 17 and 16.8.0+
  • UX: supports keyboard, mouse, touchpad and touchscreen navigation
  • Preloading: never displays partially downloaded images
  • Performance: preloads limited number of images without compromising performance or UX
  • Responsive: responsive images with automatic resolution switching are supported out of the box
  • Video: video slides are supported via an optional plugin
  • Zoom: image zoom is supported via an optional plugin
  • Customization: customize any UI element or add your own custom slides
  • No bloat: never bundle rarely used features; add optional features via plugins
  • TypeScript: type definitions come built-in in the package
  • RTL: compatible with RTL layout

Yet Another React Lightbox | Example

Documentation

https://yet-another-react-lightbox.com/documentation

Examples

https://yet-another-react-lightbox.com/examples

Installation

npm install yet-another-react-lightbox

or

yarn add yet-another-react-lightbox

Minimal Setup Example

import * as React from "react";
import Lightbox from "yet-another-react-lightbox";
import "yet-another-react-lightbox/styles.css";

export default function App() {
    const [open, setOpen] = React.useState(false);

    return (
        <>
            <button type="button" onClick={() => setOpen(true)}>
                Open Lightbox
            </button>

            <Lightbox
                open={open}
                close={() => setOpen(false)}
                slides={[{ src: "/image1.jpg" }, { src: "/image2.jpg" }, { src: "/image3.jpg" }]}
            />
        </>
    );
}

Unlike many other lightbox libraries, Yet Another React Lightbox doesn't have a concept of "thumbnail" or "original" (or "full size") images. We use responsive images instead and recommend you provide multiple files of different resolutions for each image. Yet Another React Lightbox automatically populates srcset / sizes attributes and lets the browser decide which image is more appropriate for its viewport size.

import * as React from "react";
import Lightbox from "yet-another-react-lightbox";
import "yet-another-react-lightbox/styles.css";

export default function App() {
    const [open, setOpen] = React.useState(false);

    return (
        <>
            <button type="button" onClick={() => setOpen(true)}>
                Open Lightbox
            </button>

            <Lightbox
                open={open}
                close={() => setOpen(false)}
                slides={[
                    {
                        src: "/image1x3840.jpg",
                        alt: "image 1",
                        width: 3840,
                        height: 2560,
                        srcSet: [
                            { src: "/image1x320.jpg", width: 320, height: 213 },
                            { src: "/image1x640.jpg", width: 640, height: 427 },
                            { src: "/image1x1200.jpg", width: 1200, height: 800 },
                            { src: "/image1x2048.jpg", width: 2048, height: 1365 },
                            { src: "/image1x3840.jpg", width: 3840, height: 2560 },
                        ],
                    },
                    // ...
                ]}
            />
        </>
    );
}

You can also integrate 3rd-party image components (e.g., Next.js Image or Gatsby Image) via a custom render function. See examples on the documentation website.

Plugins

Yet Another React Lightbox allows you to add optional features to your project based on your requirements via plugins.

The following plugins are bundled in the package:

  • Captions - adds support for slide title and description
  • Counter - adds slides counter
  • Download - adds download button
  • Fullscreen - adds support for fullscreen mode
  • Inline - transforms the lightbox into an image carousel
  • Share - adds sharing button
  • Slideshow - adds slideshow button
  • Thumbnails - adds thumbnails track
  • Video - adds support for video slides
  • Zoom - adds image zoom feature

License

MIT © 2022 Igor Danchenko

版本与发布记录

@danielmoraes/yet-another-react-lightbox 共发布 6 个版本,首次发布于 2023/09/27;过去 12 个月发布了 0 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2024/06/072 年前
0.0.52023/09/283 年前
0.0.42023/09/273 年前
0.0.32023/09/273 年前
0.0.22023/09/273 年前
0.0.12023/09/273 年前

关于 @danielmoraes/yet-another-react-lightbox 的常见问题

@danielmoraes/yet-another-react-lightbox 是什么?

Modern React lightbox component

如何安装 @danielmoraes/yet-another-react-lightbox?

在项目目录运行 npm install @danielmoraes/yet-another-react-lightbox,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0)、react-dom(>=16.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@danielmoraes/yet-another-react-lightbox 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@danielmoraes/yet-another-react-lightbox 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@danielmoraes/yet-another-react-lightbox 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@danielmoraes/yet-another-react-lightbox 可以商用吗?

@danielmoraes/yet-another-react-lightbox 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@danielmoraes/yet-another-react-lightbox 的下载量有多少?

根据 npm 官方下载统计,@danielmoraes/yet-another-react-lightbox 在 2026/10/12 – 2026/11/10 这 30 天内被下载 3,520 次,日均约 117 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@danielmoraes/yet-another-react-lightbox 还在维护吗?

最新版本 1.1.0 发布于 2024/06/07(2 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/09/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。