DocsBlog
  • 1.0.0

  • light

    dark

    system

    Switch mode
  • Cerberus

    Acheron

    Elysium

Get Started
Components
Data Grid
Styling
Theming

Concepts

OverviewCompositionCerberus ContextTesting

Layout

Aspect RatioBleedBoxCenterContainerDividerFlexFloatGridGroupNewLink OverlayScrollableStackWrap

Components

AccordionAdmonitionAvatarButtonCarouselCheckboxClipboardCollapsibleComboboxConfirm ModalCTAModalDate PickerDialogFieldFieldsetFile UploaderIcon ButtonInputLoading StatesMenuNotificationsNumber InputPaginationNewPin InputProgressPrompt ModalRadioRatingSelectSplit ButtonSwitchTableTabsTagTextTextareaToggleTooltip

Utilities

Client OnlyDownload TriggerEnvironmentFeature FlagsFocus TrapForFormat ByteFormat NumberFormat Relative TimeFrameHighlightJSON Tree ViewLocaleLocal StoragePortalPresenceShowsplitPropsTheme

Pagination

A navigation component that allows users to browse through pages.

  • npm
  • source
  • Ark
import { Pagination } from '@cerberus/react'

Usage

Used to navigate through a series of pages.

Attached

To change the layout style of the pagination, you can use the layout prop from the Group component.

Compact

To show a compact pagination style, use the compact prop. This can be useful for mobile.

Data Slicing

Use the slice() method to paginate actual data arrays. This method automatically slices your data based on the current page and page size.

Alignment

To align the pagination items, use the alignment props on a parent element. This will be differentdepending on the layout.

Controlled

Use the onPageChange prop to control the active page of the pagination.

Page Size

Control the number of items per page dynamically using setPageSize(). This example shows how to integrate a native select element to change the page size.

Note

For uncontrolled behavior, use defaultPageSize to set the initial value. For controlled behavior, use pageSize and onPageSizeChange to programmatically manage the page size.

Customization

You can utilize the css prop to customize the pagination by selecting the desired prmitive data-scope layers.

API

Primitives

Root Props:

PropTypeRequiredDescription
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.
countnumberNoTotal number of data items
defaultPagenumberNoThe initial active page when rendered.
Use when you don't need to control the active page of the pagination.
defaultPageSizenumberNoThe initial number of data items per page when rendered. Use when you don't need to control the page size of the pagination.
getPageUrl(details: PageUrlDetails) => stringNoFunction to generate href attributes for pagination links. Only used when type is set to "link".
idsPartial<PrimitiveLayers>NoThe ids of the elements in the accordion. Useful for composition.
onPageChange(details: PageChangeDetails) => voidNoCalled when the page number is changed
onPageSizeChange(details: PageSizeChangeDetails) => voidNoCalled when the page size is changed
pagenumberNoThe controlled active page
pageSizenumberNoThe controlled number of data items per page
siblingCountnumberNoNumber of pages to show beside active page
translationsIntlTranslationsNoSpecifies the localized strings that identifies the accessibility elements and their states
type'button', 'link'NoThe type of the trigger element

Ellipsis Props:

PropTypeRequiredDescription
indexnumberYes
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.

Item Props:

PropTypeRequiredDescription
type'page'Yes
valuenumberYes
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.

Item Data Attributes:

AttributeValue
[data-scope]pagination
[data-part]item
[data-index]The index of the item
[data-selected]Present when selected

NextTrigger Props:

PropTypeRequiredDescription
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.

NextTrigger Data Attributes:

AttributeValue
[data-scope]pagination
[data-part]next-trigger
[data-disabled]Present when disabled

PrevTrigger Props:

PropTypeRequiredDescription
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.

PrevTrigger Data Attributes:

AttributeValue
[data-scope]pagination
[data-part]prev-trigger
[data-disabled]Present when disabled

RootProvider Props:

PropTypeRequiredDescription
valueUsePaginationReturnYes
asChildbooleanNoUse the provided child element as the default rendered element, combining their props and behavior.

On this page

  • Edit this page on Github
Cerberus Design System | Docs
Copy
import { Pagination } from '@cerberus/react'

export function BasicDemo() {
  return <Pagination count={5000} pageSize={10} siblingCount={2} />
}
Copy
import { VStack } from 'styled-system/jsx'
import { Pagination } from '@cerberus/react'
import { DecorativeBox } from '@/app/components/decorative-box'

export function AlignmentDemo() {
  return (
    <VStack alignItems="flex-end" w="3/4">
      <DecorativeBox h="200px" />
      <Pagination count={5} pageSize={2} />
    </VStack>
  )
}
Copy
'use client'

import { Pagination } from '@cerberus/react'
import { useState } from 'react'

