Pagination

The Pagination component allows users to navigate through a series of content separated into discrete pages.

Installation

$ cbui-cli install @crossbuildui/pagination

Import

index.tsx
1import { Pagination } from '@/crossbuildui/pagination'; 2import Icon from 'react-native-vector-icons/MaterialIcons'; // If using custom controls with icons

Basic Usage

Provide the total number of pages and an optional initialPage.

index.tsx
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.

index.tsx
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.

index.tsx
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.

index.tsx
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.

index.tsx
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.

index.tsx
1<Pagination total={5} initialPage={1} loop />

Custom Controls

Customize or hide the previous/next controls using prevControlContent, nextControlContent, and showControls.

index.tsx
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.

index.tsx
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.

index.tsx
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

PROPTYPEDEFAULTDESCRIPTION
totalnumber-The total number of pages. Required.
variant'flat' | 'bordered' | 'light' | 'faded''flat'Visual style.
colorThemeColorName'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.
dotsJumpnumber5Number of pages to jump on '...' click.
initialPagenumber1Initial page (uncontrolled).
pagenumber-Current page (controlled).
onChange(page: number) => void-Callback on page change.
siblingsnumber1Pages before/after current.
boundariesnumber1Pages at start/end.
loopbooleanfalseLoop pagination.
isCompactbooleanfalseCompact style.
isDisabledbooleanfalseDisable pagination.
showControlsbooleantrueShow prev/next controls.
disableAnimationbooleanfalseDisable animation (not implemented).
stylesPaginationSlotsStyles-Custom styles for internal slots (e.g., item, activeItem, wrapper).
styleStyleProp<ViewStyle>-Style for the outermost container.
prevControlContentReactNodeDefault IconCustom content for the "previous" control button.
nextControlContentReactNodeDefault IconCustom content for the "next" control button.

Styling

Customize the appearance using:

  • style prop on Pagination for the outermost container.
  • styles prop on Pagination 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).
index.tsx
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 an accessibilityLabel of "Pagination controls".
  • Each page item Pressable has accessibilityRole="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 accessibilityLabels (e.g., "Previous page", "Next page").
  • accessibilityState (selected, disabled) is applied to page items and controls.