Pagination API
Import
Section titled “Import”import { Pagination } from '@cimpress-ui/react';Controlled/uncontrolled usage
Section titled “Controlled/uncontrolled usage”This component can be used in a controlled or uncontrolled way.
In the controlled way, this component doesn’t maintain its own internal state, and its value is provided by the parent component. Use the controlled way when you need to be able to change the state of this component in other parts of your application.
In the uncontrolled way, this component maintains its own internal state, and can optionally notify the parent component when its internal state changes. Use the uncontrolled way when you don’t need to change the state of this component in other parts of your application.
Controlled
Uncontrolled
import { Pagination, Stack, Text } from '@cimpress-ui/react';import { useState } from 'react';
export default function Demo() { const [currentPage, setCurrentPage] = useState(3);
return ( <Stack gap={32}> <Stack gap={16}> <Text as="h2" variant="title-4"> Controlled </Text>
<Pagination aria-label="Pagination" pageCount={10} currentPage={currentPage} onPageChange={setCurrentPage} /> </Stack>
<Stack gap={16}> <Text as="h2" variant="title-4"> Uncontrolled </Text>
<Pagination aria-label="Pagination" pageCount={10} defaultPage={3} /> </Stack> </Stack> );}Accessibility notes
Section titled “Accessibility notes”Pagination renders a navigation landmark, and requires a textual label to identify itself to assistive technologies. See our accessibility guide for more details.
If pagination controls a subsection of the page (for example, a data table), paginatedElementId prop should be set to the id of the paginated element. This allows assistive technologies to understand the association between the paginated element and its pagination controls.
API reference
Section titled “API reference”Pagination
Section titled “Pagination”Allows navigating across multiple pages of related content.
- Ref<HTMLElement>
-
The
reftype for this component.
PaginationProps
- number
pageCount *
Section titled “ pageCount * ” -
The total number of pages.
- string
paginatedElementId
Section titled “ paginatedElementId ” -
The
idof the paginated element. You must provide this prop when pagination controls a subsection of the page (for example, a data table). - number
currentPage
Section titled “ currentPage ” -
The current page number (controlled). Should be between
1andpageCount. - number
defaultPage
Section titled “ defaultPage ” -
The default page number (uncontrolled). Should be between
1andpageCount. - (page: number) => void
onPageChange
Section titled “ onPageChange ” -
A callback function that is called when the page number changes.
- (page: number) => string
-
A function that returns a URL for a given page number.
- string
-
The element's unique identifier. See MDN.
- boolean
data-cim-style-root
Section titled “ data-cim-style-root ” -
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- string
UNSAFE_className
Section titled “ UNSAFE_className ” -
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- CSSProperties
UNSAFE_style
Section titled “ UNSAFE_style ” -
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- string
aria-label
Section titled “ aria-label ” -
Defines a string value that labels the current element.
- string
aria-labelledby
Section titled “ aria-labelledby ” -
Identifies the element (or elements) that labels the current element.
- string
aria-describedby
Section titled “ aria-describedby ” -
Identifies the element (or elements) that describes the object.
- string
aria-details
Section titled “ aria-details ” -
Identifies the element (or elements) that provide a detailed, extended description for the object.
- undefined
routerOptions
Section titled “ routerOptions ” -
Options for the configured client side router.
- string
hrefLang
Section titled “ hrefLang ” -
Hints at the human language of the linked URL. SeeMDN.
- HTMLAttributeAnchorTarget
target
Section titled “ target ” -
The target window for the link. See MDN.
- string
-
The relationship between the linked resource and the current page. See MDN.
- string | boolean
download
Section titled “ download ” -
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
- string
-
A space-separated list of URLs to ping when the link is followed. See MDN.
- HTMLAttributeReferrerPolicy
referrerPolicy
Section titled “ referrerPolicy ” -
How much of the referrer to send when following the link. See MDN.
StyleProps
- Responsive<Spacing | "auto">
margin
Section titled “ margin ” -
The amount of margin applied to all edges of this component.
- Responsive<Spacing | "auto">
marginX
Section titled “ marginX ” -
The amount of margin applied to the left and right edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginY
Section titled “ marginY ” -
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin. - Responsive<Spacing | "auto">
marginTop
Section titled “ marginTop ” -
The amount of margin applied to the top edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginRight
Section titled “ marginRight ” -
The amount of margin applied to the right edge of this component. Takes priority over
marginXandmargin. - Responsive<Spacing | "auto">
marginBottom
Section titled “ marginBottom ” -
The amount of margin applied to the bottom edge of this component. Takes priority over
marginYandmargin. - Responsive<Spacing | "auto">
marginLeft
Section titled “ marginLeft ” -
The amount of margin applied to the left edge of this component. Takes priority over
marginXandmargin.