mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-02 17:08:39 +00:00
* feat: add base and radix docs * feat: transform code for display * fix * fix * fix * fix * fix * chore: remove claude files * fix * fix * fix * chore: run format:write * fix * feat: add more examples * fix * feat: add aspect-ratio * feat: add avatar * feat: add badge * feat: add breadcrumb * fix * feat: add button * fix * fix * fix * feat: add calendar and card * feat: add carousel * fix: chart * feat: add checkbox * feat: add collapsible * feat: add combobox * feat: add command * feat: add context menu * feat: add data-table dialog and drawer * feat: dropdown-menu * feat: add date-picker * feat: add empty * feat: add field and hover-card * fix: input * feat: add input * feat: add input-group * feat: add input-otp * feat: add item * feat: add kbd and label * feat: add menubar * feat: add native-select * feat: add more components * feat: more components * feat: more components * feat: add skeleton, slider and sonner * feat: add spinner and switch * feat: add more components * fix: tabs * fix: tabs * feat: add docs for sidebar * fix * fix * fi * docs: update * fix: create page * fix * fix * chore: add changelog * fix
130 lines
2.6 KiB
Plaintext
130 lines
2.6 KiB
Plaintext
---
|
|
title: Pagination
|
|
description: Pagination with page navigation, next and previous links.
|
|
base: base
|
|
component: true
|
|
---
|
|
|
|
<ComponentPreview styleName="base-nova" name="pagination-demo" />
|
|
|
|
## Installation
|
|
|
|
<CodeTabs>
|
|
|
|
<TabsList>
|
|
<TabsTrigger value="cli">Command</TabsTrigger>
|
|
<TabsTrigger value="manual">Manual</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="cli">
|
|
|
|
```bash
|
|
npx shadcn@latest add pagination
|
|
```
|
|
|
|
</TabsContent>
|
|
|
|
<TabsContent value="manual">
|
|
|
|
<Steps className="mb-0 pt-2">
|
|
|
|
<Step>Copy and paste the following code into your project.</Step>
|
|
|
|
<ComponentSource
|
|
name="pagination"
|
|
title="components/ui/pagination.tsx"
|
|
styleName="base-nova"
|
|
/>
|
|
|
|
<Step>Update the import paths to match your project setup.</Step>
|
|
|
|
</Steps>
|
|
|
|
</TabsContent>
|
|
|
|
</CodeTabs>
|
|
|
|
## Usage
|
|
|
|
```tsx showLineNumbers
|
|
import {
|
|
Pagination,
|
|
PaginationContent,
|
|
PaginationEllipsis,
|
|
PaginationItem,
|
|
PaginationLink,
|
|
PaginationNext,
|
|
PaginationPrevious,
|
|
} from "@/components/ui/pagination"
|
|
```
|
|
|
|
```tsx showLineNumbers
|
|
<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.
|
|
|
|
<ComponentPreview styleName="base-nova" name="pagination-simple" />
|
|
|
|
### Icons Only
|
|
|
|
Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.
|
|
|
|
<ComponentPreview styleName="base-nova" name="pagination-icons-only" />
|
|
|
|
## Next.js
|
|
|
|
By default the `<PaginationLink />` component will render an `<a />` tag.
|
|
|
|
To use the Next.js `<Link />` component, make the following updates to `pagination.tsx`.
|
|
|
|
```diff showLineNumbers /typeof Link/ {1}
|
|
+ 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>
|
|
)
|
|
|
|
```
|
|
|
|
<Callout className="mt-6">
|
|
|
|
**Note:** We are making updates to the cli to automatically do this for you.
|
|
|
|
</Callout>
|