Pagination
The Pagination component allows users to navigate through a series of content separated into discrete pages.
Installation
$ cbui-cli install @crossbuildui/pagination
cbui-cli
globally and authenticated your account. This will ensure you can access all the necessary features.Import
1import { Pagination } from '@/crossbuildui/pagination';
2import Icon from 'react-native-vector-icons/MaterialIcons'; // If using custom controls with icons
react-native-vector-icons
for its default control icons. Ensure this library is installed and linked in your React Native project if you plan to use the default icons or custom icons from this library.Basic Usage
Provide the total
number of pages and an optional initialPage
.
1<Pagination total={10} initialPage={1} />
Controlled vs. Uncontrolled
The Pagination can be uncontrolled using initialPage
or controlled using the page
prop along with an onChange
handler.
1const [currentPage, setCurrentPage] = useState(3);
2
3<Pagination
4 total={20}
5 page={currentPage}
6 onChange={setCurrentPage}
7/>
Variants & Colors
Pagination supports flat
(default), bordered
, light
, and faded
variants. The color
prop applies to the active item.
1// Flat (default)
2<Pagination total={7} color="primary" />
3
4// Bordered
5<Pagination total={7} variant="bordered" color="secondary" />
6
7// Light
8<Pagination total={7} variant="light" color="success" />
9
10// Faded
11<Pagination total={7} variant="faded" color="warning" />
Sizes
Adjust the size of pagination items using the size
prop: sm
, md
(default), and lg
.
1<Pagination total={5} size="sm" />
2<Pagination total={5} size="md" /> // Default
3<Pagination total={5} size="lg" />
Compact Mode
Use isCompact
for a more condensed pagination display, typically showing fewer page numbers.
1<Pagination total={15} isCompact />
2<Pagination total={15} isCompact showControls={false} />
Looping
Enable loop
to allow navigation from the last page to the first, and vice-versa.
1<Pagination total={5} initialPage={1} loop />
Custom Controls
Customize or hide the previous/next controls using prevControlContent
, nextControlContent
, and showControls
.
1<Pagination
2 total={8}
3 prevControlContent={<Icon name="arrow-back" size={20} />}
4 nextControlContent={<Icon name="arrow-forward" size={20} />}
5/>
6
7// Hiding controls
8<Pagination total={8} showControls={false} />
Dots Jump Behavior
The dotsJump
prop controls how many pages are skipped when an ellipsis (...) button is pressed.
1<Pagination total={25} initialPage={1} dotsJump={3} siblings={1} boundaries={1} />
2{/* Click '...' to jump 3 pages instead of default 5 */}
Siblings and Boundaries
Control the number of page numbers displayed around the current page (siblings
) and at the start/end (boundaries
) of the pagination list.
1<Pagination total={30} initialPage={15} siblings={2} boundaries={2} />
2{/* Shows 2 siblings on each side and 2 boundary pages at start/end */}
3
4<Pagination total={30} initialPage={15} siblings={0} boundaries={1} />
5{/* Shows only current page and 1 boundary page at start/end, with dots */}
Props Overview
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
total | number | - | The total number of pages. Required. |
variant | 'flat' | 'bordered' | 'light' | 'faded' | 'flat' | Visual style. |
color | ThemeColorName | 'primary' | Thematic color for active item. |
size | 'sm' | 'md' | 'lg' | 'md' | Size of items. |
radius | 'none' | 'sm' | 'md' | 'lg' | 'full' | 'md' | Border radius for items. |
dotsJump | number | 5 | Number of pages to jump on '...' click. |
initialPage | number | 1 | Initial page (uncontrolled). |
page | number | - | Current page (controlled). |
onChange | (page: number) => void | - | Callback on page change. |
siblings | number | 1 | Pages before/after current. |
boundaries | number | 1 | Pages at start/end. |
loop | boolean | false | Loop pagination. |
isCompact | boolean | false | Compact style. |
isDisabled | boolean | false | Disable pagination. |
showControls | boolean | true | Show prev/next controls. |
disableAnimation | boolean | false | Disable animation (not implemented). |
styles | PaginationSlotsStyles | - | Custom styles for internal slots (e.g., item , activeItem , wrapper ). |
style | StyleProp<ViewStyle> | - | Style for the outermost container. |
prevControlContent | ReactNode | Default Icon | Custom content for the "previous" control button. |
nextControlContent | ReactNode | Default Icon | Custom content for the "next" control button. |
Styling
Customize the appearance using:
style
prop onPagination
for the outermost container.styles
prop onPagination
for internal slots. Available slots are:base
: The main container view.wrapper
: The view wrapping all items (pages, dots, controls).item
: Each individual page number item (Pressable).itemText
: Text inside each page number item.activeItem
: The currently active page number item.activeItemText
: Text inside the active page number item.dotsItem
: The ellipsis (...) item.dotsItemText
: Text inside the ellipsis item.controlItem
: The previous/next control buttons.controlItemContent
: Style for icon/text inside control buttons (not directly stylable if custom ReactNode is provided).
1<Pagination
2 total={10}
3 style={{ marginVertical: 20, paddingHorizontal: 10 }} // Style for the outermost container
4 styles={{
5 base: { backgroundColor: '#e0e0e0', borderRadius: 12 },
6 wrapper: { gap: 8 }, // Custom gap between items
7 item: { borderWidth: 2, borderColor: 'blue' },
8 activeItem: { backgroundColor: 'green', borderColor: 'darkgreen' },
9 itemText: { color: 'black' },
10 activeItemText: { color: 'white', fontWeight: 'bold' },
11 controlItem: { backgroundColor: 'lightgray' },
12 dotsItem: { opacity: 0.7 }
13 }}
14/>
Accessibility
The Pagination
component is designed with accessibility in mind:
- The root view has
accessibilityRole="toolbar"
and anaccessibilityLabel
of "Pagination controls". - Each page item
Pressable
hasaccessibilityRole="button"
. - Page items include an
accessibilityLabel
indicating the page number and if it's the current page (e.g., "Go to page 5, current page"). - Dots items have an
accessibilityLabel
of "Jump pages". - Control buttons (previous/next) have appropriate
accessibilityLabel
s (e.g., "Previous page", "Next page"). accessibilityState
(selected, disabled) is applied to page items and controls.