Socket
Socket
Sign inDemoInstall

@bazhe/pagination-wrapper

Package Overview
Dependencies
11
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @bazhe/pagination-wrapper

React Wrapper Component for handling your pagination


Version published
Weekly downloads
5
decreased by-28.57%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

@bazhe/pagination-wrapper

React Wrapper Component for handling your pagination

Playground/Demo: https://blagoj5.github.io/pagination/#playground
Full documentation: https://blagoj5.github.io/pagination

Getting Started

Prerequisites

You need to have react-dom and react above version 16

"react": ">=16.0.0",
"react-dom": ">=16.0.0"

Installing

npm

npm install @bazhe/pagination-wrapper

yarn

yarn add @bazhe/pagination-wrapper

Usage

Typescript usage example in: https://github.com/Blagoj5/pagination/blob/main/example/components/pagination-wrapper-demo.tsx

Import

import { Pagination } from '@bazhe/pagination-wrapper';

Initialization

Syntax: <Pagination paginationOptions={paginationOptions} render={WrappedComponent} />
or
Syntax: <Pagination
paginationOptions={paginationOptions}>
{(paginationResult) => (<WrappedComponent {...paginationResult} />)}
</Pagination>

Returns: PaginationResult as props to the wrapped component (if render method is used) or as the first argument in the children callback function


const Playground = (props) => {
    return <pre>{JSON.stringify(props.paginationResult, null, 2)}</pre>
}


const fakeData = [1, 2, 3]

export const PaginationWrapper = () => {
  // With children callback
  return (
    <Pagination paginationOptions={{ items: fakeData, limit: 2 }}>
      {props => <Playground {...props} />}
    </Pagination>
  );

  // Another example with callback
  return (<Pagination paginationOptions={{items: fakeData, limit: 2}}>
    {({nextPage, paginationResult, previousPage, setCurrentPage, setItems }) => {
      // do something with the data from above
      // ...
      return null; // return anything / JSX ... / string etc...
    }
  </Pagination>)

   //   With render prop
  return (
    <Pagination paginationOptions={{ items, limit: 2 }} render={Playground} />
  );
};

API

Props

NameTypeDescription
renderReact.ComponentType<PaginationResults<I & Props>>The wrapped component that will be rendered with the pagination result passed as props
childrenchildren?: (paginationData: PaginationResults<I & Props>) => anyThe wrapped component that will be rendered with the pagination result passed to props
propsanyParent props you want to pass when you are using render method for getting pagination result. It merges existing props with pagination result and passes them to the component provided in render
paginationOptionsPaginatorOptions<I>Options for handling the pagination logic
Pagination Options
NameTypeDefaultDescription
itemsT[] | undefined[]Initial items for the pagination
limitnumber | undefined4The limit of items per page
currentPagenumber | undefined1The current page
linksnumber | undefined10Links is the number of pages/links/buttons to display. Example: How many buttons you want to show in the pagination bar?
totalResultsnumber | undefineditems.lengthTotal results is the maximum number of items. Usually refers to items.length (so there's no need to pass it)

Pagination Result/Return

The pagination result passed to the children callback or the pagination props passed to the wrapped component (when using render prop):

  • paginationResult:
NameTypeDescription
itemsT[] | undefinedThe items that will change depending on the pagination (currentPage, limit ...)
all_itemsT[] | undefinedInitial/All items for the pagination
total_pagesnumber | undefinedThe total pages for the provided items. Example: 12 items with limit 2 -> 6 total pages
pagesnumberThe number of pages between range(first_page, last_page)
current_pagenumberCurrent page
first_pagenumberFirst page, depends on the link (buttons/links to display in the pagination bar) and limit (items per page)
last_pagenumberLast page, depends on the link (buttons/links to display in the pagination bar) and limit (items per page)
previous_pagenumberPrevious page, current_page - 1
next_pagenumberNext page, current_page + 1
has_previous_pageboolean
has_next_pageboolean
total_resultsnumberThe length of the initial items
resultsnumberResults per page
first_resultnumberFirst result is the index of the item that's first for the current page - items[first_result] (depends on link and limit)
last_resultnumberLast result is the index of the item that's last for the current page - items[last_result] (depends on link and limit)
limitnumberThe limit of items per page

  • Pagination handlers for managing state
NameTypeDescription
setCurrentPage(n: number) => voidFunction handler for changing the current page
setItems(items: T[]) => voidFunction handler for changing the items
setPageAndItems(payload: { items: I[]; currentPage: number }) => voidFunction handler for changing current page and the items themselves
nextPage() => voidFunction handler for changing to next page
previousPage() => voidFunction handler for changing to previous page

Built With

Depends on:

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Blagoj Petrov

Security

This project doesn’t have any security concerns.

License

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

Keywords

FAQs

Last updated on 16 May 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc