@biem/ui

Pagination

Links that take users from one page of a long list to another.

A pagination links the pages of a list that is too long for one view. Users open a page by its number or move one page back or forward, and the outlined number shows them which page they are on.

Usage

pagination-default.tsx
import {
	Pagination,
	PaginationContent,
	PaginationItem,
	PaginationLink,
	PaginationNext,
	PaginationPrevious,
} from "@biem/ui/components/ui/pagination";

export function PaginationDefault() {
	return (
		<Pagination>
			<PaginationContent>
				<PaginationItem>
					<PaginationPrevious href="/inventory/transfers?page=1"/>
				</PaginationItem>
				<PaginationItem>
					<PaginationLink href="/inventory/transfers?page=1">1</PaginationLink>
				</PaginationItem>
				<PaginationItem>
					<PaginationLink href="/inventory/transfers?page=2" isActive>2</PaginationLink>
				</PaginationItem>
				<PaginationItem>
					<PaginationLink href="/inventory/transfers?page=3">3</PaginationLink>
				</PaginationItem>
				<PaginationItem>
					<PaginationNext href="/inventory/transfers?page=3"/>
				</PaginationItem>
			</PaginationContent>
		</Pagination>
	);
}

Examples

Extra Small

A list in a narrow side panel, such as the recent movements of one article, leaves little room for its pagination. Set to "xs" on the previous and next links and to "icon-xs" on the page numbers, size keeps the pagination at its most compact, so the list stays in the foreground.

Small

Cards and dialogs often hold a short list that users page through without leaving their task. In such a place, size set to "sm" on the previous and next links and "icon-sm" on the page numbers brings the pagination to the scale of a small button, so it fits in without drawing attention from the list.

Default Size

Most lists in the body of a page, such as all open purchase orders of a store, need no size of their own. Left without a size, the page numbers take "icon" and the previous and next links take "default", so pagination keeps one scale across every product.

Large

On a tablet in the store, users page through lists such as the open counting tasks with a finger. With size set to "lg" on the previous and next links and "icon-lg" on the page numbers, every link offers a larger target and is easier to hit.

With Ellipsis

Long lists can have more pages than a pagination can show at once. The ellipsis stands for the pages that are left out, so the pagination stays compact and users still see that further pages exist. Assistive technology skips it and announces only the links that users can follow.

Custom Text

Where a list follows an order of its own, such as the date of each entry, words that name this order guide users better than a plain step back or forward. Through text, the previous and next links carry those words. Since assistive technology keeps announcing the previous or next page whatever the text says, aria-label passes the same meaning on to users who rely on it.

Active Page

Before users choose another page, they need to know which page they are on. Marked with isActive, a page link shows them that place at once, and assistive technology announces it as the current page.

API Reference

Pagination

Pagination marks its links as navigation, labels them "pagination" for assistive technology, and centers them in the available width. It renders a nav and has no props of its own.

PaginationContent

PaginationContent holds the items in a row. It renders a ul and has no props of its own.

PaginationItem

PaginationItem holds one entry of the row: a page link, the previous link, the next link or the ellipsis. It renders an li and has no props of its own.

PropisActive
Typeboolean
Default–
DescriptionMarks the link as the page that users are on. The link gets an outline, and assistive technology announces it as the current page.
Propsize
Type"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg"
Default"icon"
DescriptionControls the dimensions and spacing of the link. "icon", "icon-xs", "icon-sm" and "icon-lg" make it square, which fits a page number.
Prophref
Typestring
Default–
DescriptionSets the address of the page that the link opens.

PaginationPrevious

Proptext
Typestring
Default"Previous"
DescriptionSets the label after the chevron. The label shows from the sm breakpoint up, and narrower viewports show only the chevron. Assistive technology announces the link as "Go to previous page" whatever the text, so set aria-label as well when the text says something else.
PropisActive
Typeboolean
Default–
DescriptionDraws the previous link with an outline and marks it as the current page for assistive technology. The previous link never opens the page that users are on, so a pagination leaves this prop unset.
Propsize
Type"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg"
Default"default"
DescriptionControls the dimensions and spacing of the previous link.
Prophref
Typestring
Default–
DescriptionSets the address of the page before the one that users are on.

PaginationNext

Proptext
Typestring
Default"Next"
DescriptionSets the label before the chevron. The label shows from the sm breakpoint up, and narrower viewports show only the chevron. Assistive technology announces the link as "Go to next page" whatever the text, so set aria-label as well when the text says something else.
PropisActive
Typeboolean
Default–
DescriptionDraws the next link with an outline and marks it as the current page for assistive technology. The next link never opens the page that users are on, so a pagination leaves this prop unset.
Propsize
Type"default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg"
Default"default"
DescriptionControls the dimensions and spacing of the next link.
Prophref
Typestring
Default–
DescriptionSets the address of the page after the one that users are on.

PaginationEllipsis

PaginationEllipsis stands for the pages that a shortened pagination leaves out. It renders a span with three dots, which assistive technology skips, and has no props of its own.