Atrium // Components
Pager
A headless pagination element with slotted controls and CSS part styling.
A headless a-pager element that renders numbered page links and accepts your own prev/next controls as slots.
<script setup lang="ts">
import "@atrium-ui/elements/pager";
import { ref } from "vue";
import Button from "./Button.vue";
const props = defineProps<{
page?: number;
count?: number;
url?: string;
query?: string;
}>();
const emit = defineEmits<{
change: [e: CustomEvent<{ page: number; url: string }>];
}>();
const params = new URLSearchParams(location.search);
const pageParam = params.get("page");
const currentPage = ref(pageParam ? Number.parseInt(pageParam) : props.page);
function onPageChange(e: Event) {
const detail = (e as CustomEvent<{ page: number; url: string }>).detail;
currentPage.value = detail.page;
emit("change", e as CustomEvent<{ page: number; url: string }>);
}
</script>
<template>
<a-pager
class="pager-sv"
:page="currentPage"
:count="count ?? 1"
:url="url"
:query="query"
@change="onPageChange"
>
<Button slot="prev" variant="ghost" :disabled="currentPage <= 1">←</Button>
<Button slot="next" variant="ghost" :disabled="currentPage >= (count ?? 1)">→</Button>
</a-pager>
</template>
<style>
.pager-sv {
display: flex;
align-items: center;
gap: 8px;
}
.pager-sv::part(pages) {
display: flex;
align-items: center;
gap: 4px;
}
.pager-sv::part(page) {
box-sizing: border-box;
min-width: 2rem;
padding: calc(0.5rem - 1px) calc(1rem - 1px);
border-radius: 0.375rem;
border: 1px solid var(--color-gray-300);
background: transparent;
color: inherit;
font-size: inherit;
font-family: inherit;
text-align: center;
transition: background 100ms, color 100ms;
}
.pager-sv::part(page):hover {
background: var(--color-gray-100);
color: var(--color-gray-900);
}
.pager-sv::part(page active) {
background: var(--color-gray-900);
border-color: var(--color-gray-900);
color: white;
}
.pager-sv::part(ellipsis) {
min-width: 2rem;
text-align: center;
color: var(--color-gray-300);
}
</style> Example
Start on page 5 to see the ellipsis truncation in action. Click a number or the arrow buttons.
Many pages
Usage
<a-pager page="1" count="20" url="/results/{page}">
<button slot="prev">← Prev</button>
<button slot="next">Next →</button>
</a-pager>
Styling
Style page numbers via CSS shadow parts:
/* Layout */
a-pager::part(pages) {
display: flex;
align-items: center;
gap: 4px;
}
/* Individual page links */
a-pager::part(page) {
padding: 0.25rem 0.5rem;
border: 1px solid #ccc;
border-radius: 4px;
}
/* Active page */
a-pager::part(page active) {
background: blue;
color: white;
border-color: blue;
}
/* The "…" truncation spans */
a-pager::part(ellipsis) {
color: #999;
}
Disable the boundary controls with the at-start / at-end host attributes:
a-pager[at-start] [slot="prev"],
a-pager[at-end] [slot="next"] {
opacity: 0.4;
pointer-events: none;
}
Accessibility
- Page links use
aria-current="page"on the active item. - Prev/next controls retain their native semantics (button or anchor).
- The page number list is wrapped in
<nav aria-label="Pagination">.