PeakUI

Pagination

Page navigation with numbered links

Usage

import {Pagination} from "@peakui/react";

Anatomy

import {Pagination} from "@peakui/react";

export default () => (
  <Pagination>
    <Pagination.Summary>1 to 5 of 42</Pagination.Summary>
    <Pagination.Content>
      <Pagination.Item>
        <Pagination.Previous aria-label="Previous page">
          <Pagination.PreviousIcon />
        </Pagination.Previous>
      </Pagination.Item>
      <Pagination.Item>
        <Pagination.Link isActive>1</Pagination.Link>
      </Pagination.Item>
      <Pagination.Item>
        <Pagination.Ellipsis />
      </Pagination.Item>
      <Pagination.Item>
        <Pagination.Next aria-label="Next page">
          <Pagination.NextIcon />
        </Pagination.Next>
      </Pagination.Item>
    </Pagination.Content>
  </Pagination>
);

Examples

Sizes

With Summary

With Ellipsis

Controlled

isActive marks the current page; onPress on each link changes it.

Customization

Tailwind CSS

<Pagination className="justify-center">
  <Pagination.Content>
    <Pagination.Item>
      <Pagination.Link className="rounded-md" isActive>
        1
      </Pagination.Link>
    </Pagination.Item>
  </Pagination.Content>
</Pagination>

Global CSS

@layer components {
  .pagination__link {
    --pagination-link-radius: var(--radius-md);
  }

  .pagination__link[data-active="true"] {
    --pagination-link-bg: var(--color-accent);
    --pagination-link-fg: var(--color-accent-foreground);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Pagination component uses these CSS classes (view source styles):

Base & Size Classes

  • .pagination - Base container: summary and page list on one row
  • .pagination--sm - Small size
  • .pagination--md - Medium size (default)
  • .pagination--lg - Large size

Element Classes

  • .pagination__summary - The summary text
  • .pagination__content - The page list
  • .pagination__item - Each list item
  • .pagination__link - A page button
  • .pagination__link--nav - Previous and Next: wider, icon beside the label
  • .pagination__ellipsis - The gap between page ranges

Slots

  • [data-slot="pagination"] - The root <nav>
  • [data-slot="pagination-summary"] - The summary
  • [data-slot="pagination-content"] - The <ul>
  • [data-slot="pagination-item"] - Each <li>
  • [data-slot="pagination-link"] - A page button
  • [data-slot="pagination-previous"] - The Previous button
  • [data-slot="pagination-previous-icon"] - The Previous icon
  • [data-slot="pagination-next"] - The Next button
  • [data-slot="pagination-next-icon"] - The Next icon
  • [data-slot="pagination-ellipsis"] - The ellipsis

CSS Variables

VariablePurpose
--pagination-link-bgLink background color
--pagination-link-bg-hoverLink background color when hovered
--pagination-link-bg-pressedLink background color when pressed
--pagination-link-fgLink text and icon color
--pagination-link-borderLink border color
--pagination-link-radiusLink corner radius

Interactive States

The links support both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered]
  • Focus: :focus-visible or [data-focus-visible]
  • Pressed: :active or [data-pressed]
  • Active page: [data-active="true"] or [aria-current="page"]
  • Disabled: :disabled, [aria-disabled="true"] or [data-disabled]

API Reference

Pagination

PropTypeDefaultDescription
size'sm' | 'md' | 'lg''md'Size of the links, ellipsis and summary
childrenReactNode-The summary and the page list
classNamestring-Additional classes on the <nav>
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'nav'
...restJSX.IntrinsicElements[E]-aria-label defaults to "Pagination"; every other <nav> attribute is accepted

Pagination.Summary

PropTypeDefaultDescription
childrenReactNode-The summary text
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'div'
...restJSX.IntrinsicElements[E]-dir defaults to "auto"; every other <div> attribute is accepted

Pagination.Content

PropTypeDefaultDescription
childrenReactNode-The items
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'ul'
...restJSX.IntrinsicElements[E]-Every other <ul> attribute

Pagination.Item

PropTypeDefaultDescription
childrenReactNode-A link, Previous, Next or ellipsis
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'li'
...restJSX.IntrinsicElements[E]-Every other <li> attribute
PropTypeDefaultDescription
isActiveboolean-Marks the current page: sets aria-current="page" and data-active
isDisabledboolean-Whether the link is disabled
onPress(e: PressEvent) => void-Handler called when the link is pressed
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-The page label, or a function of the button's state
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the button's state
...restButtonProps-Every other React Aria Button prop

Pagination.Previous

PropTypeDefaultDescription
isDisabledboolean-Whether the button is disabled
onPress(e: PressEvent) => void-Handler called when the button is pressed
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Icon and label; pass aria-label when there is no text
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the button's state
...restButtonProps-Every other React Aria Button prop

Pagination.Next

PropTypeDefaultDescription
isDisabledboolean-Whether the button is disabled
onPress(e: PressEvent) => void-Handler called when the button is pressed
childrenReactNode | ((values: ButtonRenderProps) => ReactNode)-Label and icon; pass aria-label when there is no text
classNamestring | ((values: ButtonRenderProps) => string)-Additional classes, or a function of the button's state
...restButtonProps-Every other React Aria Button prop

Pagination.PreviousIcon

PropTypeDefaultDescription
childrenReactNodeleft chevronReplaces the default icon
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restJSX.IntrinsicElements[E]-Rendered with aria-hidden="true"; every other <span> attribute

Pagination.NextIcon

PropTypeDefaultDescription
childrenReactNoderight chevronReplaces the default icon
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restJSX.IntrinsicElements[E]-Rendered with aria-hidden="true"; every other <span> attribute

Pagination.Ellipsis

PropTypeDefaultDescription
classNamestring-Additional classes
renderDOMRenderFunction<E, undefined>-Replaces the rendered element; E defaults to 'span'
...restJSX.IntrinsicElements[E]-Rendered with aria-hidden="true"; every other <span> attribute

Render Props

PropTypeDescription
children(values: ButtonRenderProps) => ReactNodeOn Link, Previous and Next; receives isHovered, isPressed, isFocused, isFocusVisible, isDisabled
className(values: ButtonRenderProps) => stringSame values as children

On this page