Skip to content
Vy logo
  • Identitet
  • Spor
  • Resources
Components

Pagination

The Pagination component provides a user interface for navigating through a set of pages, typically used for displaying large datasets or splitting content into multiple pages.

FigmaGitHub

Examples

A basic pagination.

<Pagination count={20} pageSize={2} defaultPage={1}>
  <PaginationPrevTrigger />
  <PaginationItems />
  <PaginationNextTrigger />
</Pagination>

Controlled, using page and onPageChange

() => {
 const [page, setPage] = React.useState(1)
 return (
   <Pagination 
     count={20} 
     pageSize={2}
     page={page}
     onPageChange={(e) => setPage(e.page)}
    >
    <PaginationPrevTrigger />
    <PaginationItems />
    <PaginationNextTrigger />
  </Pagination>
 )
}

As link, using the getHref prop

<Pagination 
  count={20} 
  pageSize={2}
  defaultPage={3}
  getHref={(page) => `?page=${page}`}
>
  <PaginationPrevTrigger />
  <PaginationItems />
  <PaginationNextTrigger />
</Pagination>

Guidelines

When using the Pagination component, follow these guidelines for optimal usage:

  1. Provide an Accurate Page Count: Ensure that the count prop accurately reflects the total number of pages. This allows users to navigate efficiently through all available content.
  2. Define the Page Size: Use the pageSize prop to specify the number of items displayed per page. This helps maintain consistency in pagination behavior.
  3. Set a Default Page: The defaultPage prop determines which page is shown initially. Ensure this value aligns with your application’s expected user flow.
  4. Adjust Sibling Pages: The siblingCount prop controls how many page numbers are shown adjacent to the current page. Use this to balance usability and compactness.

Code

<Pagination />

import { Pagination } from "@vygruppen/spor-react";

Props

Name
Type
Required?
Description
countnumberTotal number of pages in the pagination.
defaultPagenumberThe currently selected page.
pageSizefunctionThe number of pages to spread the pages between
siblingCountnumber How many page numbers are shown adjacent to the current page.
pagenumberThe active page
onPageChangefunctionCalled when the page number is changed
onPageSizeChangefunctionCalled when the page size is changed
getHref(page: number) => string

<PaginationItem />

import { PaginationItem } from "@vygruppen/spor-react";

Props

Name
Type
Required?
Description
asstring

<PaginationPrevTrigger />

import { PaginationPrevTrigger } from "@vygruppen/spor-react";

<PaginationNextTrigger />

import { PaginationNextTrigger } from "@vygruppen/spor-react";