@anypoint-web-components/anypoint-item

中文文档
1.1.3发布于 2021/10/15Apache-2.0ESM + CJS近 30 天下载 3262

Anypoint list item

原始使用文档
文档目录9 节
  1. Styling options
  2. Usage
  3. Installation
  4. In an HTML file
  5. Styling
  6. Accessibility
  7. Development
  8. Running the demo locally
  9. Running the tests

Deprecated

This component has been moved to anypoint-web-components/awc.

====

This component is based on Material Design text field and adjusted for Anypoint platform components.

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

A list item to be used in menus and list views.

<anypoint-item>Item</anypoint-item>

tests

Published on NPM

Styling options

The element has two built-in themes:

  • Material Design - Default style
  • Anypoint Design - Enabled by adding legacy attribute to the elements.

OSS application should not use Anypoint based styling as it's protected by MuleSoft copyrights. This property is reserved for OSS applications embedded in the Anypoint platform.

Usage

Installation

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

In an HTML file

<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-item/anypoint-item.js';
    </script>
  </head>
  <body>
    <div role="listbox" slot="content">
      <anypoint-item>
        Option 1
      </anypoint-item>
      <anypoint-item>
        Option 2
      </anypoint-item>
      <anypoint-item>
        Option 3
      </anypoint-item>
      <anypoint-item>
        <p>Paragraph as a child</p>
      </anypoint-item>
    </div>
  </body>
</html>

Use this element with <anypoint-item-body> to make styled twoLine and threeLine items.

<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-item/anypoint-item.js';
      import '@anypoint-web-components/anypoint-item/anypoint-item-body.js';
    </script>
  </head>
  <body>
    <div role="listbox" slot="content">
      <anypoint-item-body twoline>
        <div>Show your status</div>
        <div secondary>Your status is visible to everyone</div>
      </anypoint-item-body>
      <iron-icon icon="warning"></iron-icon>
    </div>
  </body>
</html>

To use anypoint-item as a link, wrap it in an anchor tag. Since anypoint-item will already receive focus, you may want to prevent the anchor tag from receiving focus as well by setting its tabindex to -1.

<a href="https://domain.com/project" tabindex="-1">
  <anypoint-item raised>API Project</anypoint-item>
</a>

If you are concerned about performance and want to use anypoint-item in a anypoint-listbox with many items, you can just use a native button with the anypoint-item class applied (provided you have correctly included the shared styles):

import { LitElement, html, css } from 'lit-element';
import itemStyles from '@anypoint-web-components/anypoint-item/anypoint-item-shared-styles.js';

class SampleElement extends LitElement {
  get styles() {
    return [
      itemStyles,
      css`...`;
    ];
  }

  render() {
    return html`<style>${this.styles}</style>
    <anypoint-listbox>
      <button class="anypoint-item" role="option">Inbox</button>
      <button class="anypoint-item" role="option">Starred</button>
      <button class="anypoint-item" role="option">Sent mail</button>
    </anypoint-listbox>
    `;
  }
}
customElements.define('sample-element', SampleElement);

Styling

See anypoint-item-shared-styles.js for list of CSS variables.

Accessibility

This element has role="listitem" by default. Depending on usage, it may be more appropriate to set role="menuitem", role="menuitemcheckbox" or role="menuitemradio".

<anypoint-item role="menuitemcheckbox">
  <anypoint-item-body>
    Show your status
  </anypoint-item-body>
  <paper-checkbox></paper-checkbox>
</anypoint-item>

Development

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

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

@anypoint-web-components/anypoint-item 共发布 13 个版本,首次发布于 2019/06/23;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.3latest2021/10/155 年前
1.1.22021/05/315 年前
1.1.12021/05/195 年前
1.1.02021/01/305 年前
1.0.82020/09/226 年前
1.0.72020/05/296 年前

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

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

Anypoint list item

如何安装 @anypoint-web-components/anypoint-item?

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

@anypoint-web-components/anypoint-item 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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