Pagination

Pagination with page navigation, next and previous links.

Installation

pnpm dlx cubix@latest add pagination --base aria

Usage

Import
import {
  Pagination,
  PaginationContent,
  PaginationEllipsis,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious,
} from "@/components/cubix/pagination"
Example
<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
        └── PaginationNext

Simple

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

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Usually a PaginationContent of items and links.

PaginationContent

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-PaginationItem elements that wrap links and controls.

PaginationItem

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-A PaginationLink, PaginationPrevious, PaginationNext, or PaginationEllipsis.

PaginationLink

PropTypeDefaultDescription
isActivebooleanfalseMarks 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.
hrefstring-Destination URL for the page link.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-The page number or label shown in the link.

PaginationPrevious / PaginationNext

PropTypeDefaultDescription
textstring"Previous" | "Next"Visible label next to the chevron. Hidden below the sm breakpoint.
hrefstring-Destination URL for previous or next navigation.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

PaginationEllipsis

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).