# @anypoint-web-components/anypoint-dialog 中文文档

规范地址：https://npmcn.com/package/%40anypoint-web-components/anypoint-dialog/

版本：0\.1\.10
npm 元数据更新时间：2026-04-07T19:25:17.711Z
中文译文更新时间：2026-11-06T12:57:42.861Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40anypoint-web-components/anypoint-dialog
原文对照：https://npmcn.com/package/%40anypoint-web-components/anypoint-dialog/?lang=original
项目主页：https://github.com/anypoint-web-components/anypoint-dialog#readme
源码仓库：https://github.com/anypoint-web-components/anypoint-dialog

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：43.2 kB，22 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：未声明
- 运行依赖：4 个
- 首次发布：2019-09-07T23:22:40.791Z
- 最新版本发布：2021-09-27T18:29:14.633Z
- 近 30 天下载量：3175（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：10（近 12 个月 0 个）

## 中文简介

与任意点平台兼容的材料设计对话框

## 安装

```sh
npm install @anypoint-web-components/anypoint-dialog
```

也可以使用：`pnpm add @anypoint-web-components/anypoint-dialog`、`yarn add @anypoint-web-components/anypoint-dialog`、`bun add @anypoint-web-components/anypoint-dialog`

## README

# 任意点对话框

一个材料设计对话框,同样为Anypoint平台所取名.

任意点网络组件是允许在开源项目中构建任意点启用的UI的组件集.

对话框将一项任务告知用户,可以包含关键信息,需要决策,或者涉及多个任务.

[![Published on NPM](https://img.shields.io/npm/v/@anypoint-web-components/anypoint-dialog.svg)](https://www.npmjs.com/package/@anypoint-web-components/anypoint-dialog)

[![tests](https://github.com/anypoint-web-components/anypoint-dialog/actions/workflows/tests.yml/badge.svg)](https://github.com/anypoint-web-components/anypoint-dialog/actions/workflows/tests.yml)

## 使用量

### 安装

```sh
npm install @anypoint-web-components/anypoint-dialog --save
```

### 在 html 文件内

```html
<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-dialog/anypoint-dialog.js';
      import '@anypoint-web-components/anypoint-dialog/anypoint-dialog-scrollable.js';
      import '@anypoint-web-components/anypoint-button/anypoint-button.js';
    </script>
  </head>
  <body>
    <anypoint-dialog>
      <h2>Dialog title</h2>
      <anypoint-dialog-scrollable>
        <p>Long content...</p>
      </anypoint-dialog-scrollable>
      <div class="buttons">
        <anypoint-button data-dialog-dismiss>Cancel</anypoint-button>
        <anypoint-button data-dialog-confirm autofocus>OK</anypoint-button>
      </div>
    </anypoint-dialog>
    <script>
    {
      document.querySelector('anypoint-dialog').addEventListener('overlay-closed', (e) => {
        console.log(e.detail.canceled); // only when outside click or ESC key press
        console.log(e.detail.confirmed); // true when "dialog-confirm" was pressed
      });
    }
    </script>
  </body>
</html>
```

### 在一个LitElement中

```js
import { LitElement, html } from 'lit-element';
import '@anypoint-web-components/anypoint-dialog/anypoint-dialog.js';
import '@anypoint-web-components/anypoint-dialog/anypoint-dialog-scrollable.js';
import '@anypoint-web-components/anypoint-button/anypoint-button.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <anypoint-dialog @overlay-closed="${this._dialogCloseHandler}">
      <h2>Dialog title</h2>
      <anypoint-dialog-scrollable>
        <p>Long content...</p>
      </anypoint-dialog-scrollable>
      <div class="buttons">
        <anypoint-button data-dialog-dismiss>Cancel</anypoint-button>
        <anypoint-button data-dialog-confirm autofocus>OK</anypoint-button>
      </div>
    </anypoint-dialog>
    `;
  }

  _dialogCloseHandler(e) {
    if (e.detail.confirmed) {
      // ...
    }
  }
}
customElements.define('sample-element', SampleElement);
```

### 动作按钮

带有"dialog-dispission"属性的按钮会解除被设定为虚假的"overlay-closed"事件的详细对象上带有"确认"属性的对话框.

有"dialog-confirm"属性的按钮会关闭对话框,在设定为真实的"overlay-closed"事件的详细对象上使用"confirmed"属性.

### 可滚动内容

如果对话框的内容可能超过窗口大小,则使用 `anypoint-dialog-scrollable` 作为内容包装. 它有额外的逻辑来保留内容. 否则则使用正版分录或段落.

### 模块对话框

设定“ 模式” 属性为 True 以在 scrim 上渲染对话框, ESC 按钮处理器和鼠标点击被禁用 . 用户只能使用对话框动作来解析对话框 .

## 发展

```sh
git clone https://github.com/anypoint-web-components/anypoint-dialog
cd anypoint-dialog
npm install
```

### 本地运行演示

```sh
npm start
```

### 运行测试

```sh
npm test
```

## 常见问题

### @anypoint-web-components/anypoint-dialog 是什么？

与任意点平台兼容的材料设计对话框

### 如何安装 @anypoint-web-components/anypoint-dialog？

在项目目录运行 npm install @anypoint-web-components/anypoint-dialog，或使用 pnpm add / yarn add / bun add。

### @anypoint-web-components/anypoint-dialog 支持 TypeScript 吗？

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

### @anypoint-web-components/anypoint-dialog 支持 ESM 还是 CommonJS？

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

### @anypoint-web-components/anypoint-dialog 可以商用吗？

@anypoint-web-components/anypoint-dialog 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @anypoint-web-components/anypoint-dialog 的下载量有多少？

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

### @anypoint-web-components/anypoint-dialog 还在维护吗？

最新版本 0\.1\.10 发布于 2021/09/28（5 年前）；至今共发布 10 个版本，其中过去 12 个月发布了 0 个；首次发布于 2019/09/08。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

