@danielmoraes/yet-another-react-lightbox

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

现代反应灯盒组件

中文使用文档
文档目录8 节
  1. 概览
  2. 文档
  3. 实例
  4. 安装
  5. 最小设置示例
  6. 建议设置
  7. 插件
  8. 许可证

然而,另一个反射灯盒

现代反应灯盒组件. 表演者,易于使用,可定制和可扩展.

概览

NPM Version Bundle Size License MIT

  • 为反应所建 : 与反应18、17和16.8.0+合作
  • UX : (韩语) 支持键盘、鼠标、触摸板和触摸屏导航
  • 预装 : 从未显示部分下载的图像
  • 性能 : 在不损害性能或UX的情况下预装有限数量的图像
  • 响应 : 框外支持带有自动分辨率切换的响应图像
  • 视频 : 通过可选插件支持视频幻灯片
  • 缩放 : 通过可选插件支持图像缩放
  • 自定义 : 自定义任何 UI 元素或添加自定义幻灯片
  • 没有出血 : 从未捆绑过很少使用的特性; 通过插件添加可选特性
  • 类型脚本 : 类型定义出现在软件包中
  • RTL: (英语) 兼容RTL布局

Yet Another React Lightbox | Example

文档

https://yet-an-other-react-lightbox.com/documentation 页面存档备份,存于互联网档案馆

实例

https://yet-another-resact-lightbox.com/examples 页面存档备份,存于互联网档案馆

安装

npm install yet-another-react-lightbox

或者说

yarn add yet-another-react-lightbox

最小设置示例

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" }]}
            />
        </>
    );
}

与其他许多灯盒库不同,然而"又一反应"灯盒没有"thumbnail"或"原生"的概念 (或"全尺寸")相相. 我们使用响应图像 推荐您提供不同的文件 每个图像的分辨率。 然而,另一个反应灯盒自动弹出 srcset 编号 : sizes 属性和允许 浏览器决定哪个图像更适合其视图大小.

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 },
                        ],
                    },
                    // ...
                ]}
            />
        </>
    );
}

也可以通过自定义渲染函数来整合第三方图像组件(如Next.js Image或Gatsby Image). 见 实例 在文档网站上.

插件

然而,另一个反应灯盒允许您根据您的要求通过插件在您的工程中添加可选功能 .

以下插件被捆绑在软件包中 :

许可证

麻省理工学院 2022年 伊戈尔·丹琴科

版本与发布记录

@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 是什么?

现代反应灯盒组件

如何安装 @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 和提交记录判断。