Pagination
VPagination selects a page with buttons or links. It supports truncated ranges.
Usage
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination } from 'vectis-ui'
const page = ref(1)
</script>
<template>
<VPagination v-model="page" :length="8" />
</template>Examples
Variants and tones
itemVariant styles other pages and controls. tone colours only the current page.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const variants = ['ghost', 'outline'] as const
const tones = ['accent', 'neutral', 'danger'] as const
const page = ref(3)
</script>
<template>
<div class="column">
<div v-for="variant in variants" :key="variant" class="row">
<VPagination
v-for="tone in tones"
:key="tone"
v-model="page"
:length="6"
:item-variant="variant"
:tone="tone"
:label="`${variant}, ${tone}`"
/>
<VTypography variant="caption" tone="muted">{{ variant }}</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-6);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>How the selection is drawn
selectedVariant styles the current page as solid, soft or ghost.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography, type PaginationSelectedVariant } from 'vectis-ui'
const variants: PaginationSelectedVariant[] = ['solid', 'soft', 'ghost']
const pages = ref<Record<string, number>>({ solid: 3, soft: 3, ghost: 3 })
</script>
<template>
<div class="column">
<div v-for="variant in variants" :key="variant" class="row">
<VTypography variant="caption" tone="muted">{{ variant }}</VTypography>
<VPagination
v-model="pages[variant]"
:length="6"
:selected-variant="variant"
item-variant="outline"
:label="`Pages, ${variant}`"
/>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
justify-items: start;
gap: var(--vectis-space-5);
}
.row {
display: grid;
justify-items: start;
gap: var(--vectis-space-2);
}
</style>Detached
detached separates the buttons. bordered adds dividers between joined buttons.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const joined = ref(3)
const detached = ref(3)
const bordered = ref(3)
</script>
<template>
<div class="column">
<div class="row">
<VPagination v-model="joined" :length="6" item-variant="outline" label="Joined pages" />
<VTypography variant="caption" tone="muted">Joined, the default</VTypography>
</div>
<div class="row">
<VPagination
v-model="detached"
:length="6"
detached
item-variant="outline"
label="Detached pages"
/>
<VTypography variant="caption" tone="muted">detached</VTypography>
</div>
<div class="row">
<VPagination
v-model="bordered"
:length="6"
bordered
item-variant="outline"
label="Bordered pages"
/>
<VTypography variant="caption" tone="muted">bordered</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Elevated
elevated adds a shadow to the row, or to each button when detached.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const joined = ref(3)
const detached = ref(3)
</script>
<template>
<div class="column">
<div class="row">
<VPagination
v-model="joined"
:length="6"
elevated
item-variant="outline"
label="Raised joined pages"
/>
<VTypography variant="caption" tone="muted">elevated</VTypography>
</div>
<div class="row">
<VPagination
v-model="detached"
:length="6"
elevated
detached
item-variant="outline"
label="Raised detached pages"
/>
<VTypography variant="caption" tone="muted">elevated, detached</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-6);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Sizes
size sets the button size.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const sizes = ['xs', 'sm', 'md', 'lg', 'xl'] as const
const page = ref(3)
</script>
<template>
<div class="column">
<div v-for="size in sizes" :key="size" class="row">
<VPagination
v-model="page"
:length="6"
:size="size"
item-variant="outline"
:label="`Pages, ${size}`"
/>
<VTypography variant="caption" tone="muted">{{ size }}</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-4);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Length
length is the total page count. Without totalVisible, all pages appear.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const short = ref(2)
const long = ref(7)
</script>
<template>
<div class="column">
<div class="row">
<VPagination v-model="short" :length="4" item-variant="outline" label="Four pages" />
<VTypography variant="caption" tone="muted">length 4</VTypography>
</div>
<div class="row">
<VPagination v-model="long" :length="12" item-variant="outline" label="Twelve pages" />
<VTypography variant="caption" tone="muted">length 12</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Total visible
totalVisible caps page and ellipsis slots. From five slots, the first and last pages remain visible. Below five, consecutive pages surround the current one, down to the current page alone. At zero, only the controls remain.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const page = ref(1)
</script>
<template>
<div class="column">
<div v-for="slots in [1, 3, 5, 7]" :key="slots" class="row">
<VPagination
v-model="page"
:length="20"
:total-visible="slots"
item-variant="outline"
:label="`Twenty pages in ${slots} slots`"
/>
<VTypography variant="caption" tone="muted">totalVisible {{ slots }}</VTypography>
</div>
<VTypography variant="body-sm" tone="muted">Page {{ page }} of 20</VTypography>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Previous and next
controls selects icons, text, both or neither. Controls disable when no reachable page remains in their direction.
false, no controls at all
Icons and words of your own
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
import { arrow_left_alt as arrowLeftAlt, arrow_right_alt as arrowRightAlt } from 'vectis-ui/icons'
const DISPLAYS = [
{ value: 'icon', caption: 'icon, the default' },
{ value: 'text', caption: 'text' },
{ value: 'both', caption: 'both' },
{ value: false, caption: 'false, no controls at all' },
] as const
const page = ref(3)
</script>
<template>
<div class="column">
<div v-for="display in DISPLAYS" :key="String(display.value)" class="row">
<VPagination
v-model="page"
:length="6"
:controls="display.value"
item-variant="outline"
:label="`Pages, controls ${display.caption}`"
/>
<VTypography variant="caption" tone="muted">{{ display.caption }}</VTypography>
</div>
<div class="row">
<VPagination
v-model="page"
:length="6"
controls="both"
:prev-icon="arrowLeftAlt"
:next-icon="arrowRightAlt"
prev-text="Newer"
next-text="Older"
item-variant="outline"
label="Pages with wording of their own"
/>
<VTypography variant="caption" tone="muted">Icons and words of your own</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>First and last
edgeControls adds controls leading to the first and last reachable pages, displayed as controls specifies.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination } from 'vectis-ui'
const page = ref(5)
</script>
<template>
<div class="column">
<VPagination
v-model="page"
:length="20"
:total-visible="7"
edge-controls
item-variant="outline"
label="Pages with first and last controls"
/>
<VPagination
v-model="page"
:length="20"
:total-visible="7"
edge-controls
controls="both"
item-variant="outline"
label="Pages with first and last controls, with text"
/>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
</style>Unreachable pages
disabledPages accepts a page array or predicate. Controls skip those pages.
A predicate. Now on page 1
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const listed = ref(1)
const predicate = ref(1)
</script>
<template>
<div class="column">
<div class="row">
<VPagination
v-model="listed"
:length="10"
:disabled-pages="[2, 3, 4]"
controls="both"
item-variant="outline"
label="Pages 2 to 4 unavailable"
/>
<VTypography variant="caption" tone="muted">A list. Now on page {{ listed }}</VTypography>
</div>
<div class="row">
<VPagination
v-model="predicate"
:length="10"
:disabled-pages="(page) => page % 2 === 0"
controls="both"
item-variant="outline"
label="Even pages unavailable"
/>
<VTypography variant="caption" tone="muted">
A predicate. Now on page {{ predicate }}
</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Links
Provide href to render links. Handle navigate and call preventDefault() for router navigation. Modified clicks preserve native link behaviour without updating the model.
Links to /app/products?page=3
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const page = ref(3)
const href = (n: number) => `/app/products?page=${n}`
// Cancel native navigation and pass the URL to your router.
function onNavigate(_n: number, event: MouseEvent) {
event.preventDefault()
}
</script>
<template>
<div class="row">
<VPagination
v-model="page"
:length="12"
:total-visible="7"
:href="href"
label="Products"
@navigate="onNavigate"
/>
<VTypography variant="caption" tone="muted">Links to {{ href(page) }}</VTypography>
</div>
</template>
<style scoped>
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>States
disabled disables the entire row.
The whole row switched off
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const page = ref(3)
const first = ref(1)
const last = ref(6)
</script>
<template>
<div class="column">
<div class="row">
<VPagination
v-model="page"
:length="6"
disabled
controls="both"
item-variant="outline"
label="Pages unavailable"
/>
<VTypography variant="caption" tone="muted">The whole row switched off</VTypography>
</div>
<div class="row">
<VPagination
v-model="first"
:length="6"
controls="both"
item-variant="outline"
label="On the first page"
/>
<VTypography variant="caption" tone="muted">On the first page</VTypography>
</div>
<div class="row">
<VPagination
v-model="last"
:length="6"
controls="both"
item-variant="outline"
label="On the last page"
/>
<VTypography variant="caption" tone="muted">On the last page</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.row {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: var(--vectis-space-5);
}
</style>Alignment
align positions the row within the available width.
<script setup lang="ts">
import { ref } from 'vue'
import { VPagination, VTypography } from 'vectis-ui'
const aligns = ['start', 'center', 'end'] as const
const page = ref(3)
</script>
<template>
<div class="column">
<div v-for="align in aligns" :key="align" class="box">
<VPagination
v-model="page"
:length="6"
:align="align"
item-variant="outline"
:label="`Pages aligned ${align}`"
/>
<VTypography variant="caption" tone="muted">{{ align }}</VTypography>
</div>
</div>
</template>
<style scoped>
.column {
display: grid;
gap: var(--vectis-space-5);
}
.box {
display: grid;
gap: var(--vectis-space-2);
padding: var(--vectis-space-3);
border: 1px dashed var(--vectis-color-border);
border-radius: var(--vectis-radius-surface);
}
</style>API
Props
Events
Types
Types used in the API tables. Import exported types from vectis-ui.
export interface BuiltinIcon {
name: string
paths: readonly [string] | readonly [string, string]
}export type IconRender =
| { path: string; viewBox?: string }
| { component: Component; props?: Record<string, unknown> }
| { src: string }
| { text: string; class?: string }
| { class: string }export type IconSource = string | BuiltinIcon | IconRender