The component can be imported via:
To use the component, at a minimum you'll need to pass in the following props:
page - the current page
totalItemCount - the total number of items across all pages
-1 to have the component
say "many" in the page count instead of the actual page countonPageChange and/or hrefBuilder
onPageChange is called when a page button is clicked, which
allows you to update the page statehrefBuilder, if provided, will be used to generate href
strings, to be used in the navigation buttons (which will be
a tags instead of button tags in this case)For a better navigation experience, it is recommended to use links instead of buttons with callbacks, especially if the page state is reflected as a URL query parameter.
By default, the pagination component will render buttons. However,
it accepts a hrefBuilder function for generating links instead.
hrefBuilder will be called with a page number argument, and should
return a URL string, or undefined (for example, when the total
count of elements is unknown - -1 - it's recommended to return
undefined from the hrefBuilder callback).
The links will be rendered using the link component defined on PlumaProvider, if present, so that routing libraries can be used.
By passing in onPageSizeChange, the component will render a dropdown with options
for changing the page size.
The onPageSizeChange callback will be called with the new page size when the user
selects a new option. It will show the current page size as the selected option. Additionally,
you can pass in a pageSizes prop to customize the options available. By default, the options
are [10, 25, 50, 100].
currentItemCountWhen totalItemCount is unknown (and -1 was passed in), the component
won't be able to determine the correct number of items on a page.
By default, the component will use the pageSize and page arguments to
calculate how many items fit on a page. However, on a "last page", chances
are there will be less items.
To tell the component how many items are actually present on the current page,
currentItemCount may be used:
Note: If currentItemCount is less than the pageSize, the component
assumes the current page is the last page (and will disable the "next"
and "last" page buttons accordingly).
This component supports continuation-based pagination, where the current page number is unknown, and it's only possible to page to the first, previous, next, or last page.
For these use cases, the page argument can be omitted. Additionally, the
hrefBuilder and onPageChange callbacks include a second argument, indicating
which page button was clicked. The value is a string, one of: first,
previous, next, or last. These can be used, instead of a page number,
to construct the "paged" link URLs, or update state in the callback.
The first argument to these callbacks, page, will be -1 in these cases.
PlumaPagination extends Box(Optional) The number of items on the current page.
When the total number of items is unknown (totalItemCount is -1), this
count will be used to display the count of items on the current page.
If provided, this function will be used to generate links for the
page navigation buttons. The buttons will be rendered as a tags,
and the strings returned by this function will be used as the href attribute.
If page is not provided to the component (continuation-based paging), the
first argument will be -1.
Whether the current page is the first page. Useful in continuation-based paging where the current page number is unknown.
Whether the current page is the last page. Useful in continuation-based paging where the current page number is unknown.
Called when a navigation button is clicked, with the new page number (if available), and the control that was clicked.
If page is not provided to the component (continuation-based paging), the
first argument will be -1.
When pagination is changed programmatically (not through a button click),
the control argument will be custom.
Called when the page size is changed, with the new page size.
The current page number.
Default:20
The size of the page (how many items per page).
This, along with totalItemCount, is used to calculate the total number of pages.
Default:[10, 20, 50, 100]
The page sizes to display in the page size selector.
The total number of items (if known).
This, along with pageSize, is used to calculate the total number of pages.
If a total is unknown, provide -1 to have the component reflect that in the page count.
Additional classes to apply to any of the navigation buttons.