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 Ref<HTMLElement>
-
The
ref
type for this component.
PaginationProps
- pageCount * number
-
The total number of pages.
- paginatedElementId string
-
The
id
of the paginated element. You must provide this prop when pagination controls a subsection of the page (for example, a data table). - currentPage number
-
The current page number (controlled). Should be between
1
andpageCount
. - defaultPage number
-
The default page number (uncontrolled). Should be between
1
andpageCount
. - onPageChange (page: number) => void
-
A callback function that is called when the page number changes.
- href (page: number) => string
-
A function that returns a URL for a given page number.
- id string
-
The element's unique identifier. See MDN.
- data-cim-style-root boolean
-
Use this attribute to "claim" the component tree for exclusive Cimpress UI usage.
- UNSAFE_className string
-
Sets the CSS className for the element. Only use as a last resort. Use style props instead.
See styling guide.
- UNSAFE_style CSSProperties
-
Sets the CSS style for the element. Only use as a last resort. Use style props instead.
See styling guide.
- aria-label string
-
Defines a string value that labels the current element.
- aria-labelledby string
-
Identifies the element (or elements) that labels the current element.
- aria-describedby string
-
Identifies the element (or elements) that describes the object.
- aria-details string
-
Identifies the element (or elements) that provide a detailed, extended description for the object.
- routerOptions undefined
-
Options for the configured client side router.
- hrefLang string
-
Hints at the human language of the linked URL. SeeMDN.
- target HTMLAttributeAnchorTarget
-
The target window for the link. See MDN.
- rel string
-
The relationship between the linked resource and the current page. See MDN.
- download string | boolean
-
Causes the browser to download the linked URL. A string may be provided to suggest a file name. See MDN.
- ping string
-
A space-separated list of URLs to ping when the link is followed. See MDN.
- referrerPolicy HTMLAttributeReferrerPolicy
-
How much of the referrer to send when following the link. See MDN.
StyleProps
- margin Responsive<Spacing | "auto">
-
The amount of margin applied to all edges of this component.
- marginX Responsive<Spacing | "auto">
-
The amount of margin applied to the left and right edges of this component. Takes priority over
margin
. - marginY Responsive<Spacing | "auto">
-
The amount of margin applied to the top and bottom edges of this component. Takes priority over
margin
. - marginTop Responsive<Spacing | "auto">
-
The amount of margin applied to the top edge of this component. Takes priority over
marginY
andmargin
. - marginRight Responsive<Spacing | "auto">
-
The amount of margin applied to the right edge of this component. Takes priority over
marginX
andmargin
. - marginBottom Responsive<Spacing | "auto">
-
The amount of margin applied to the bottom edge of this component. Takes priority over
marginY
andmargin
. - marginLeft Responsive<Spacing | "auto">
-
The amount of margin applied to the left edge of this component. Takes priority over
marginX
andmargin
.