export function ControlledDemo() {
  const [currentPage, setCurrentPage] = useState<number>(1)

  return (
    <Pagination
      count={5000}
      onPageChange={(details) => setCurrentPage(details.page)}
      page={currentPage}
      pageSize={10}
      siblingCount={2}
    />
  )
}
Copy
'use client'

import {
  createSelectCollection,
  Field,
  For,
  Group,
  Option,
  Pagination,
  Select,
  type SelectValueChangeDetails,
  Text,
  usePaginationContext,
} from '@cerberus/react'
import { HStack, VStack } from 'styled-system/jsx'
import { users } from './users'

export function PageDemo() {
  return (
    <VStack textAlign="center" w="3/4">
      <Pagination count={20} defaultPageSize={2}>
        <HStack justify="flex-end" pb="md" w="full">
          <PageSize />
        </HStack>

        <UserList />
      </Pagination>
    </VStack>
  )
}

function PageSize() {
  const pagination = usePaginationContext()
  const collection = createSelectCollection([
    { label: '2', value: '2' },
    { label: '4', value: '4' },
    { label: '6', value: '6' },
    { label: '8', value: '8' },
    { label: '10', value: '10' },
  ])

  return (
    <HStack justify="flex-end" w="full">
      <Text as="small" color="page.text.100" textStyle="label-sm">
        Items per page:
      </Text>

      <Field label="Select page size" hideLabel w="initial">
        <Select
          collection={collection}
          onValueChange={(details: SelectValueChangeDetails) =>
            pagination.setPageSize(Number(details.value))
          }
          value={[String(pagination.pageSize)]}
          w="fit-content"
        >
          <For each={collection.items}>
            {(item) => <Option key={item.value} item={item} />}
          </For>
        </Select>
      </Field>
    </HStack>
  )
}

function UserList() {
  const pagination = usePaginationContext()
  return (
    <Group orientation="vertical" pb="lg" w="full">
      {pagination.slice(users).map((user) => (
        <HStack
          key={user.id}
          bgColor="page.bg.100"
          gap="md"
          p="md"
          rounded="sm"
          w="full"
        >
          <Text color="page.text.initial" textStyle="body-md">
            {user.name}
          </Text>
          <Text as="small" color="page.text.100" textStyle="label-sm">
            {user.email}
          </Text>
        </HStack>
      ))}
    </Group>
  )
}
Copy
'use client'

import {
  ItemList,
  PaginationParts,
  Text,
  type PaginationContextDetails,
} from '@cerberus/react'
import { HStack } from 'styled-system/jsx'

export function CustomDemo() {
  return (
    <PaginationParts.Root count={1000} pageSize={10} asChild>
      <HStack bgColor="page.bg.100" justify="space-between" p="md" w="full">
        <PaginationParts.Context>
          {(pagination: PaginationContextDetails) => (
            <>
              <Text as="small" textStyle="label-sm">
                {pagination.page} of {pagination.totalPages}
              </Text>

              <ItemList {...pagination} />
            </>
          )}
        </PaginationParts.Context>
      </HStack>
    </PaginationParts.Root>
  )
}
Copy
import { Pagination } from '@cerberus/react'

export function CompactDemo() {
  return <Pagination compact count={5000} pageSize={10} siblingCount={2} />
}
Copy
import { Pagination } from '@cerberus/react'

export function AttachedDemo() {
  return (
    <Pagination count={20} pageSize={2} defaultPage={1} layout="attached" />
  )
}
Copy
'use client'

import {
  Group,
  Pagination,
  Text,
  usePaginationContext,
} from '@cerberus/react'
import { HStack, VStack } from 'styled-system/jsx'
import { users } from './users'

export function SliceDemo() {
  return (
    <VStack textAlign="center" w="3/4">
      <Pagination count={users.length} pageSize={5}>
        <UserList />
      </Pagination>
    </VStack>
  )
}

function UserList() {
  const pagination = usePaginationContext()
  return (
    <Group orientation="vertical" pb="lg" w="full">
      {pagination.slice(users).map((user) => (
        <HStack
          key={user.id}
          bgColor="page.bg.100"
          gap="md"
          p="md"
          rounded="sm"
          w="full"
        >
          <Text color="page.text.initial" textStyle="body-md">
            {user.name}
          </Text>
          <Text as="small" color="page.text.100" textStyle="label-sm">
            {user.email}
          </Text>
        </HStack>
      ))}
    </Group>
  )
}
Items per page:
2
4
6
8
10

Emma Wilson

emma@example.com

Liam Johnson

liam@example.com
1 of 100

1 of 500

Emma Wilson

emma@example.com

Liam Johnson

liam@example.com

Olivia Brown

olivia@example.com

Noah Davis

noah@example.com

Ava Martinez

ava@example.com