1.1.0 • Published 5 years ago

react-mui-pagination v1.1.0

Weekly downloads
50
License
MIT
Repository
github
Last release
5 years ago

React Material UI Pagination

React material UI pagination is a react library that depends on MATERIAL-UI framework.

Jun-14-2019 12-48-42

Features

  • Supports rtl, you need to enable rtl for your theme, check material-ui documentation about this point
  • Customizable, since you can change styling, content, used components and number of visible links

Requirements

This library depends on both react version ^16.8.6 and material-ui 4.0.0, so please make sure that you have these minimum requirements before you install it.

Installation

npm i react-mui-pagination

Then import it where you need to use it

import Pagination from 'react-mui-pagination';

Then add your first component

const [page, setMyPage] = React.useState(1); // this an example using hooks
const setPage = (e, p) => {
  setMyPage(p);
}
return (
    <Pagination page={page} setPage={setPage} total={100} />
);

Here you are, your component is ready to use.

Customization

You have many options to customize links to different views

Set number of visible links

<Pagination numOfLinks={3} page={page} setPage={setPage} total={424} />
// or you can even hide them 
<Pagination numOfLinks={0} page={page} setPage={setPage} total={424} />

Hide previous/next buttons or first/last buttons

<Pagination hidePrevNext hideFirstLast 
page={page} setPage={setPage} total={424}   />

Use other material-ui styles

<Pagination
  linksShadow={4}
  linksColor='secondary'
  activeLinkColor='default'
  page={page} setPage={setPage} total={424} />

Use custom components/elements

<Pagination
  LinksComponent='a'
  linksProps={{ href: '#page-' + page }}
  activeProps={{ style: { fontWeight: 'bold' } }}
  page={page} setPage={setPage} total={424} />

Use custom content for buttons

// import this from material-ui
import Fab from '@material-ui/core/Fab';
// ...
<Pagination
  firstLastShadow={6}
  firstLastColor={'secondary'}
  FirstLastComponent={Fab} // we have used our imported component
  firstContent='FST'
  lastContent='LST'
  page={page} setPage={setPage} total={424} />

Reference

You can pass many properties to the component:

NameTypeDefaultDescription
total *intThe number of total results
pageint1The current active page
setPagefunctionto change the page state
perPageint10How many results each page can has
numOfLinksint5How many links to be visible
hidePrevNextbooleanfalseIf true previous and next buttons will be hidden
hideFirstLastbooleanfalseIf true first and last buttons will be hidden
linksShadowint0The pages' links' shadow
linksColorenum: 'default' , 'primary' , 'secondary', 'error''default'The pages' links color, these colors are depending on material-ui colors for Fab component since you have left the property LinksComponent to its default value
activeLinkColorenum: 'default' , 'primary' , 'secondary', 'error''primary'The active pages link color, this color are depending on material-ui colors for Fab component since you have left the property LinksComponent to its default value
LinksComponentelementTypeFabThe component used for the links' node. Either a string to use a DOM element or a component.
linksPropsobject{}Attributes to be applied to links components.
activePropsobject{}Attributes to be applied to active link component.
prevNextShadowint0The previous and next links' shadow
prevNextColorenum: 'default' , 'primary' , 'secondary', 'errorÎ''default'The previous and next links colors, these colors are depending on material-ui colors for IconButton component since you have left the property PrevNextComponent to its default value
PrevNextComponentelementTypeIconButtonThe component used for the previous and next links' node. Either a string to use a DOM element or a component.
prevNextPropsobject{}Attributes to be applied to previous and next links components.
nextPropsobject{}Attributes to be applied to next link component.
prevPropsobject{}Attributes to be applied to previous link component.
prevContentstring | elementTypeKeyboardArrowLeftThe content of previous link, note that this default content depends on theme dircetion, so it will be automaticlly set to KeyboardArrowRight in rtl. to set html elements you cannot use the tag name directly so instead of writing 'b' you should write {<b>some text</b>}
nextContentstring | elementTypeKeyboardArrowRightThe content of next link, note that this default content depends on theme dircetion, so it will be automaticlly set to KeyboardArrowLeft in rtl. . to set html elements you cannot use the tag name directly so instead of writing 'b' you should write {<b>some text</b>}
firstLastShadowint0The first and last links' shadow
firstLastColorenum: 'default' , 'primary' , 'secondary', 'errorÎ''default'The first and last liks colors, these colors are depending on material-ui colors for IconButton component since you have left the property FirstLastComponent to its default value
FirstLastComponentelementTypeIconButtonThe component used for the first and last links' node. Either a string to use a DOM element or a component.
firstLastPropsobject{}Attributes to be applied to first and last links' components.
firstPropsobject{}Attributes to be applied to first link component.
lastPropsobject{}Attributes to be applied to last link component.
firstContentstring | elementTypeFirstPageIconThe content of previous link, note that this default content depends on theme dircetion. to set html elements you cannot use the tag name directly so instead of writing 'b' you should write {<b>some text</b>}
lastContentstring | elementTypeLastPageIconThe content of next link, note that this default content depends on theme dircetion. . to set html elements you cannot use the tag name directly so instead of writing 'b' you should write {<b>some text</b>}