@anypoint-web-components/anypoint-tabs

中文文档
0.1.19发布于 2021/07/08Apache-2.0ESM + CJS近 30 天下载 3290

Accessible tabs styled for Material Design and Anypoint platform

原始使用文档
文档目录11 节
  1. Usage
  2. Installation
  3. In a HTML document
  4. In a LitElement
  5. Styles
  6. Scrollable tabs
  7. Fit container
  8. Dynamic content
  9. Development
  10. Running the demo locally
  11. Running the tests

Anypoint tabs

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

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

Tabs organize content across different screens, data sets, and other interactions.

Published on NPM

tests

Usage

Installation

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

In a HTML document

<script type="module" src="node_modules/@anypoint-web-components/anypoint-tabs/anypoint-tabs.js"></script>
<script type="module" src="node_modules/@anypoint-web-components/anypoint-tabs/anypoint-tab.js"></script>

<anypoint-tabs selected="1">
  <anypoint-tab>Tab one</anypoint-tab>
  <anypoint-tab>Tab two</anypoint-tab>
  <anypoint-tab>Tab three</anypoint-tab>
</anypoint-tabs>

In a LitElement

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

class SimpleElement extends ControlStateMixin(ButtonStateMixin(LitElement)) {
  render() {
    return html`
    <anypoint-tabs .selected="${this.selectedTab}" @selected-changed="${this._tabHandler}">
      <anypoint-tab>Tab one</anypoint-tab>
      <anypoint-tab>Tab two</anypoint-tab>
      <anypoint-tab>Tab three</anypoint-tab>
    </anypoint-tabs>
    `;
  }

  _tabHandler(e) {
    this.selectedTab = e.detail.value;
  }
}
window.customElements.define('simple-element', SimpleElement);

Styles

Anypoint tabs comes with 2 predefined styles:

  • Material - (default) - Material Design styled tabs
  • Compatibility To provide compatibility with Anypoint design

See Tabs documentation in Material Design documentation for principles and anatomy of tabs.

Scrollable tabs

When tabs takes more place than available then set scrollable property to enable scrolling.

<div class="width: 320px;">
  <anypoint-tabs selected="0" scrollable>
    <anypoint-tab>Tab one</anypoint-tab>
    <anypoint-tab>Tab two</anypoint-tab>
    <anypoint-tab>Tab three</anypoint-tab>
    <anypoint-tab>Tab four</anypoint-tab>
  </anypoint-tabs>
</div>

Fit container

When the fitContainer property is set the tabs expands to full width of the container.

<anypoint-tabs selected="0" fitContainer>
  <anypoint-tab>Tab one</anypoint-tab>
  <anypoint-tab>Tab two</anypoint-tab>
  <anypoint-tab>Tab three</anypoint-tab>
  <anypoint-tab>Tab four</anypoint-tab>
</anypoint-tabs>

Otherwise they stay aligned to left/right (depending on dir value)

Dynamic content

The tab resets when it's children changes.

Note that the tabs won't change the selection when children change. You need to handle this situation depending on your application context.

render() {
  return html`
  <anypoint-tabs>
    <anypoint-tab>Tab one</anypoint-tab>
    ${this.renderTwo ? html`<anypoint-tab>Tab two</anypoint-tab>` : ''}
    <anypoint-tab>Tab three</anypoint-tab>
  </anypoint-tabs>
  `;
}

Development

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

Running the demo locally

npm start

Running the tests

npm test

版本与发布记录

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

版本发布日期距今
0.1.19latest2021/07/085 年前
0.1.172021/05/225 年前
0.1.162021/05/055 年前
0.1.152021/04/245 年前
0.1.142021/04/205 年前
0.1.132021/03/035 年前

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

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

Accessible tabs styled for Material Design and Anypoint platform

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

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

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

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

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

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

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

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

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

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

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

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