Pagination
Moves between pages of a long list.
Partly measured from Palermo's Pagination arrows. Page numbers are derived from the ghost and secondary buttons.
import { Pagination } from "@replicas/ui";
import { useState } from "react";
export default function PaginationDemo() {
const [page, setPage] = useState(4);
return <Pagination page={page} pageCount={12} onPageChange={setPage} />;
}Prompt
Copy Prompt hands your agent everything it needs to build the Pagination in the Palermo style: the measured tokens, the CSS and the structure.
Show Prompt
# Palermo Pagination
Moves between pages of a long list.
Build a Pagination in this project that looks and behaves like Palermo's. Measured from the running Palermo app (palermo.tryprofound.com). Keep every value exact. Map the tokens onto the project's own theme variables instead of hard-coding them. Use the project's own component library for behaviour, or Base UI primitives if it has none.
Fidelity: Partly measured from Palermo's Pagination arrows. Page numbers are derived from the ghost and secondary buttons.
## Tokens
| Token | Light | Dark |
| --- | --- | --- |
| `--color-bg-secondary` | `#fafafa` | `#1e1d1c` |
| `--color-control-bg` | `#fff` | `#252423` |
| `--color-control-hover` | `#f5f5f5` | `#31302e` |
| `--color-control-hover-opacity` | `#0000000d` | `#d6d5d412` |
| `--text-primary` | `#18181a` | `#ecebe9` |
| `--text-secondary` | `#787878` | `#aaa8a5` |
| `--text-tertiary` | `#969696` | `#898784` |
| `--text-quaternary` | `#b4b4b4` | `#676563` |
| `--shadow-low` | `var(--surface-shadow-low), var(--shadow-border)` | `var(--surface-shadow-low), var(--shadow-border)` |
| `--focus-ring` | `#006bff` | `#006bff` |
| `--font-size-mini` | `0.75rem` | `0.75rem` |
| `--line-height-mini` | `16px` | `16px` |
| `--font-weight-medium` | `500` | `500` |
| `--radius-control` | `8px` | `8px` |
| `--ease-out` | `cubic-bezier(0, 0, 0.2, 1)` | `cubic-bezier(0, 0, 0.2, 1)` |
| `--duration-press` | `300ms` | `300ms` |
## CSS
Scoped under `[data-style="palermo"]`; dark rules sit under `[data-theme="dark"]`. The `ui-*` classes and data attributes match the structure below.
```css
[data-style="palermo"] {
.ui-pagination {
display: flex;
align-items: center;
gap: 4px;
}
.ui-pagination-button {
box-sizing: border-box;
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 24px;
height: 24px;
margin: 0;
padding: 0 6px;
border: none;
border-radius: var(--radius-control);
background-color: transparent;
color: var(--text-secondary);
font-family: inherit;
font-size: var(--font-size-mini);
font-weight: var(--font-weight-medium);
line-height: var(--line-height-mini);
font-variant-numeric: tabular-nums;
user-select: none;
cursor: pointer;
outline: none;
transition: scale var(--duration-press) var(--ease-out);
@media (hover: hover) {
&:hover:not(:disabled, [aria-current="page"]) {
background-color: var(--color-control-hover-opacity);
color: var(--text-primary);
}
}
&:active:not(:disabled) {
scale: 0.97;
}
&:focus-visible {
outline: 1px solid var(--focus-ring);
outline-offset: -1px;
}
& svg {
width: 14px;
height: 14px;
flex-shrink: 0;
}
}
.ui-pagination-button:is([aria-current="page"], [data-direction]) {
background-color: var(--color-control-bg);
box-shadow: var(--shadow-low);
color: var(--text-primary);
}
.ui-pagination-button[data-direction] {
padding: 5px;
@media (hover: hover) {
&:hover:not(:disabled) {
background-color: var(--color-control-hover);
}
}
&:disabled {
background-color: var(--color-bg-secondary);
box-shadow: none;
color: var(--text-quaternary);
cursor: not-allowed;
}
}
&[data-theme="dark"] .ui-pagination-button:is([aria-current="page"], [data-direction]):not(:disabled) {
background-color: var(--color-bg-secondary);
@media (hover: hover) {
&[data-direction]:hover {
background-color: var(--color-control-bg);
}
}
}
.ui-pagination-gap {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 24px;
height: 24px;
color: var(--text-tertiary);
font-size: var(--font-size-mini);
line-height: var(--line-height-mini);
user-select: none;
}
}
```
## Structure
How Replicas assembles it on Base UI.
```tsx
import type { ComponentProps } from "react";
import { join } from "./utils";
export type PaginationProps = Omit<ComponentProps<"nav">, "onChange"> & {
page: number;
pageCount: number;
onPageChange: (page: number) => void;
siblings?: number;
size?: string;
};
function range(page: number, count: number, siblings: number): (number | "gap")[] {
const pages = new Set([1, count]);
for (let i = page - siblings; i <= page + siblings; i++) if (i >= 1 && i <= count) pages.add(i);
const sorted = [...pages].sort((a, b) => a - b);
return sorted.flatMap((value, index) => (index > 0 && value - sorted[index - 1] > 1 ? ["gap" as const, value] : [value]));
}
const chevron = (d: string) => (
<svg viewBox="0 0 16 16" fill="none" aria-hidden>
<path d={d} stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
);
export function Pagination({ className, page, pageCount, onPageChange, siblings = 1, size, ...props }: PaginationProps) {
return (
<nav aria-label="Pagination" className={join("ui-pagination", className)} data-size={size} {...props}>
<button
type="button"
className="ui-pagination-button"
data-direction="previous"
aria-label="Previous page"
disabled={page <= 1}
onClick={() => onPageChange(page - 1)}
>
{chevron("M9.5 4l-4 4 4 4")}
</button>
{range(page, pageCount, siblings).map((item, index) =>
item === "gap" ? (
<span key={`gap-${index}`} className="ui-pagination-gap" aria-hidden>
…
</span>
) : (
<button
key={item}
type="button"
className="ui-pagination-button"
aria-label={`Page ${item}`}
aria-current={item === page ? "page" : undefined}
onClick={() => onPageChange(item)}
>
{item}
</button>
),
)}
<button
type="button"
className="ui-pagination-button"
data-direction="next"
aria-label="Next page"
disabled={page >= pageCount}
onClick={() => onPageChange(page + 1)}
>
{chevron("M6.5 4l4 4-4 4")}
</button>
</nav>
);
}
```
## Example
```tsx
import { Pagination } from "@replicas/ui";
import { useState } from "react";
export default function PaginationDemo() {
const [page, setPage] = useState(4);
return <Pagination page={page} pageCount={12} onPageChange={setPage} />;
}
```
## Foundations
The rest of the Palermo style, as a skill: https://replicas.raphaelsalaja.com/skills/palermo/SKILL.md