@anypoint-web-components/anypoint-menu-button

中文文档
0.1.5发布于 2021/03/31Apache-2.0ESM + CJS近 30 天下载 3141

An icon button to trigger a dropdown menu

原始使用文档
文档目录7 节
  1. Usage
  2. Installation
  3. In an html file
  4. In a LitElement
  5. Development
  6. Running the demo locally
  7. Running the tests

Published on NPM

Build Status

anypoint-menu-button

A material design button that triggers a menu, also styled for Anypoint platform.

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

Menu button renders a trigger icon button which, once activated, renders a drodown menu. The button is to be used as a context action list.

Usage

Installation

npm install --save @anypoint-web-components/anypoint-menu-button

In an html file

<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-menu-button/anypoint-menu-button.js';
      import '@anypoint-web-components/anypoint-button/anypoint-icon-button.js';
      import '@anypoint-web-components/anypoint-listbox/anypoint-listbox.js';
      import '@anypoint-web-components/anypoint-item/anypoint-item.js';
      import '@polymer/iron-icons/iron-icons.js';
      import '@polymer/iron-icon/iron-icon.js';
    </script>
  </head>
  <body>
    <anypoint-menu-button>
      <anypoint-icon-button
        slot="dropdown-trigger"
        aria-label="activate for context menu">
        <iron-icon icon="menu" alt="menu"></iron-icon>
      </anypoint-icon-button>
      <anypoint-listbox slot="dropdown-content">
        <anypoint-item>alpha</anypoint-item>
        <anypoint-item>beta</anypoint-item>
        <anypoint-item>gamma</anypoint-item>
        <anypoint-item>delta</anypoint-item>
        <anypoint-item>epsilon</anypoint-item>
      </anypoint-listbox>
    </anypoint-menu-button>

    <script>
    {
      document.querySelector('anypoint-menu-button').onselect = () => {
        // an item is selected.
        // This is the same event dispatched by the `anypoint-listbox`
      };
    }
    </script>
  </body>
</html>

In a LitElement

import { LitElement, html } from 'lit-element';
import '@anypoint-web-components/anypoint-menu-button/anypoint-menu-button.js';
import '@anypoint-web-components/anypoint-button/anypoint-icon-button.js';
import '@anypoint-web-components/anypoint-listbox/anypoint-listbox.js';
import '@anypoint-web-components/anypoint-item/anypoint-item.js';
import '@polymer/iron-icons/iron-icons.js';
import '@polymer/iron-icon/iron-icon.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <anypoint-menu-button
      slot="content"
      ?compatibility="${compatibility}"
      ?disabled="${disabled}"
      ?ignoreSelect="${ignoreSelect}"
      ?noOverlap="${noOverlap}"
      ?closeOnActivate="${closeOnActivate}"
    >
      <anypoint-icon-button
        slot="dropdown-trigger"
        aria-label="activate for context menu"
        ?compatibility="${compatibility}">
        <iron-icon icon="menu" alt="menu"></iron-icon>
      </anypoint-icon-button>
      <anypoint-listbox
        slot="dropdown-content"
        ?compatibility="${compatibility}">
        <anypoint-item>alpha</anypoint-item>
        <anypoint-item>beta</anypoint-item>
        <anypoint-item>gamma</anypoint-item>
        <anypoint-item>delta</anypoint-item>
        <anypoint-item>epsilon</anypoint-item>
      </anypoint-listbox>
    </anypoint-menu-button>
    `;
  }
}
customElements.define('sample-element', SampleElement);

Development

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

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

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

版本发布日期距今
0.1.5latest2021/03/315 年前
0.1.42020/11/265 年前
0.1.32020/11/265 年前
0.1.22020/11/265 年前
0.1.12020/05/296 年前
0.1.02019/09/087 年前

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

@anypoint-web-components/anypoint-menu-button 是什么?

An icon button to trigger a dropdown menu

如何安装 @anypoint-web-components/anypoint-menu-button?

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

@anypoint-web-components/anypoint-menu-button 支持 TypeScript 吗?

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

@anypoint-web-components/anypoint-menu-button 支持 ESM 还是 CommonJS?

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

@anypoint-web-components/anypoint-menu-button 可以商用吗?

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

@anypoint-web-components/anypoint-menu-button 的下载量有多少?

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

@anypoint-web-components/anypoint-menu-button 还在维护吗?

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