@anypoint-web-components/anypoint-selector

中文文档
1.1.8发布于 2021/08/27Apache-2.0ESM + CJS近 30 天下载 3285

Port of iron-selector that works with ES6 classes. Manages a list of elements that can be selected.

原始使用文档
文档目录8 节
  1. <anypoint-selector>, AnypointSelectableMixin , AnypointMult…
  2. Usage
  3. Installation
  4. In an html file
  5. In a LitElement template
  6. Development
  7. Running the demo locally
  8. Running the tests

Published on NPM

Build Status

Published on webcomponents.org

anypoint-selector

This is a port of iron-selector that works with LitElement and ES6 classes, originally developed by Polymer team.

<anypoint-selector>, AnypointSelectableMixin, AnypointMultiSelectableMixin

anypoint-selector is an element which can be used to manage a list of elements that can be selected. Tapping on the item will make the item selected. The selected indicates which item is being selected. The default is to use the index of the item. anypoint-selector's functionality is entirely defined by AnypointMultiSelectableMixin.

AnypointSelectableMixin gives an element the concept of a selected child element. By default, the element will select one of its selectable children when a click event is dispatched to it.

AnypointSelectableMixin lets you ...

  • decide which children should be considered selectable (selectable),
  • retrieve the currently selected element (selectedItem) and all elements in the selectable set (items),
  • change the selection (select, selectNext, etc.),
  • decide how selected elements are modified to indicate their selected state (selectedClass, selectedAttribute),

... among other things.

AnypointMultiSelectableMixin includes all the features of AnypointSelectableMixin as well as a multi property, which can be set to true to indicate that the element can have multiple selected child elements. It also includes the selectedItems and selectedValues properties for working with arrays of selectable elements and their corresponding values (multi is true) - similar to the single-item versions provided by AnypointSelectableMixin: selectedItem and selected.

The element has no own shadow DOM. Items are rendered as is. The element also covers a case where the selector is used in another custom element and a <slot> is passed as a child (e.g. dropdown list wit children defined in light DOM).

Usage

Installation

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

In an html file

<html>
  <head>
    <script type="module">
      import '@anypoint-web-components/anypoint-selector/anypoint-selector.js';
    </script>
  </head>
  <body>
    <anypoint-selector selected="0">
      <div>Item 0</div>
      <div>Item 1</div>
      <div>Item 2</div>
      <div>Item 3</div>
      <div>Item 4</div>
    </anypoint-selector>
    <script>
    {
      document.querySelector('files-payload-editor').onselect = (e) => {
        console.log(e.detail.value);
      };
    }
    </script>
  </body>
</html>

In a LitElement template

import { LitElement, html } from 'lit-element';
import '@anypoint-web-components/anypoint-selector/anypoint-selector.js';

class SampleElement extends LitElement {
  render() {
    return html`
    <anypoint-selector @select="${this._selectedHandler}"></anypoint-selector>
    `;
  }

  _selectedHandler(e) {
    console.log('current selection:', e.detail.item);
  }
}
customElements.define('sample-element', SampleElement);

Development

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

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

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

版本发布日期距今
1.1.8latest2021/08/275 年前
1.1.72020/12/135 年前
1.1.62020/11/215 年前
1.1.52020/09/286 年前
1.1.32020/06/206 年前
1.1.22020/05/176 年前

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

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

Port of iron-selector that works with ES6 classes. Manages a list of elements that can be selected.

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

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

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

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

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

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

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

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

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

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

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

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