<nav class="icen-pagination" aria-label="分页"> <button class="icen-page-btn icen-motion is-disabled" aria-label="上一页"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M12.25 5.5 7.75 10l4.5 4.5"></path></svg></button> <button class="icen-page-btn icen-motion">1</button> <span class="icen-page-ellipsis">…</span> <button class="icen-page-btn icen-motion">4</button> <button class="icen-page-btn icen-motion is-active" aria-current="page">5</button> <button class="icen-page-btn icen-motion">6</button> <span class="icen-page-ellipsis">…</span> <button class="icen-page-btn icen-motion">12</button> <button class="icen-page-btn icen-motion" aria-label="下一页"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M7.75 5.5 12.25 10l-4.5 4.5"></path></svg></button></nav>
特性
- 结构:
icen-page-btn页码钮;is-active+aria-current="page"当前页;is-disabled禁用;icen-page-ellipsis省略号 - 职责:翻页逻辑归消费方,组件只管呈现
接口
- 初始化
initPagination()(kit 一行入口可直接命名导入)- 导出
-
initPagination共享行为模块,清单含族内导出 - 事件
-
icen:check-changeicen:page-changeicen:rating-changeicen:segmented-changeicen:sort-changeicen:step-changeicen:stepper-changeicen:switch-changedetail 契约见IcenEventMap;共享行为模块,清单含族内事件 - 类型
dist/behaviors/controls.d.mts(随 npm 包发布,含全部 JSDoc 约束)
安装
bun add @icen.ai/ui pnpm add @icen.ai/ui npm install @icen.ai/ui yarn add @icen.ai/ui 一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):
import '@icen.ai/ui/kit/pagination';import { initPagination } from '@icen.ai/ui';initPagination();
也可以用脚手架直接打印引入行:
bunx --bun @icen.ai/ui add pagination
Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/pagination.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。
用法
<nav class="icen-pagination" aria-label="分页"> <button class="icen-page-btn icen-motion is-disabled" aria-label="上一页"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M12.25 5.5 7.75 10l4.5 4.5"></path></svg></button> <button class="icen-page-btn icen-motion is-active" aria-current="page">1</button> <button class="icen-page-btn icen-motion" aria-label="下一页"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" focusable="false" class="icen-symbol" aria-hidden="true"><path d="M7.75 5.5 12.25 10l-4.5 4.5"></path></svg></button></nav>