npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ibrahimstudio/pagination

v1.0.3

Published

This package provides a customizable pagination component for React applications.

Downloads

265

Readme

@ibrahimstudio/pagination is a reusable React component designed to handle navigation across paginated datasets or views. It provides a highly customizable interface with support for boundary counts, sibling counts, ellipsis indicators, and various design options. This component ensures accessibility and responsiveness, making it suitable for modern web applications.

This documentation explains how to use the component, its available props, and examples to integrate it effectively.

Code by Ibrahim Space Studio, Design by Ibrahim Design Studio.

1. Features

  • Highly Customizable: Adjust spacing, colors, and styles to match your design system.
  • Accessible: The component uses semantic HTML and supports ARIA attributes.
  • Responsive: Works well on devices with varying screen sizes.
  • Minimal Dependencies: Lightweight and optimized for performance.
  • Ellipsis Support: Automatically manages long pagination ranges with ellipses.

2. Installation

You can install this package via npm:

npm i @ibrahimstudio/pagination

or via yarn:

yarn add @ibrahimstudio/pagination

3. Usage

Basic Example

To create a basic pagination component:

<Pagination ttlPages={10} currentPage={1} onChange={(page) => console.log(`Navigated to ${page}`)} />

This example initializes a pagination bar for 10 pages. The onChange callback logs the current page when the user navigates to a different page.

Adding Boundary and Sibling Counts

<Pagination ttlPages={10} currentPage={1} sibling={2} boundary={1} />

Here, the pagination displays up to two sibling pages around the current page and one boundary page at the start and end of the range. This setup reduces clutter in large datasets.

Using Custom Labels for Navigation Buttons

<Pagination prevcontent={<span>Previous</span>} nextcontent={<span>Next</span>} />

This example customizes the "Previous" and "Next" button labels using the prevcontent and nextcontent props.

Styling the Pagination

<Pagination radius="full" bcolor="blue" pcolor="white" scolor="gray" variant="hollow" />

This example demonstrates customizing the appearance of the pagination using design props like radius, bcolor (background color), pcolor (primary color), scolor (secondary color), and variant.

4. API

Pagination Props

| Attribute | Type | Required | Description | Depend To | Default | | ------------- | -------------------------------------- | -------- | -------------------------------------------------------------------------------------------------- | ------------------ | -------------------------------- | | id | string | Yes | A unique identifier for the pagination component. | - | '@ibrahimstudio/pagination' | | form | string | - | Specifies the form associated with the pagination buttons. | - | - | | currentPage | number | Yes | The currently active page. | - | 1 | | ttlPages | number | Yes | The total number of pages. | - | 1 | | sibling | number | - | Number of sibling pages to display on each side of the current page. | - | 1 | | boundary | number | - | Number of boundary pages to display at the beginning and end of the range. | - | 1 | | radius | 'none' 'sm' 'md' 'lg' 'full' | - | Defines the border-radius of the pagination buttons. | - | 'md' | | bcolor | string | - | Background color for pagination buttons. Can be a valid CSS color value or variable. | - | 'var(--theme-color-base)' | | pcolor | string | - | Primary color (e.g., text or active state) for pagination buttons. Can be a CSS color or variable. | - | 'var(--theme-color-primary)' | | scolor | string | - | Secondary color for hover or focus effects. Can be a CSS color or variable. | - | 'var(--theme-color-secondary)' | | variant | 'fill' 'hollow' | - | Specifies the visual style of the pagination buttons. | - | 'fill' | | prevcontent | React.ReactNode | - | Custom content for the "Previous" button. | - | <Chevron /> | | nextcontent | React.ReactNode | - | Custom content for the "Next" button. | - | <Chevron /> | | nospacing | boolean | - | If true, removes spacing between pagination buttons. | - | false | | noshadow | boolean | - | If true, disables shadow effects on the buttons. | - | false | | colorized | boolean | - | Applies color effects for the "hollow" variant. | variant='hollow' | false |

Pagination Event(s)

| Attribute | Type | Required | Description | Depend To | | ---------- | ---------------- | -------- | -------------------------------------------------------- | --------- | | onChange | (page) => void | Yes | Callback function triggered when a new page is selected. | - |

5. Contributing

Contributions are welcome! If you have any improvements, bug fixes, or features, feel free to open an issue or create a pull request on GitHub.

6. License

This project is licensed under the MIT License - see the LICENSE file for details.