Pagination

The pagination component can be used to show a list of pages with numbers and links to allow the users to navigate through multiple pages, data from tables, and more.

Choose one of the examples below based on various styles and sizes and customize them using the React props API and the utility classes from Tailwind CSS.

You need to import the pagination component from the pol-ui library before using it:

import { Pagination } from "pol-ui";

Default pagination

Use the <Pagination> component to create a default pagination element and use the currentPage prop to set the currently active page, the totalPages prop to set how many pages there are in total and update the onPageChange even listener to set the state of the pagination component via React.

Default pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination currentPage={page} onPageChange={setPage} totalPages={100} />
  );
};
export default PaginationComponent;

Props

Pagination

Prop nameTypeDefaultDescription
classNamestringundefinedThe className to apply to the pagination component.
currentPagenumber1The current page number.
hasRangebooleantrueShow the range of pages.
hasLabelsbooleanfalseShow the labels.
labelsLabelsLabelsThe labels to show.
onPageChange(page: number) => voidundefinedThe event listener to handle the page change.
renderPaginationButton(props) => ReactNode<PaginationButton />The render prop to customize the pagination button.
showIconsbooleanfalseShow the icons.
themePaginationTheme {} The theme to apply to the pagination component.
totalPagesnumber1The total number of pages.
pageSizenumber5The number of pages to show.
outlinebooleanfalseShow the outline.
💡

You can also provide any prop comming from the HTML nav tag.

PaginationButton

Prop nameTypeDefaultDescription
activebooleanfalseThe active state of the button.
childrenReactNodeundefinedThe children to render.
onClick(event) => voidundefinedThe event listener to handle the click.
outlinebooleanfalseShow the outline.
themePaginationButtonThemeThe theme to apply to the pagination button.
💡

You can also provide any prop comming from the HTML button tag.

Examples

Pagination with icons

Add next and previous icons to the pagination component by passing theshowIcon` prop via React.

Default pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      showIcons={true}
    />
  );
};
export default PaginationComponent;

Show only the next and previous control buttons by passing the hasRange="false" prop from React.

Navigation pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      hasRange={false}
    />
  );
};
export default PaginationComponent;

Control button icons

Show the control buttons with icons by passing both the hasRange="false" and showIcons props.

Control button icons

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      hasRange={false}
      showIcons={true}
    />
  );
};
export default PaginationComponent;

Outline

If you want to show the pagination component with an outline, you can pass the outline prop.

Outline pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      outline={true}
    />
  );
};
export default PaginationComponent;

Table data navigation

Use this example show table data navigation by turning true the hasLabels prop.

Table data navigation

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      hasLabels={true}
    />
  );
};
export default PaginationComponent;

Table data navigation with icons

Show icons for the next and previous control buttons for table navigation by passing the showIcons prop.

Default pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      hasLabels={true}
      showIcons={true}
    />
  );
};
export default PaginationComponent;

Custom Labels

Customize the text for the next and previous buttons by passing a Labels object to the labels prop.

Default pagination

import { Pagination } from "pol-ui";
 
const PaginationComponent = () => {
  const [page, setPage] = useState(1);
 
  return (
    <Pagination
      currentPage={page}
      onPageChange={setPage}
      totalPages={100}
      hasLabels={true}
      labels={{
        entries: "dades",
        of: "de",
        showing: "Mostrant",
        to: "de",
        next: "Següent",
        previous: "Anterior",
      }}
    />
  );
};
export default PaginationComponent;

Theme

To learn more about how to customize the appearance of components, please see the Theme docs.

PaginationTheme

export interface PaginationTheme {
  base: string;
  layout: {
    table: {
      base: string;
      span: string;
    };
  };
  pages: {
    base: string;
    showIcon: string;
    previous: {
      base: string;
      icon: string;
    };
    next: {
      base: string;
      icon: string;
    };
    selector: {
      base: string;
      active: string;
      disabled: string;
    };
  };
}

Labels

interface Labels {
  next: string;
  previous: string;
  of: string;
  to: string;
  entries: string;
  showing: string;
}

Since February 21, 2024

Proudly Open Source
  • Npm

  • Github

  • Creator

  • Made with love and Pol-ui by Pol Gubau Amores