Coder Social home page Coder Social logo

jasmo2 / material-ui-pagination Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lo-tp/material-ui-pagination

0.0 2.0 1.0 154 KB

An easy to use and customizable pagination component for material ui.

Home Page: http://blog.lotp.xyz/demo/material-ui-pagination/

License: MIT License

JavaScript 98.60% HTML 1.40%

material-ui-pagination's Introduction

material-ui-pagination

Build Status

An easy to use and customizable pagination component for material ui.

Play with this demo to see how it works.

Demonstration

Notice


Because some upstream modification about the click event made to the material-ui repo, I have to make some changes in response.

You can check what I have done in issue16.

  • Now for the newest version, you can install by npm install material-ui-pagination@next.
  • Otherwise go with the stable version by npm install mateiral-ui-pagination.

Quick Start


  • npm install material-ui-pagination
  • import Pagination from 'material-ui-pagination';

Usage


material-ui-pagination exposes one module called, Pagination, which accepts a few props:

Option Description
total Total number of pages
display Number of pages you want to show in the panel
current Current page selected
onChange Handles the change event of selected page: function(value: integer) => void
styleRoot Styles for root element
styleFirstPageLink Styles for FirstPageLink. If not provided, a NavigationFirstPage from Material UI will be rendered as default, otherwise <div> with styles will show up instead
styleLastPageLink Styles for LastPageLink. If not provided, a NavigationLastPage from Material UI will be rendered as default, otherwise <div> with styles will show up instead
styleButton Styles for page number button. If not provided, a FlatButton from Material UI will be rendered as default, otherwise <div> with styles will show up instead
stylePrimary Styles for active page element. Requires the styleButton

Run Local Demo


  • git clone https://github.com/lo-tp/material-ui-pagination
  • npm install
  • npm run dev-server
  • visit http://localhost:7890/

Run test


  • git clone https://github.com/lo-tp/material-ui-pagination
  • npm install
  • npm run test

Code Example


import React from 'react';
import ReactDOM from 'react-dom';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import injectTapEventPlugin from 'react-tap-event-plugin';
import Pagination from 'material-ui-pagination';

injectTapEventPlugin();

class App extends React.Component {
  constructor(props) {
    super(props);
    this.setTotal = this.setTotal.bind(this);
    this.setDisplay = this.setDisplay.bind(this);
    this.state = {
      total: 20,
      display: 7,
      number: 7,
    };
  }

  setTotal(event, total) {
    // eslint-disable-next-line no-param-reassign
    total = total.trim();
    if (total.match(/^\d*$/)) {
      if (total !== '') {
        // eslint-disable-next-line no-param-reassign
        total = parseInt(total, 10);
      } else {
        // eslint-disable-next-line no-param-reassign
        total = 0;
      }

      this.setState({ total });
    }
  }

  setDisplay(event, display) {
    // eslint-disable-next-line no-param-reassign
    display = display.trim();
    if (display.match(/^\d*$/)) {
      if (display !== '') {
        // eslint-disable-next-line no-param-reassign
        display = parseInt(display, 10);
      } else {
        // eslint-disable-next-line no-param-reassign
        display = 0;
      }

      this.setState({ display });
    }
  }

  render() {
    return (
      <div
        style = { {
          width: 500,
          margin: '0 auto',
        } }
      >
        <h3 >
          Now you are at
          <em
            style = { { color: 'red' } }
          >
            {` ${this.state.number} ` }
          </em>
          page
        </h3>
        <Pagination
          total = { this.state.total }
          current = { this.state.number }
          display = { this.state.display }
          onChange = { number => this.setState({ number }) }
        />
      </div>
    );
  }
}

ReactDOM.render(
  <MuiThemeProvider >
    <App />
  </MuiThemeProvider>,
  document.getElementById('root')
);

material-ui-pagination's People

Contributors

benjavr avatar hawkeyepierce89 avatar jasmo2 avatar lo-tp avatar

Watchers

 avatar  avatar

Forkers

jonny5

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.