Pagination
Pagination with page navigation, next and previous links.
Installation
pnpm dlx cubix@latest add pagination --base radixUsage
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/cubix/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>Composition
Use the following composition to build a Pagination:
Pagination
└── PaginationContent
├── PaginationItem
│ └── PaginationPrevious
├── PaginationItem
│ └── PaginationLink
├── PaginationItem
│ └── PaginationEllipsis
└── PaginationItem
└── PaginationNextSimple
A simple pagination with only page numbers.
Icons Only
Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.
Next.js
By default PaginationLink renders an <a> tag. To use the Next.js Link component, update pagination.tsx to compose onto Link (Base UI render, Radix UI asChild).
import Link from "next/link"
// Base UI: compose PaginationLink onto Next.js Link via Button render
// Radix UI: use asChild on Button with a Link child
type PaginationLinkProps = {
isActive?: boolean
} & Pick<React.ComponentProps<typeof Button>, "size"> &
React.ComponentProps<typeof Link>
function PaginationLink({
className,
isActive,
size = "icon",
...props
}: PaginationLinkProps) {
return (
<Button
variant={isActive ? "outline" : "ghost"}
size={size}
className={cn(className)}
nativeButton={false}
render={
<Link
aria-current={isActive ? "page" : undefined}
data-slot="pagination-link"
data-active={isActive}
{...props}
/>
}
/>
)
}API Reference
Pagination
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Usually a PaginationContent of items and links. |
PaginationContent
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | PaginationItem elements that wrap links and controls. |
PaginationItem
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | A PaginationLink, PaginationPrevious, PaginationNext, or PaginationEllipsis. |
PaginationLink
| Prop | Type | Default | Description |
|---|---|---|---|
| isActive | boolean | false | Marks the link as the current page. |
| size | "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | "icon" | Button size variant applied to the link. |
| href | string | - | Destination URL for the page link. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | The page number or label shown in the link. |
PaginationPrevious / PaginationNext
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | "Previous" | "Next" | Visible label next to the chevron. Hidden below the sm breakpoint. |
| href | string | - | Destination URL for previous or next navigation. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
PaginationEllipsis
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |