导航
Pagination
分页导航组件,用于在多页内容中切换
分页(Pagination)用于将大量数据拆分为多页展示,提供页码按钮、前后翻页、首尾跳转和省略号导航。支持多种样式变体、形状和尺寸。
import { Pagination } from '@skyroc/web-ui';
import type {
PaginationClassNames,
PaginationProps,
PaginationPages,
PaginationPageItem
} from '@skyroc/web-ui';何时使用
- 数据量较大需要分页展示时(表格、列表、搜索结果等)。
- 需要用户在页码之间快速导航时。
- 如果数据量不确定或需要无限滚动,优先使用虚拟列表。
基础用法
传入 total(总条数)和 itemsPerPage(每页条数),即可自动计算页数并渲染分页。
Preview
Code
Loading...
<Pagination
showEdges
total={200}
itemsPerPage={10}
siblingCount={1}
/>变体
通过 variant 切换选中页码的样式风格。
Preview
Code
Loading...
| 变体 | 说明 |
|---|---|
pure | 默认,选中时带边框和背景 |
solid | 选中时使用主色填充 |
outline | 选中时使用主色边框 |
soft | 选中时使用主色半透明背景 |
尺寸
通过 size 控制分页整体大小。
Preview
Code
Loading...
形状
通过 shape 切换按钮形状。
Preview
Code
Loading...
| 形状 | 说明 |
|---|---|
square | 默认,圆角矩形 |
rounded | 圆形按钮 |
显示边缘页码
showEdges 控制是否始终显示首页、尾页和省略号,避免用户迷失当前位置。
Preview
Code
Loading...
首尾按钮
showFirstLast 控制是否显示"跳到首页"和"跳到尾页"按钮,默认显示。
Preview
Code
Loading...
导航按钮选中态
actionAsSelected 为 true 时,前后翻页和首尾按钮也使用 variant 对应的选中样式。
Preview
Code
Loading...
受控模式
通过 page + onPageChange 实现受控分页。
Preview
Code
Loading...
const [page, setPage] = useState(1);
<Pagination
total={200}
itemsPerPage={10}
page={page}
onPageChange={setPage}
/>API
Pagination
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| total* | 数据总条数 | number | - |
| itemsPerPage | 每页条数 | number | 10 |
| page | 受控模式的当前页码 | number | - |
| defaultPage | 非受控模式的默认页码 | number | 1 |
| onPageChange | 页码变化时的回调 | (page: number) => void | - |
| siblingCount | 当前页两侧显示的兄弟页码数量 | number | 1 |
| showEdges | 是否始终显示首页、尾页和省略号 | boolean | false |
| showFirstLast | 是否显示"跳到首页/尾页"按钮 | boolean | true |
| variant | 选中页码的样式变体 | 'pure' | 'solid' | 'outline' | 'soft' | 'pure' |
| shape | 按钮形状 | 'square' | 'rounded' | 'square' |
| size | 尺寸,影响按钮大小和字号 | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'md' |
| disabled | 禁用所有交互 | boolean | false |
| actionAsSelected | 导航按钮是否使用 variant 对应的选中样式 | boolean | false |
| previousLabel | "上一页"按钮的文字标签,传 true 显示默认文字 | ReactNode | true | - |
| previousIcon | 自定义"上一页"按钮图标 | ReactNode | - |
| nextLabel | "下一页"按钮的文字标签,传 true 显示默认文字 | ReactNode | true | - |
| nextIcon | 自定义"下一页"按钮图标 | ReactNode | - |
| firstLabel | "首页"按钮的文字标签,传 true 显示默认文字 | ReactNode | true | - |
| firstIcon | 自定义"首页"按钮图标 | ReactNode | - |
| lastLabel | "尾页"按钮的文字标签,传 true 显示默认文字 | ReactNode | true | - |
| lastIcon | 自定义"尾页"按钮图标 | ReactNode | - |
| ellipsisIcon | 自定义省略号图标 | ReactNode | - |
| className | 根容器 class | ClassValue | - |
| classNames | 各 slot 的自定义 class | PaginationClassNames | - |
| contentProps | 透传给内容容器的属性 | PaginationContentProps | - |
| itemProps | 透传给页码按钮的属性 | PaginationItemProps | - |
| previousProps | 透传给"上一页"按钮的属性 | PaginationPreviousProps | - |
| nextProps | 透传给"下一页"按钮的属性 | PaginationNextProps | - |
| firstProps | 透传给"首页"按钮的属性 | PaginationFirstProps | - |
| lastProps | 透传给"尾页"按钮的属性 | PaginationLastProps | - |
| ellipsisProps | 透传给省略号组件的属性 | PaginationEllipsisProps | - |
子组件
基础子组件可用于更细粒度的自定义组合:
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| PaginationRoot | 导航根容器(nav 元素) | PaginationRootProps | - |
| PaginationContent | 内容容器,包裹所有按钮 | PaginationContentProps | - |
| PaginationItem | 页码按钮 | PaginationItemProps | - |
| PaginationPrevious | "上一页"按钮 | PaginationPreviousProps | - |
| PaginationNext | "下一页"按钮 | PaginationNextProps | - |
| PaginationFirst | "首页"按钮 | PaginationFirstProps | - |
| PaginationLast | "尾页"按钮 | PaginationLastProps | - |
| PaginationEllipsis | 省略号占位 | PaginationEllipsisProps | - |
类型
PaginationClassNames
Pagination 各 slot 的自定义 class 配置。
| 字段 | 类型 | 说明 |
|---|---|---|
| root | ClassValue | 根容器 class。 |
| list | ClassValue | 内容列表容器 class。 |
| button | ClassValue | 页码按钮 class。 |
| navigationButton | ClassValue | 导航按钮(前后翻页、首尾)class。 |
| ellipsis | ClassValue | 省略号 class。 |
PaginationContentProps
内容容器属性。继承 div 元素属性。
| 字段 | 类型 | 说明 |
|---|---|---|
| className | ClassValue | 容器 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationItemProps
页码按钮属性。继承 button 元素属性。
| 字段 | 类型 | 说明 |
|---|---|---|
| value* | number | 页码值。 |
| isActive | boolean | 是否为当前选中页。 |
| variant | 'pure' | 'solid' | 'outline' | 'soft' | 样式变体。 |
| shape | 'square' | 'rounded' | 按钮形状。 |
| className | ClassValue | 按钮 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationPreviousProps
"上一页"按钮属性。继承 PaginationNavigationButtonProps。
| 字段 | 类型 | 说明 |
|---|---|---|
| label | ReactNode | 按钮文字标签。 |
| icon | ReactNode | 自定义图标。 |
| actionAsSelected | boolean | 是否使用选中样式。 |
| variant | 'pure' | 'solid' | 'outline' | 'soft' | 样式变体。 |
| shape | 'square' | 'rounded' | 按钮形状。 |
| className | ClassValue | 按钮 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationNextProps
"下一页"按钮属性。继承 PaginationNavigationButtonProps。
| 字段 | 类型 | 说明 |
|---|---|---|
| label | ReactNode | 按钮文字标签。 |
| icon | ReactNode | 自定义图标。 |
| actionAsSelected | boolean | 是否使用选中样式。 |
| variant | 'pure' | 'solid' | 'outline' | 'soft' | 样式变体。 |
| shape | 'square' | 'rounded' | 按钮形状。 |
| className | ClassValue | 按钮 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationFirstProps
"首页"按钮属性。继承 PaginationNavigationButtonProps。
| 字段 | 类型 | 说明 |
|---|---|---|
| label | ReactNode | 按钮文字标签。 |
| icon | ReactNode | 自定义图标。 |
| actionAsSelected | boolean | 是否使用选中样式。 |
| variant | 'pure' | 'solid' | 'outline' | 'soft' | 样式变体。 |
| shape | 'square' | 'rounded' | 按钮形状。 |
| className | ClassValue | 按钮 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationLastProps
"尾页"按钮属性。继承 PaginationNavigationButtonProps。
| 字段 | 类型 | 说明 |
|---|---|---|
| label | ReactNode | 按钮文字标签。 |
| icon | ReactNode | 自定义图标。 |
| actionAsSelected | boolean | 是否使用选中样式。 |
| variant | 'pure' | 'solid' | 'outline' | 'soft' | 样式变体。 |
| shape | 'square' | 'rounded' | 按钮形状。 |
| className | ClassValue | 按钮 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationEllipsisProps
省略号组件属性。
| 字段 | 类型 | 说明 |
|---|---|---|
| icon | ReactNode | 自定义省略号图标。 |
| className | ClassValue | 省略号 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationRootProps
根容器属性。继承 nav 元素属性。
| 字段 | 类型 | 说明 |
|---|---|---|
| className | ClassValue | 根容器 class。 |
| size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 尺寸。 |
PaginationPageItem
分页项数据,页码或省略号。
| 字段 | 类型 | 说明 |
|---|---|---|
| type* | 'page' | 'ellipsis' | 项的类型。 |
| value | number | 页码值(仅 type 为 page 时存在)。 |