1.0.0 • Published 11 months ago

@element-public/react-pagination v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Pagination

Description

Pagination is used for dividing content or data among several pages with control for navigation between pages, both backwards and forwards.

See live demos on storybook

Storybook Pagination Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-pagination @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Notes

Many important props exist for Pagination, as well as many methods for dictating how a user navigates information or data. Vital props include controlled, which disables internal state tracking in favor of programmatic control, directNavigation, which enables a Select list of pages for direct navigation, and initialPage, to set the current page on mount. Besides these props, totalItems and itemsPerPage are values that impact how a user navigates data by dictating how much data can be accessed at a time.

Usage

Pagination is used with large amounts of data, usually within a Table or other large data container.

Pagination Props

NameTypeDefaultRequiredDescription
controlledbooleanfalsefalseDisables internal state tracking in favor of programmatic control.
currentPagenumber0falseWhen using Pagination in controlled mode, this will set the currently selected data page.
directNavigationbooleanfalsefalseEnables a Select list of pages for direct navigation. If the number of pages is below the directNavigationThreshold, numbered buttons will displayed instead.
directNavigationThresholdnumber4falseWhen using directNavigation, this is number of pages above which a Select list of pages will be presented instead of number buttons.
disableNextPagebooleanfalsefalseWhen using Pagination in controlled mode, this controls enabled or disabled the next page button.
disablePreviousPagebooleanfalsefalseWhen using Pagination in controlled mode, this controls enabled or disabled the previous page button.
disabledbooleanfalsefalsePrevent the user from interacting with the component.
hideFirstLastbooleanfalsefalseHide the first and last buttons.
hideItemsPerPagebooleanfalsefalseHide the Items Per Page component.
hideNextPrevbooleanfalsefalseHide the next and previous buttons.
hideRowsPerPagebooleanfalsefalseHide the Rows Per Page component.
idstringundefinedfalseRandomly generated id. May be overwritten.
initialItemsPerPagenumber10falseSets item per page. Defaults to first index in itemsPerPageOptions array if value is not available array.
initialPagenumber0falseSets the current page on mount.
itemsPerPagenumberundefinedfalseSets item per page.
itemsPerPageOptionsnumber10, 25, 50, 100, 200falseNumber of items per page.
localizeFunctionnullfalseA customizable function to enable text translation services. Possible string values are 'Page', 'of', and 'Rows per page'.
selectPropsobjectundefinedfalseProps to be passed directly to the itemsPerPage and directNavigation Select components. May be used to override the opening direction or enable hoisting. See Select for a full list of props.
totalItemsnumber0falseTotal count of the total number of items to paginate through.
totalPagesnumber0falseWhen using Pagination in controlled mode, this will override the total number of pages.

Pagination Events

NameDefaultRequiredParamsDescription
onFirstPagenullfalseFired with the first page button is clicked.
onItemsPerPageChangenullfalseReturns item per page selected.
onLastPagenullfalseFired with the last page button is clicked. Returns the new page.
onNextPagenullfalseFired with the next page button is clicked. Returns the new page.
onPageChangenullfalseFired when any page change occurs. Returns the new page.
onPreviousPagenullfalseFired with the previous page button is clicked.