@anypoint-web-components/anypoint-dialog

中文文档
0.1.10发布于 2021/09/28Apache-2.0ESM + CJS近 30 天下载 3175

A Material design dialog with compatibility with Anypoint platform

原始使用文档
文档目录10 节
  1. Usage
  2. Installation
  3. In an html file
  4. In a LitElement
  5. Action buttons
  6. Scrollable content
  7. Modal dialog
  8. Development
  9. Running the demo locally
  10. Running the tests

anypoint-dialog

A material design dialog, also styled for Anypoint platform.

Anypoint web components are set of components that allows to build Anypoint enabled UI in open source projects.

Dialogs inform users about a task and can contain critical information, require decisions, or involve multiple tasks.

Published on NPM

tests

Usage

Installation

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

In an html file

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

In a LitElement

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);

Action buttons

Button with "dialog-dismiss" attribute will dismiss the dialog with "confirmed" property on a detail object of "overlay-closed" event set to false.

Button with "dialog-confirm" attribute will close the dialog with "confirmed" property on a detail object of "overlay-closed" event set to true.

Scrollable content

If the content of the dialog may exceed window size then use anypoint-dialog-scrollable as a content wrapper. It has additional logic to keep the content in place. Otherwise use regular div or paragraph.

Modal dialog

Set "modal" property to true to render the dialog over a scrim, with ESC button handler and mouse click disabled. The user can dismiss the dialog only by using dialog actions.

Development

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

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

@anypoint-web-components/anypoint-dialog 共发布 10 个版本,首次发布于 2019/09/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.10latest2021/09/285 年前
0.1.92021/03/315 年前
0.1.82021/03/225 年前
0.1.72021/02/065 年前
0.1.62020/10/126 年前
0.1.52020/10/116 年前

关于 @anypoint-web-components/anypoint-dialog 的常见问题

@anypoint-web-components/anypoint-dialog 是什么?

A Material design dialog with compatibility with Anypoint platform

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