Back to Woocommerce

Pagination

packages/js/components/src/pagination/README.md

10.8.0-dev2.3 KB
Original Source

Pagination

Use Pagination to allow navigation between pages that represent a collection of items. The component allows for selecting a new page and items per page options.

You can also make use of the usePagination hook and the custom components:

  • PaginationPageArrowsWithPicker
  • PaginationPageArrows
  • PaginationPagePicker
  • PaginationPageSizePicker

Usage

jsx
<Pagination
	page={ 1 }
	perPage={ 10 }
	total={ 500 }
	onPageChange={ ( newPage ) => setState( { page: newPage } ) }
	onPerPageChange={ ( newPerPage ) => setState( { perPage: newPerPage } ) }
/>

Custom Example

jsx
const paginationProps = usePagination( {
	totalCount: 200,
	defaultPerPage: 25,
} );

return (
	<div>
		<div>
			Viewing { paginationProps.start }-{ paginationProps.end } of 200
			items
		</div>
		<PaginationPageArrowsWithPicker { ...paginationProps } />
		<PaginationPageSizePicker
			{ ...paginationProps }
			total={ 200 }
			perPageOptions={ [ 5, 10, 25 ] }
			label=""
		/>
	</div>
);

Props

NameTypeDefaultDescription
pageNumbernull(required) The current page of the collection
onPageChangeFunctionnoopA function to execute when the page is changed
perPageNumbernull(required) The amount of results that are being displayed per page
onPerPageChangeFunctionnoopA function to execute when the per page option is changed
totalNumbernull(required) The total number of results
classNameStringnullAdditional classNames
showPagePickerBooleantrueWhether the page picker should be shown.
showPerPagePickerBooleantrueWhether the per page picker should shown.
showPageArrowsLabelBooleantrueWhether the page arrows label should be shown.