rc-pagination
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -5,14 +5,13 @@ 'use strict'; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
var React = require('react'); | ||
var KEYCODE = require('./KeyCode'); | ||
var Select = require('rc-select'); | ||
var Option = Select.Option; | ||
var Options = (function (_React$Component) { | ||
_inherits(Options, _React$Component); | ||
function Options(props) { | ||
@@ -24,9 +23,3 @@ var _this = this; | ||
_get(Object.getPrototypeOf(Options.prototype), 'constructor', this).call(this, props); | ||
this.state = { | ||
current: props.current, | ||
_current: props.current | ||
}; | ||
['_handleChange', '_changeSize', '_go', '_buildOptionText'].forEach(function (method) { | ||
['_quickGo', '_changeSize'].map(function (method) { | ||
return _this[method] = _this[method].bind(_this); | ||
@@ -36,91 +29,51 @@ }); | ||
_inherits(Options, _React$Component); | ||
_createClass(Options, [{ | ||
key: '_buildOptionText', | ||
value: function _buildOptionText(value) { | ||
return value + ' ' + this.props.locale.items_per_page; | ||
} | ||
}, { | ||
key: '_changeSize', | ||
value: function _changeSize(value) { | ||
this.props.changeSize(Number(value)); | ||
} | ||
}, { | ||
key: '_handleChange', | ||
value: function _handleChange(evt) { | ||
var _val = evt.target.value; | ||
this.setState({ | ||
_current: _val | ||
}); | ||
} | ||
}, { | ||
key: '_go', | ||
value: function _go(e) { | ||
var _val = e.target.value; | ||
if (_val === '') { | ||
return; | ||
} | ||
var val = Number(this.state._current); | ||
if (isNaN(val)) { | ||
val = this.state.current; | ||
} | ||
if (e.keyCode === KEYCODE.ENTER) { | ||
var c = this.props.quickGo(val); | ||
this.setState({ | ||
_current: c, | ||
current: c | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _this2 = this; | ||
var props = this.props; | ||
var state = this.state; | ||
var locale = props.locale; | ||
var prefixCls = props.rootPrefixCls + '-options'; | ||
var changeSize = props.changeSize; | ||
var quickGo = props.quickGo; | ||
var buildOptionText = props.buildOptionText || this._buildOptionText; | ||
var Select = props.selectComponentClass; | ||
var changeSelect = null; | ||
var goInput = null; | ||
if (!(changeSize || quickGo)) { | ||
return null; | ||
if (changeSize) { | ||
changeSelect = React.createElement( | ||
Select, | ||
{ prefixCls: props.selectPrefixCls, showSearch: false, | ||
className: prefixCls + '-size-changer', | ||
defaultValue: '10', onChange: this._changeSize }, | ||
React.createElement( | ||
Option, | ||
{ value: '10' }, | ||
'10 条/页' | ||
), | ||
React.createElement( | ||
Option, | ||
{ value: '20' }, | ||
'20 条/页' | ||
), | ||
React.createElement( | ||
Option, | ||
{ value: '30' }, | ||
'30 条/页' | ||
), | ||
React.createElement( | ||
Option, | ||
{ value: '40' }, | ||
'40 条/页' | ||
) | ||
); | ||
} | ||
if (changeSize && Select) { | ||
(function () { | ||
var Option = Select.Option; | ||
var defaultOption = props.pageSizeOptions[0]; | ||
var options = props.pageSizeOptions.map(function (opt, i) { | ||
return React.createElement( | ||
Option, | ||
{ key: i, value: opt }, | ||
buildOptionText(opt) | ||
); | ||
}); | ||
changeSelect = React.createElement( | ||
Select, | ||
{ | ||
prefixCls: props.selectPrefixCls, showSearch: false, | ||
className: prefixCls + '-size-changer', | ||
optionLabelProp: 'children', | ||
defaultValue: defaultOption, onChange: _this2._changeSize }, | ||
options | ||
); | ||
})(); | ||
} | ||
if (quickGo) { | ||
goInput = React.createElement( | ||
'div', | ||
{ title: 'Quick jump to page', className: prefixCls + '-quick-jumper' }, | ||
locale.jump_to, | ||
React.createElement('input', { type: 'text', value: state._current, onChange: this._handleChange.bind(this), onKeyUp: this._go.bind(this) }), | ||
locale.page | ||
{ className: prefixCls + '-quick-jumper' }, | ||
'跳至', | ||
React.createElement('input', { type: 'text', value: props.current, onChange: this._quickGo }), | ||
'页' | ||
); | ||
@@ -136,2 +89,12 @@ } | ||
} | ||
}, { | ||
key: '_changeSize', | ||
value: function _changeSize(value) { | ||
this.props.changeSize(Number(value)); | ||
} | ||
}, { | ||
key: '_quickGo', | ||
value: function _quickGo(evt) { | ||
this.props.quickGo(Number(evt.target.value)); | ||
} | ||
}]); | ||
@@ -145,13 +108,7 @@ | ||
quickGo: React.PropTypes.func, | ||
selectComponentClass: React.PropTypes.func, | ||
current: React.PropTypes.number, | ||
pageSizeOptions: React.PropTypes.arrayOf(React.PropTypes.string), | ||
buildOptionText: React.PropTypes.func, | ||
locale: React.PropTypes.object | ||
}; | ||
Options.defaultProps = { | ||
pageSizeOptions: ['10', '20', '30', '40'] | ||
sizeChangerClass: React.PropTypes.bool, | ||
current: React.PropTypes.number | ||
}; | ||
module.exports = Options; |
@@ -5,7 +5,7 @@ 'use strict'; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
@@ -15,4 +15,2 @@ var React = require('react'); | ||
var Pager = (function (_React$Component) { | ||
_inherits(Pager, _React$Component); | ||
function Pager() { | ||
@@ -24,2 +22,4 @@ _classCallCheck(this, Pager); | ||
_inherits(Pager, _React$Component); | ||
_createClass(Pager, [{ | ||
@@ -29,3 +29,2 @@ key: 'render', | ||
var props = this.props; | ||
var locale = props.locale; | ||
var prefixCls = props.rootPrefixCls + '-item'; | ||
@@ -37,14 +36,5 @@ var cls = prefixCls + ' ' + prefixCls + '-' + props.page; | ||
} | ||
var title = undefined; | ||
if (props.page === 1) { | ||
title = locale.first_page; | ||
} else if (props.last) { | ||
title = locale.last_page + ': ' + props.page; | ||
} else { | ||
title = props.page; | ||
} | ||
return React.createElement( | ||
'li', | ||
{ title: title, className: cls, onClick: props.onClick }, | ||
{ className: cls, onClick: props.onClick }, | ||
React.createElement( | ||
@@ -64,7 +54,5 @@ 'a', | ||
page: React.PropTypes.number, | ||
active: React.PropTypes.bool, | ||
last: React.PropTypes.bool, | ||
locale: React.PropTypes.object | ||
active: React.PropTypes.bool | ||
}; | ||
module.exports = Pager; |
@@ -5,7 +5,7 @@ 'use strict'; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; } | ||
@@ -15,4 +15,2 @@ var React = require('react'); | ||
var Options = require('./Options'); | ||
var KEYCODE = require('./KeyCode'); | ||
var LOCALE = require('./locale/zh_CN'); | ||
@@ -22,4 +20,2 @@ function noop() {} | ||
var Pagination = (function (_React$Component) { | ||
_inherits(Pagination, _React$Component); | ||
function Pagination(props) { | ||
@@ -32,20 +28,8 @@ var _this = this; | ||
var hasOnChange = props.onChange !== noop; | ||
var hasCurrent = props.current !== -1; | ||
if (hasOnChange ^ hasCurrent) { | ||
console.warn('provide `onChange` and `current` together'); | ||
} | ||
var current = props.defaultCurrent; | ||
if ('current' in props) { | ||
current = props.current; | ||
} | ||
this.state = { | ||
current: current, | ||
_current: current, | ||
current: props.current, | ||
pageSize: props.pageSize | ||
}; | ||
['render', '_handleChange', '_handleKeyUp', '_handleKeyDown', '_changePageSize', '_isValid', '_prev', '_next', '_hasPrev', '_hasNext', '_jumpPrev', '_jumpNext'].forEach(function (method) { | ||
['render', '_handleChange', '_simpleChange', '_changePageSize', '_isValid', '_prev', '_next', '_hasPrev', '_hasNext', '_jumpPrev', '_jumpNext', '_canJumpPrev', '_canJumpNext'].map(function (method) { | ||
return _this[method] = _this[method].bind(_this); | ||
@@ -55,2 +39,4 @@ }); | ||
_inherits(Pagination, _React$Component); | ||
_createClass(Pagination, [{ | ||
@@ -71,135 +57,6 @@ key: 'componentWillReceiveProps', | ||
} | ||
// private methods | ||
}, { | ||
key: '_calcPage', | ||
value: function _calcPage(p) { | ||
var pageSize = p; | ||
if (typeof pageSize === 'undefined') { | ||
pageSize = this.state.pageSize; | ||
} | ||
return Math.floor((this.props.total - 1) / pageSize) + 1; | ||
} | ||
}, { | ||
key: '_isValid', | ||
value: function _isValid(page) { | ||
return typeof page === 'number' && page >= 1 && page !== this.state.current; | ||
} | ||
}, { | ||
key: '_handleKeyDown', | ||
value: function _handleKeyDown(evt) { | ||
if (evt.keyCode === KEYCODE.ARROW_UP || evt.keyCode === KEYCODE.ARROW_DOWN) { | ||
evt.preventDefault(); | ||
} | ||
} | ||
}, { | ||
key: '_handleKeyUp', | ||
value: function _handleKeyUp(evt) { | ||
var _val = evt.target.value; | ||
var val = undefined; | ||
if (_val === '') { | ||
val = _val; | ||
} else if (isNaN(Number(_val))) { | ||
val = this.state._current; | ||
} else { | ||
val = Number(_val); | ||
} | ||
this.setState({ | ||
_current: val | ||
}); | ||
if (evt.keyCode === KEYCODE.ENTER) { | ||
this._handleChange(val); | ||
} else if (evt.keyCode === KEYCODE.ARROW_UP) { | ||
this._handleChange(val - 1); | ||
} else if (evt.keyCode === KEYCODE.ARROW_DOWN) { | ||
this._handleChange(val + 1); | ||
} | ||
} | ||
}, { | ||
key: '_changePageSize', | ||
value: function _changePageSize(size) { | ||
if (typeof size === 'number') { | ||
var current = this.state.current; | ||
this.setState({ | ||
pageSize: size | ||
}); | ||
if (this.state.current > this._calcPage(size)) { | ||
current = this._calcPage(size); | ||
this.setState({ | ||
current: current, | ||
_current: current | ||
}); | ||
} | ||
this.props.onShowSizeChange(current, size); | ||
} | ||
} | ||
}, { | ||
key: '_handleChange', | ||
value: function _handleChange(p) { | ||
var page = p; | ||
if (this._isValid(page)) { | ||
if (page > this._calcPage()) { | ||
page = this._calcPage(); | ||
} | ||
if (!('current' in this.props)) { | ||
this.setState({ | ||
current: page, | ||
_current: page | ||
}); | ||
} | ||
this.props.onChange(page); | ||
return page; | ||
} | ||
return this.state.current; | ||
} | ||
}, { | ||
key: '_prev', | ||
value: function _prev() { | ||
if (this._hasPrev()) { | ||
this._handleChange(this.state.current - 1); | ||
} | ||
} | ||
}, { | ||
key: '_next', | ||
value: function _next() { | ||
if (this._hasNext()) { | ||
this._handleChange(this.state.current + 1); | ||
} | ||
} | ||
}, { | ||
key: '_jumpPrev', | ||
value: function _jumpPrev() { | ||
this._handleChange(Math.max(1, this.state.current - 5)); | ||
} | ||
}, { | ||
key: '_jumpNext', | ||
value: function _jumpNext() { | ||
this._handleChange(Math.min(this._calcPage(), this.state.current + 5)); | ||
} | ||
}, { | ||
key: '_hasPrev', | ||
value: function _hasPrev() { | ||
return this.state.current > 1; | ||
} | ||
}, { | ||
key: '_hasNext', | ||
value: function _hasNext() { | ||
return this.state.current < this._calcPage(); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var props = this.props; | ||
var locale = props.locale; | ||
@@ -211,4 +68,2 @@ var prefixCls = props.prefixCls; | ||
var jumpNext = null; | ||
var firstPager = null; | ||
var lastPager = null; | ||
@@ -221,9 +76,13 @@ if (props.simple) { | ||
'li', | ||
{ title: locale.prev_page, onClick: this._prev, className: (this._hasPrev() ? '' : prefixCls + '-disabled ') + (prefixCls + '-prev') }, | ||
React.createElement('a', null) | ||
{ onClick: this._prev, className: (this._hasPrev() ? '' : prefixCls + '-disabled ') + (prefixCls + '-prev') }, | ||
React.createElement( | ||
'a', | ||
null, | ||
'‹' | ||
) | ||
), | ||
React.createElement( | ||
'div', | ||
{ title: this.state.current + '/' + allPages, className: prefixCls + '-simple-pager' }, | ||
React.createElement('input', { type: 'text', value: this.state._current, onKeyDown: this._handleKeyDown, onKeyUp: this._handleKeyUp, onChange: this._handleKeyUp }), | ||
{ className: prefixCls + '-simple-pager' }, | ||
React.createElement('input', { type: 'text', value: this.state.current, onChange: this._simpleChange }), | ||
React.createElement( | ||
@@ -238,4 +97,8 @@ 'span', | ||
'li', | ||
{ title: locale.next_page, onClick: this._next, className: (this._hasNext() ? '' : prefixCls + '-disabled ') + (prefixCls + '-next') }, | ||
React.createElement('a', null) | ||
{ onClick: this._next, className: (this._hasNext() ? '' : prefixCls + '-disabled ') + (prefixCls + '-next') }, | ||
React.createElement( | ||
'a', | ||
null, | ||
'›' | ||
) | ||
) | ||
@@ -248,3 +111,3 @@ ); | ||
var active = this.state.current === i; | ||
pagerList.push(React.createElement(Pager, { locale: locale, rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
} | ||
@@ -254,3 +117,3 @@ } else { | ||
'li', | ||
{ title: locale.prev_5, key: 'prev', onClick: this._jumpPrev, className: prefixCls + '-jump-prev' }, | ||
{ key: 'prev', onClick: this._jumpPrev, className: prefixCls + '-jump-prev' }, | ||
React.createElement('a', null) | ||
@@ -260,45 +123,36 @@ ); | ||
'li', | ||
{ title: locale.next_5, key: 'next', onClick: this._jumpNext, className: prefixCls + '-jump-next' }, | ||
{ key: 'next', onClick: this._jumpNext, className: prefixCls + '-jump-next' }, | ||
React.createElement('a', null) | ||
); | ||
lastPager = React.createElement(Pager, { | ||
locale: props.locale, | ||
last: true, rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, allPages), key: allPages, page: allPages, active: false }); | ||
firstPager = React.createElement(Pager, { | ||
locale: props.locale, | ||
rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, 1), key: 1, page: 1, active: false }); | ||
var current = this.state.current; | ||
var left = Math.max(1, current - 2); | ||
var right = Math.min(current + 2, allPages); | ||
if (current - 1 <= 2) { | ||
right = 1 + 4; | ||
} | ||
if (allPages - current <= 2) { | ||
left = allPages - 4; | ||
} | ||
for (var i = left; i <= right; i++) { | ||
var active = current === i; | ||
pagerList.push(React.createElement(Pager, { | ||
locale: props.locale, | ||
rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
} | ||
if (current - 1 >= 4) { | ||
pagerList.unshift(jumpPrev); | ||
} | ||
if (allPages - current >= 4) { | ||
// TODO: need optimization | ||
if (current <= 5) { | ||
// do not show first ••• | ||
for (var i = 1; i <= 5; i++) { | ||
var active = current === i; | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
} | ||
pagerList.push(jumpNext); | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, allPages), key: allPages, page: allPages, active: false })); | ||
} else if (allPages - current < 5) { | ||
// do not show last ••• | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, 1), key: 1, page: 1, active: false })); | ||
pagerList.push(jumpPrev); | ||
for (var i = allPages - 4; i <= allPages; i++) { | ||
var active = current === i; | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
} | ||
} else { | ||
// show both ••• | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, 1), key: 1, page: 1, active: false })); | ||
pagerList.push(jumpPrev); | ||
for (var i = current - 2; i <= current + 2; i++) { | ||
var active = current === i; | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, i), key: i, page: i, active: active })); | ||
} | ||
pagerList.push(jumpNext); | ||
pagerList.push(React.createElement(Pager, { rootPrefixCls: prefixCls, onClick: this._handleChange.bind(this, allPages), key: allPages, page: allPages, active: false })); | ||
} | ||
if (left !== 1) { | ||
pagerList.unshift(firstPager); | ||
} | ||
if (right !== allPages) { | ||
pagerList.push(lastPager); | ||
} | ||
} | ||
@@ -312,4 +166,8 @@ | ||
'li', | ||
{ title: locale.prev_page, onClick: this._prev, className: (this._hasPrev() ? '' : prefixCls + '-disabled ') + (prefixCls + '-prev') }, | ||
React.createElement('a', null) | ||
{ onClick: this._prev, className: (this._hasPrev() ? '' : prefixCls + '-disabled ') + (prefixCls + '-prev') }, | ||
React.createElement( | ||
'a', | ||
null, | ||
'‹' | ||
) | ||
), | ||
@@ -319,16 +177,97 @@ pagerList, | ||
'li', | ||
{ title: locale.next_page, onClick: this._next, className: (this._hasNext() ? '' : prefixCls + '-disabled ') + (prefixCls + '-next') }, | ||
React.createElement('a', null) | ||
{ onClick: this._next, className: (this._hasNext() ? '' : prefixCls + '-disabled ') + (prefixCls + '-next') }, | ||
React.createElement( | ||
'a', | ||
null, | ||
'›' | ||
) | ||
), | ||
React.createElement(Options, { | ||
locale: props.locale, | ||
rootPrefixCls: prefixCls, | ||
selectComponentClass: props.selectComponentClass, | ||
React.createElement(Options, { rootPrefixCls: prefixCls, | ||
selectPrefixCls: props.selectPrefixCls, | ||
changeSize: this.props.showSizeChanger ? this._changePageSize.bind(this) : null, | ||
current: this.state.current, | ||
pageSizeOptions: this.props.pageSizeOptions, | ||
quickGo: this.props.showQuickJumper ? this._handleChange.bind(this) : null }) | ||
changeSize: this.props.showSizeChanger ? this._changePageSize.bind(this) : null, current: this.state.current, quickGo: this.props.showQuickJumper ? this._handleChange.bind(this) : null }) | ||
); | ||
} | ||
}, { | ||
key: '_calcPage', | ||
// private methods | ||
value: function _calcPage() { | ||
return Math.floor((this.props.total - 1) / this.state.pageSize); | ||
} | ||
}, { | ||
key: '_isValid', | ||
value: function _isValid(page) { | ||
return typeof page === 'number'; // && page >= 1 && page <= this._calcPage(); | ||
} | ||
}, { | ||
key: '_changePageSize', | ||
value: function _changePageSize(size) { | ||
if (typeof size === 'number') { | ||
this.setState({ | ||
pageSize: size | ||
}); | ||
} | ||
} | ||
}, { | ||
key: '_simpleChange', | ||
value: function _simpleChange(evt) { | ||
this._handleChange(Number(evt.target.value)); | ||
} | ||
}, { | ||
key: '_handleChange', | ||
value: function _handleChange(page) { | ||
if (this._isValid(page)) { | ||
this.setState({ current: page }); | ||
this.props.onChange(page); | ||
} | ||
} | ||
}, { | ||
key: '_prev', | ||
value: function _prev() { | ||
if (this._hasPrev()) { | ||
this._handleChange(this.state.current - 1); | ||
} | ||
} | ||
}, { | ||
key: '_next', | ||
value: function _next() { | ||
if (this._hasNext()) { | ||
this._handleChange(this.state.current + 1); | ||
} | ||
} | ||
}, { | ||
key: '_jumpPrev', | ||
value: function _jumpPrev() { | ||
if (this._canJumpPrev()) { | ||
this._handleChange(this.state.current - 5); | ||
} | ||
} | ||
}, { | ||
key: '_jumpNext', | ||
value: function _jumpNext() { | ||
if (this._canJumpNext()) { | ||
this._handleChange(this.state.current + 5); | ||
} | ||
} | ||
}, { | ||
key: '_hasPrev', | ||
value: function _hasPrev() { | ||
return this.state.current > 1; | ||
} | ||
}, { | ||
key: '_hasNext', | ||
value: function _hasNext() { | ||
return this.state.current < this._calcPage(); | ||
} | ||
}, { | ||
key: '_canJumpPrev', | ||
value: function _canJumpPrev() { | ||
return this.state.current > 5; | ||
} | ||
}, { | ||
key: '_canJumpNext', | ||
value: function _canJumpNext() { | ||
return this._calcPage() - this.state.current > 5; | ||
} | ||
}]); | ||
@@ -341,3 +280,2 @@ | ||
current: React.PropTypes.number, | ||
defaultCurrent: React.PropTypes.number, | ||
total: React.PropTypes.number, | ||
@@ -347,12 +285,7 @@ pageSize: React.PropTypes.number, | ||
showSizeChanger: React.PropTypes.bool, | ||
onShowSizeChange: React.PropTypes.func, | ||
selectComponentClass: React.PropTypes.func, | ||
showQuickJumper: React.PropTypes.bool, | ||
pageSizeOptions: React.PropTypes.arrayOf(React.PropTypes.string), | ||
locale: React.PropTypes.object | ||
showQuickJumper: React.PropTypes.bool | ||
}; | ||
Pagination.defaultProps = { | ||
defaultCurrent: 1, | ||
current: 1, | ||
total: 0, | ||
@@ -364,9 +297,6 @@ pageSize: 10, | ||
prefixCls: 'rc-pagination', | ||
selectComponentClass: null, | ||
showQuickJumper: false, | ||
showSizeChanger: false, | ||
onShowSizeChange: noop, | ||
locale: LOCALE | ||
showSizeChanger: false | ||
}; | ||
module.exports = Pagination; |
{ | ||
"name": "rc-pagination", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "pagination ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25510
8
559