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.
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:
- Provide an Accurate Page Count: Ensure that the
countprop accurately reflects the total number of pages. This allows users to navigate efficiently through all available content. - Define the Page Size: Use the
pageSizeprop to specify the number of items displayed per page. This helps maintain consistency in pagination behavior. - Set a Default Page: The
defaultPageprop determines which page is shown initially. Ensure this value aligns with your application’s expected user flow. - Adjust Sibling Pages: The
siblingCountprop 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 |
|---|---|---|---|
count | number | Total number of pages in the pagination. | |
defaultPage | number | The currently selected page. | |
pageSize | function | The number of pages to spread the pages between | |
siblingCount | number | How many page numbers are shown adjacent to the current page. | |
page | number | The active page | |
onPageChange | function | Called when the page number is changed | |
onPageSizeChange | function | Called when the page size is changed | |
getHref | (page: number) => string |
<PaginationItem />
import { PaginationItem } from "@vygruppen/spor-react";
Props
Name | Type | Required? | Description |
|---|---|---|---|
as | string |
<PaginationPrevTrigger />
import { PaginationPrevTrigger } from "@vygruppen/spor-react";
<PaginationNextTrigger />
import { PaginationNextTrigger } from "@vygruppen/spor-react";