Skip to content
Page

Pagination

Moves between pages of a long list.

import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationPrevious,
PaginationNext,
PaginationEllipsis,
} from "@pelagornis/page/components";

The preview above renders this file. Copy it into src/components/ to start from it.

src/components/PaginationExample.tsx
import { useState } from "react";
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@pelagornis/page/components";
const pages = [1, 2, 3];
export default function PaginationDemo() {
const [page, setPage] = useState(1);
return (
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious onClick={() => setPage((current) => Math.max(1, current - 1))} />
</PaginationItem>
{pages.map((item) => (
<PaginationItem key={item}>
<PaginationLink
href="#"
isActive={page === item}
onClick={(event) => {
event.preventDefault();
setPage(item);
}}
>
{item}
</PaginationLink>
</PaginationItem>
))}
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext onClick={() => setPage((current) => Math.min(3, current + 1))} />
</PaginationItem>
</PaginationContent>
</Pagination>
);
}

Pagination is composed from parts that share React state. Children written in MDX are rendered as separate islands, so the parts can’t reach each other. Put the composition in a .tsx file, like the example above, and import that file instead.

src/content/docs/example.mdx
---
title: Example
---
import PaginationExample from "../../components/PaginationExample";
<PaginationExample client:load />

client:load hydrates the island on page load. Use client:visible for content far down the page.

Markdoc tags render Astro components, and this one needs client state. Wrap the example in an .astro file that hydrates it, then register that file as a tag.

src/components/markdoc/PaginationExample.astro
---
import PaginationExample from "../PaginationExample";
---
<PaginationExample client:load />
markdoc.config.mjs
import { component, defineMarkdocConfig } from "@astrojs/markdoc/config";
import starlightMarkdoc from "@astrojs/starlight-markdoc";
import pageMarkdoc from "@pelagornis/page/markdoc";
export default defineMarkdocConfig({
extends: [starlightMarkdoc(), pageMarkdoc()],
tags: {
"pagination-example": {
render: component("./src/components/markdoc/PaginationExample.astro"),
selfClosing: true,
},
},
});
src/content/docs/example.mdoc
{% pagination-example /%}

Parts of the component and the data-refineui role each one renders.

PartRole
rootpagination

States the component styles. Component states are exposed as data attributes.

KindStates
Pseudofocus-visible

Keys the component handles when it has focus.

KeyAction
Enteractivate
Spaceactivate