@depay/react-dialog

中文文档
14.1.1发布于 2023/07/14MITESM + CJS零依赖近 30 天下载 3075

A basic dialog component for react.

原始使用文档
文档目录8 节
  1. Quickstart
  2. Demo
  3. Functionalities
  4. Render
  5. Development
  6. Get started
  7. Testing
  8. Release

Quickstart

yarn add @depay/react-dialog

or

npm install --save @depay/react-dialog
import { ReactDialog } from '@depay/react-dialog'

  /*...*/

  close() {
    if(this.state == something) {
      this.setState({ showDialog: false })
    }
  }

  /*...*/

  <ReactDialog close={this.close} open={this.state.showDialog}>
    <div className="ReactDialogAnimation MyDialogStyle">
      <h1>I am a dialog</h1>
      <button onclick={this.close}>Close Dialog</button>
    </div>
  </ReactDialog>

Demo

https://depayfi.github.io/react-dialog/demo.html

Functionalities

Render

import { ReactDialog } from '@depay/react-dialog'

render() {
  return(
    ...
    <ReactDialog close={this.close} open={this.state.showDialog}>
      <div className="ReactDialogAnimation MyDialogStyle">
        <h1>I am a dialog</h1>
        <button onclick={this.close}>Close Dialog</button>
      </div>
    </ReactDialog>
  )
}

Please apply the ReactDialogAnimation class to the child element that you want to be animated as part of the dialog opening animation.

Props

close (function): A function living in the dialog parent that is called from the ReactDialog on a close attempt. The parent has to take care if a dialog is closable, and needs to set it's own state accordingly.

  close() {
    if(this.state == something) {
      this.setState({ showDialog: false })
    }
  }

  /*...*/

  <ReactDialog close={this.close} open={this.state.showDialog}>
    <h1>I am a dialog</h1>
    <button onclick={this.close}>Close Dialog</button>
  </ReactDialog>

background (string): Background passed as CSS to the ReactDialogBackground.

  <ReactDialog background={'rgba(255,255,255,0.6)'} close={this.close} open={this.state.showDialog}>
    <h1>I am a dialog with white background.</h1>
  </ReactDialog>

document (Document): Allows to forward a different document where the dialog is supposed to live in.


  <ReactDialog document={someIframe.document}>
    <h1>I am a dialog</h1>
    <button onclick={this.close}>Close Dialog</button>
  </ReactDialog>

container (HTMLElement): Allows to provide a explicit container where the dialog is supposed to be rendered into.


  <ReactDialog container={document.getElementById('app')}>
    <h1>I am a dialog</h1>
    <button onclick={this.close}>Close Dialog</button>
  </ReactDialog>

Development

Get started

yarn install
yarn start

Testing

Debug Cypress

Starts cypress in --headed and --no-exit

test:cypress:debug

Test and debug single cypress file:

yarn test:cypress:debug --spec "cypress/integration/close.js"

Release

npm publish

版本与发布记录

@depay/react-dialog 共发布 14 个版本,首次发布于 2021/11/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
14.1.1latest2023/07/143 年前
14.1.02023/07/143 年前
14.0.62023/05/263 年前
14.0.52023/05/263 年前
14.0.42023/05/263 年前
14.0.32022/10/264 年前

关于 @depay/react-dialog 的常见问题

@depay/react-dialog 是什么?

A basic dialog component for react.

如何安装 @depay/react-dialog?

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

@depay/react-dialog 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/depay__react-dialog 是否存在。

@depay/react-dialog 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@depay/react-dialog 需要什么版本的 Node.js?

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

@depay/react-dialog 可以商用吗?

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

@depay/react-dialog 的下载量有多少?

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

@depay/react-dialog 还在维护吗?

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