|
3 | 3 | [![Build Status][travis-image]][travis-url]<br /> |
4 | 4 | [![NPM version][npm-stats]][npm-url] |
5 | 5 |
|
6 | | -## TODO |
7 | | -* Move it all to ES6 |
8 | 6 |
|
9 | 7 | ## Getting started |
10 | | -### browserify |
11 | | -```sh |
12 | | -var Pager = require( 'react-pager' ); |
13 | | -``` |
14 | 8 |
|
15 | | -### Global scripts |
16 | | -dist/pager.min.js is prebuilded for using in global `<script>` tag. |
17 | | -(It's used in JSFiddle demo). |
| 9 | +```javascript |
| 10 | +import React from 'react'; |
| 11 | +import { render } from 'react-dom'; |
| 12 | +import Pager from 'react-pager'; |
| 13 | + |
| 14 | +class App extends React.Component { |
| 15 | + constructor(props) { |
| 16 | + super(props); |
| 17 | + |
| 18 | + this.handlePageChanged = this.handlePageChanged.bind(this); |
| 19 | + |
| 20 | + this.state = { |
| 21 | + total: 11, |
| 22 | + current: 7, |
| 23 | + visiblePage: 3, |
| 24 | + }; |
| 25 | + } |
| 26 | + |
| 27 | + handlePageChanged(newPage) { |
| 28 | + this.setState({ current : newPage }); |
| 29 | + } |
| 30 | + |
| 31 | + render() { |
| 32 | + return ( |
| 33 | + <Pager |
| 34 | + total={this.state.total} |
| 35 | + current={this.state.current} |
| 36 | + visiblePages={this.state.visiblePage} |
| 37 | + titles={{ first: '<|', last: '>|' }} |
| 38 | + onPageChanged={this.handlePageChanged} |
| 39 | + /> |
| 40 | + ); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +window.onload = () => { |
| 45 | + render(React.createElement(App), document.querySelector('#app')); |
| 46 | +}; |
18 | 47 |
|
19 | | - |
20 | | -## Usage |
21 | | -``` |
22 | | -var Pager = require( 'react-pager' ); |
23 | | -
|
24 | | -var PagerDemo = React.createClass({ |
25 | | - getInitialState: function () { |
26 | | - return { |
27 | | - total: 11, |
28 | | - current: 7, |
29 | | - visiblePages: 3 |
30 | | - }; |
31 | | - }, |
32 | | - |
33 | | - handlePageChanged: function ( newPage ) { |
34 | | - this.setState({ current : newPage }); |
35 | | - }, |
36 | | - |
37 | | - render: function() { |
38 | | - return (<Pager total={this.state.total} |
39 | | - current={this.state.current} |
40 | | - |
41 | | - {/* Optional */} |
42 | | - titles={{ |
43 | | - first: 'First', |
44 | | - prev: '\u00AB', |
45 | | - prevSet: '...', |
46 | | - nextSet: '...', |
47 | | - next: '\u00BB', |
48 | | - last: 'Last' |
49 | | - }} |
50 | | - |
51 | | - visiblePages={this.state.visiblePages} |
52 | | - onPageChanged={this.handlePageChanged}/>); |
53 | | - } |
54 | | -}); |
55 | | -
|
56 | | -React.render(<PagerDemo />, document.body); |
57 | 48 | ``` |
58 | 49 |
|
59 | | - |
60 | 50 | ## How it looks like* |
61 | | -``` |
62 | | -First | Prev | ... | 6 | 7 | 8 | 9 | ... | Next | Last |
63 | | -``` |
| 51 | + |
| 52 | + |
64 | 53 |
|
65 | 54 | \* Bootstrap 3.0 is required by default, but you can replace it with your own css. |
66 | 55 |
|
67 | 56 |
|
68 | 57 | ## Demo |
69 | | -```shell |
70 | | -gulp demo -p 8003 |
71 | | -``` |
72 | | -or |
73 | | -```shell |
74 | | -./node_modules/.bin/gulp demo -p 8003 |
75 | | -``` |
76 | 58 |
|
77 | | -[JSFiddle](http://jsfiddle.net/azaviruha/69z2wepo/4060/) |
| 59 | +Just open `demo/index.html` in your browser. |
| 60 | +Or see interactive demo [here](http://azaviruha.github.io/demo/react-pager/). |
| 61 | + |
78 | 62 |
|
79 | 63 |
|
80 | 64 | ## Tests |
| 65 | + |
81 | 66 | ```sh |
82 | 67 | npm test |
83 | 68 | ``` |
84 | 69 |
|
85 | 70 | ## Changelog |
| 71 | + |
| 72 | +### v1.2.0 |
| 73 | +* Rewrited all to ES6. |
| 74 | +* Switched from gulp + browserify to webpack. |
| 75 | +* Now officially supports only React >= 15.0.0 |
| 76 | + |
86 | 77 | ### v1.1.4 |
87 | 78 | * Updated to React 15. Thanks to contributors! |
88 | 79 |
|
|
0 commit comments