Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nextjs-pagination

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nextjs-pagination

A customizable pagination component for Next.js

  • 2.6.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by175%
Maintainers
1
Weekly downloads
 
Created
Source

Nextjs-Pagination

Nextjs-Pagination is a powerful, customizable, and easy-to-use pagination component built specifically for Next.js projects. Designed with user experience in mind, it provides flexible configuration options so you can adjust the pagination behavior and look-and-feel to suit your needs. Nextjs-Pagination is built with TypeScript, offering type safety and autocompletion support in supported editors. Screenshot 2023-05-25 175609

Features

  • Customizable button color and shape
  • Set maximum number of page buttons to display
  • Option to show or hide 'Next' and 'Prev' buttons
  • Option to show or hide 'First' and 'Last' buttons
  • Callback function for page changes
  • Customizable text for 'First', 'Prev', 'Next', 'Last' buttons. You can use text, emojis, symbols, or anything that is a valid React node. Here are some examples:
    • Text: 'First', 'Prev', 'Next', 'Last'
    • Emojis: '⏮', '⏪', '⏩', '⏭'
    • Symbols: '⇤', '←', '→', '⇥'
    • Special Symbols: '⟪', '⟨', '⟩', '⟫'

Installation

Install the package using npm:

TypeScript

npm install nextjs-pagination

JavaScript

npm install nextjs-pagination

Usage

First, import the Pagination component from the nextjs-pagination package then use it in your components. Below are the 3 required props needed for JavaScript and TypeScript components:

TypeScript

import { Pagination } from 'nextjs-pagination';

const TSExample = () => {
  const handlePageChange = (page: number) => {
    setCurrentPage(page);
  };

  return (
    <Pagination
      onPageChange={handlePageChange}
      totalItems={100}
      itemsPerPage={10}
    />
  );
};

JavaScript

import Pagination from 'nextjs-pagination';

const JSExample = () => {
  const handlePageChange = (page) => {
    setCurrentPage(page);
  };

  return (
    <Pagination
      onPageChange={handlePageChange}
      totalItems={100}
      itemsPerPage={10}
    />
  );
};

This will render a pagination component for 100 items with 10 items per page.

API

Below are the props that you can pass to the Pagination component:

PropDescriptionTypeDefaultRequired
totalItemsTotal number of itemsnumber-Yes
itemsPerPageNumber of items per pagenumber-Yes
onPageChangeCallback function called when page changesfunction() => {}Yes
colorButton colorstring'#007bff'No
shapeButton shape ('circle' or 'square')string'square'No
buttonCountMaximum number of page buttonsnumber5No
showNextPrevWhether to show 'Next' and 'Prev' buttonsbooleanfalseNo
showFirstLastWhether to show 'First' and 'Last' buttonsbooleanfalseNo
onSuccessCallback function called when a valid page is selectedfunction() => {}No
onErrorCallback function called when an error occursfunction() => {}No
firstTextText for the 'First' button. Can be any valid React node, such as text, emojis, symbols, etc.React.ReactNode'First'No
lastTextText for the 'Last' button. Can be any valid React node, such as text, emojis, symbols, etc.React.ReactNode'Last'No
prevTextText for the 'Prev' button. Can be any valid React node, such as text, emojis, symbols, etc.React.ReactNode'Prev'No
nextTextText for the 'Next' button. Can be any valid React node, such as text, emojis, symbols, etc.React.ReactNode'Next'No

File Structure

  • @types/
    • nextjs-pagination.d.ts - TypeScript declaration file for the package.
  • dist/
    • index.js - Compiled JavaScript file of the package.
    • Pagination.js - Compiled JavaScript file of the package.
  • src/
    • index.ts - Entry point file of the package.
    • Pagination.tsx - The main implementation of the pagination component.
  • .babelrc - Babel configuration file.
  • jest.config.js - Jest configuration file.
  • package.json - Package metadata and dependency information.
  • tsconfig.json - TypeScript configuration file.

Examples

Want to see it in action? CLICK HERE! to check our the example on replit.

(please give it a few seconds to start up the server when you load)

TypeScript Example

import { Pagination } from 'nextjs-pagination';

const ExamplePage: React.FC = () => {
  const handlePageChange = (page: number) => {
    setCurrentPage(page);
  };

  return (
    <Pagination
      totalItems={500}
      itemsPerPage={20}
      onPageChange={handlePageChange}
      color="green"
      shape="circle"
      buttonCount={7}
      showNextPrev={true}
      showFirstLast={true}
      onSuccess={(page: number) => console.log("Current page: ", page)}
      onError={(error: Error) => console.error(error)}
      firstText="First"
      lastText="Last"
      prevText="Prev"
      nextText="Next"
    />
  );
};

JavaScript Example

import Pagination from 'nextjs-pagination';

const ExamplePage = () => {
  const handlePageChange = (page) => {
    setCurrentPage(page);
  };

  return (
    <Pagination
      totalItems={500}
      itemsPerPage={20}
      onPageChange={handlePageChange}
      color="green"
      shape="circle"
      buttonCount={7}
      showNextPrev={true}
      showFirstLast={true}
      onSuccess={(page) => console.log("Current page: ", page)}
      onError={(error) => console.error(error)}
      firstText="First"
      lastText="Last"
      prevText="Prev"
      nextText="Next"
    />
  );
};

Contributing

We welcome contributions! Whether it's a bug report, feature request, or a code contribution, we greatly appreciate all help to improve Nextjs-Pagination. For major changes, please open an issue first to discuss what you would like to change.

License

Nextjs-Pagination is MIT licensed.

Keywords

FAQs

Package last updated on 16 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc