@10up/component-tabs

中文文档
2.0.1发布于 2022/03/10MITTypeScriptESM + CJS近 30 天下载 2556

Accessible tab component.

原始使用文档
文档目录12 节
  1. Installation
  2. NPM
  3. Standalone
  4. API
  5. Callbacks
  6. Usage
  7. Markup
  8. CSS
  9. JavaScript
  10. Demo
  11. Support Level
  12. Like what you see?

10up Tabs component

The tabs component is based on and extended from work done by the folks over at Simply Accessible. It is a stripped down, but still accessible version of UI tabs. They are keyboard accessible and user friendly and are meant to be a starting point for you to use on a project.

Installation

NPM

npm install --save @10up/component-tabs

Standalone

Clone this repo and import tabs.js and tabs.css from the dist/ directory.

API

This component accepts two arguments, the selector for the tab container and an object containing optional callbacks.

Callbacks

  • onCreate: Called after the tabs are initialized on page load
  • onTabChange: Called after a tab has been changed

Usage

Markup

This is the markup template expected by the component.

<div class="tabs">
    <div class="tab-control">
        <ul class="tab-list" role="tablist">
            <li class="tab-item"><button role="tab" aria-controls="js-tab1">View Tab 1</button></li>
            <li class="tab-item"><button role="tab" aria-controls="js-tab2">View Tab 2</button></li>
        </ul>
    </div>
    <div class="tab-group">
        <div class="tab-content" id="js-tab1" role="tabpanel">
            <h2>Tab 1 Content</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </div>
        <div class="tab-content" id="js-tab2" role="tabpanel">
            <h2>Tab 2 Content</h2>
            <p>In tincidunt tempor risus gravida tincidunt.</p>
        </div>
    </div>
</div>

CSS

The styles can be imported into your existing codebase by using PostCSS imports, or by including the standalone CSS file in your project.

PostCSS Imports

@import "@10up/component-tabs";

Standalone

Include the tabs.css file from the dist/ directory.

JavaScript

Create a new instance by supplying the selector to use for the tabs and an object containing any necessary callback functions.

NPM

import Tabs from '@10up/component-tabs';

new Tabs( '.tabs', {
    onCreate: function() {
        console.log( 'onCreate callback' );
    },
    onTabChange: function() {
        console.log( 'onTabChange callback' );
    }
} );

Standalone

<script src="unpkg.com/@10up/[email protected]/index.umd.js"></script>
let myTabs = new TenUp.tabs( '.tabs', {
    onCreate: function() {
        console.log( 'onCreate callback' );
    },
    onTabChange: function() {
        console.log( 'onTabChange callback' );
    }
} );

Demo

Example implementations can be found in the demo directory.

Support Level

Active: 10up is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome.

Like what you see?

Work with us at 10up

版本与发布记录

@10up/component-tabs 共发布 7 个版本,首次发布于 2018/11/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.1latest2022/03/104 年前
2.0.02021/04/215 年前
2.0.0-rc.1next2021/02/225 年前
1.0.32019/09/067 年前
1.0.22019/04/047 年前
1.0.12019/04/027 年前

关于 @10up/component-tabs 的常见问题

@10up/component-tabs 是什么?

Accessible tab component.

如何安装 @10up/component-tabs?

在项目目录运行 npm install @10up/component-tabs,或使用 pnpm add / yarn add / bun add。

@10up/component-tabs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@10up/component-tabs 支持 ESM 还是 CommonJS?

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

@10up/component-tabs 可以商用吗?

@10up/component-tabs 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@10up/component-tabs 的下载量有多少?

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

@10up/component-tabs 还在维护吗?

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