其它组件
基础用法
AI 时代的组件库
Pagination 完整案例
分页 Pagination采用分页控制单页内的信息数量,也可进行页面跳转。。
Tailwind 版本
edit js
CSS 版本
edit css
edit js
使用方法
1import { Select, IconCheckLine, IconCloseLine, IconDownLine, IconEmptyFill, } from '@t-headless-ui/react';
2
3<Pagination.Root
4 total={100}
5>
6 <Pagination.Total>
7 {(total, range) => (
8 <div>
9 {`${range[0]} - ${range[1]} of ${total} items`}
10 </div>
11 )}
12 </Pagination.Total>
13
14 <Pagination.Previous>
15 <IconLeftLine />
16 </Pagination.Previous>
17
18 <Pagination.StartItem>
19 {(page) => <span>{page}</span>}
20 </Pagination.StartItem>
21
22 <Pagination.StartEllipsis>
23 <IconMoreFill />
24 </Pagination.StartEllipsis>
25
26 <Pagination.Items>
27 {(page) => <span>{page}</span>}
28 </Pagination.Items>
29
30 <Pagination.EndEllipsis>
31 <IconMoreFill />
32 </Pagination.EndEllipsis>
33
34 <Pagination.EndItem>
35 {(page) => <span>{page}</span>}
36 </Pagination.EndItem>
37
38 <Pagination.Next>
39 <IconRightLine />
40 </Pagination.Next>
41
42 <div>
43 <span>Go to</span>
44 <Pagination.Jumper />
45 <span>Page</span>
46 </div>
47
48 <Pagination.Option>
49 {({ sizeOptions, pageSize, disabled, onPageSizeChange }) => (
50 // this is a select component to change page size
51 // you can find an example in Pagination demo page
52 <PageSizeSelect sizeOptions={sizeOptions} pageSize={pageSize} disabled={disabled} onPageSizeChange={onPageSizeChange} />
53 )}
54 </Pagination.Option>
55 </Pagination.Root>API
Pagination.Root Props
接口名: PaginationRootProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'style' | 'className' | 'onChange'>
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| style | CSSProperties | 分页器的样式 | - |
| className | string | 分页器的类名 | - |
| current | number | 当前页 | - |
| pageSize | number | 每页数据条数 | - |
| total | number | 数据总数 | 0 |
| defaultCurrent | number | 当前页默认值 | - |
| defaultPageSize | number | 默认每页数据条数 | - |
| disabled | boolean | 是否禁用 | - |
| hideOnSinglePage | boolean | 是否在只有一页的情况下隐藏 | - |
| sizeOptions | number[] | 每页可以显示数据条数 | [10, 20, 50] |
| bufferSize | number | `current` 页与 `...` 之间的页码个数 | 2 |
| onChange | (pageNumber: number, pageSize: number) => void | 变化时的回调 | - |
| onPageSizeChange | (size: number, current: number) => void | pageSize 变化时的回调 | - |
| pageSizeChangeResetCurrent | boolean | `pageSize` 改变的时候重置当前页码为 `1` | - |
Pagination.StartItem/EndItem/Items Props
接口名: PaginationItemProps
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| className | string | 分页项的类名 | - |
| style | CSSProperties | 分页项的样式 | - |
| children | ReactNode | ((page: number, { isActive, disabled }: { isActive: boolean; disabled: boolean; }) => ReactNode) | 分页项的内容 | - |
Pagination.Previous/Next Props
接口名: PaginationPageTurningProps
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| className | string | 分页项的类名 | - |
| style | CSSProperties | 分页项的样式 | - |
| children | ReactNode | 分页项的内容 | - |
Pagination.StartEllipsis/EndEllipsis Props
接口名: PaginationEllipsisProps
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| className | string | 分页项的类名 | - |
| style | CSSProperties | 分页项的样式 | - |
| children | ReactNode | 分页项的内容 | - |
Pagination.Option Props
接口名: PaginationOptionProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'style' | 'className'>
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| className | string | 分页项的类名 | - |
| style | CSSProperties | 分页项的样式 | - |
| children | ReactNode | (({ sizeOptions, pageSize, disabled, onPageSizeChange, }: { sizeOptions: number[]; pageSize: number; disabled: boolean; onPageSizeChange: (size: number, current: number) => void; }) => ReactNode) | 分页项的内容 | - |
Pagination.Jumper Props
接口名: PaginationJumperProps
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| showCurrent | boolean | 是否显示当前页 | - |
| className | string | 分页项的类名 | - |
| style | CSSProperties | 分页项的样式 | - |
Pagination.Total Props
接口名: PaginationTotalProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children'>
| 参数名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| children | ReactNode | ((total: number, range: number[], allPages: number) => ReactNode) | 分页项的内容 | - |