import {
Pagination,
PaginationContent,安装
🌐 Installation
pnpm dlx shadcn@latest add pagination
用法
🌐 Usage
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">3</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>示例
🌐 Examples
简单
🌐 Simple
一个只有页码的简单分页。
🌐 A simple pagination with only page numbers.
import {
Pagination,
PaginationContent,仅图标
🌐 Icons Only
仅使用上一个和下一个按钮,不使用页码。这对于带有每页行数选择器的数据表格很有用。
🌐 Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.
import { Field, FieldLabel } from "@/components/ui/field"
import {
Pagination,Next.js
默认情况下,<PaginationLink /> 组件将渲染一个 <a /> 标签。
🌐 By default the <PaginationLink /> component will render an <a /> tag.
要使用 Next.js <Link /> 组件,请对 pagination.tsx 进行以下更新。
🌐 To use the Next.js <Link /> component, make the following updates to pagination.tsx.
+ import Link from "next/link"
- type PaginationLinkProps = ... & React.ComponentProps<"a">
+ type PaginationLinkProps = ... & React.ComponentProps<typeof Link>
const PaginationLink = ({...props }: ) => (
<PaginationItem>
- <a>
+ <Link>
// ...
- </a>
+ </Link>
</PaginationItem>
)
注意: 我们正在更新 CLI,以便自动为你完成此操作。
从右到左
🌐 RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.
"use client"
import * as React from "react"更新日志
🌐 Changelog
右到左支持
🌐 RTL Support
如果你正在从先前版本的 Pagination 组件升级,你需要应用以下更新以添加 text 属性:
🌐 If you're upgrading from a previous version of the Pagination component, you'll need to apply the following updates to add the text prop:
更新 PaginationPrevious。
function PaginationPrevious({
className,
+ text = "Previous",
...props
- }: React.ComponentProps<typeof PaginationLink>) {
+ }: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to previous page"
size="default"
className={cn("cn-pagination-previous", className)}
{...props}
>
<ChevronLeftIcon />
<span className="cn-pagination-previous-text hidden sm:block">
- Previous
+ {text}
</span>
</PaginationLink>
)
}更新 PaginationNext。
function PaginationNext({
className,
+ text = "Next",
...props
- }: React.ComponentProps<typeof PaginationLink>) {
+ }: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to next page"
size="default"
className={cn("cn-pagination-next", className)}
{...props}
>
- <span className="cn-pagination-next-text hidden sm:block">Next</span>
+ <span className="cn-pagination-next-text hidden sm:block">{text}</span>
<ChevronRightIcon />
</PaginationLink>
)
}