1.18.0 • Published 5 months ago

@asphalt-react/pagination v1.18.0

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
5 months ago

Pagination

Paginate long list of data split in different pages. There are controls to go to a particular page, or navigate to the next/previous page.

Pagination renders truncation icon if total number of pages is more than 10. The first and last pages are always visible.

It consists of 2 sub-components - PerPage and Records

Accessibility

  • Use tab or shift+tab to navigate among pages.

Usage

import React, { useState, useMemo } from "react"
import { Link } from "gatsby" // or any other router like react-router
import Pagination, { Records, PerPage } from "@asphalt-react/pagination"

function App() {
  const [active, setActive] = useState(1)

  const linkFunc = (num) => ({
    to: `/Hello?page=${num}`,
  })

  const pageChangeHandler = ({ page, event }) => {
    event.preventDefault()
    setActive(page)
  }

  return (
    <Pagination
      totalPages={totalPages}
      as={Link}
      getTagProps={linkFunc}
      active={active}
      onChange={pageChangeHandler}
    />
  )
}

Props

totalPages

Total number of available pages

typerequireddefault
numbertrueN/A

as

Name of the element to be used for each Pagination element

typerequireddefault
elementTypefalse"a"

getTagProps

function to generate props for props.as

typerequireddefault
funcfalseN/A

active

A number to determine the active page.

typerequireddefault
numberfalse1

onChange

Function to be called when page changes

onChange receives an object with the following signature

  • page - active page number
  • event - browser event
({page, event}) => void
typerequireddefault
funcfalseN/A

PerPage

Set number of records visible on each page.

Props

as

Name of the element to be used for each PerPage element

typerequireddefault
elementTypefalse"a"

perPage

Number of records per page

typerequireddefault
numberfalse10

getTagProps

function to generate props for props.as

typerequireddefault
funcfalseN/A

onChange

Function to be called when props.perPage value

onChange receives an object with the following signature

  • records - number of records to show per page
  • event - click event
 ({records, event}) => void
typerequireddefault
funcfalseN/A

Records

Displays the index of records shown in the current page along with total records.

Props

perPage

Number of records per page

typerequireddefault
numbertrueN/A

total

Number of total records

typerequireddefault
numbertrueN/A

active

Active page's number

typerequireddefault
numbertrueN/A

translate

Function to replace text with the preferred language

({start, end, total}) => string

start: starting index of the records shown in page

end: last index of the records shown in page

total: total records present

typerequireddefault
funcfalseN/A