Repository URL to install this package:
|
Version:
0.9.5 ▾
|
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const mobx_react_1 = require("xmobx/mobx-react");
const exotic_1 = require("exotic");
const fixtures_1 = require("./fixtures");
const renderProps_1 = require("./renderProps");
const state_1 = require("./state");
// only instantiate if needed
function initPaginationState() {
// console.debug('[Pagination] creating default state')
return new state_1.CountState();
}
function toPaginationState(props) {
if (props.state !== undefined) {
// console.debug('[Pagination] passed in state via props')
// console.dir(props)
return props.state;
}
else {
return initPaginationState();
}
}
let Pagination = class Pagination extends react_1.default.Component {
constructor() {
super(...arguments);
this.observableState = toPaginationState(this.props);
}
componentWillMount() {
const { paginationLimit, defaultIndex } = this.props;
if (paginationLimit === 1) {
this.observableState.disableIcon();
}
if (defaultIndex) {
const paginator = defaultIndex;
if (paginator === 1) {
this.observableState.disableIcon('left');
}
if (paginator === paginationLimit) {
this.observableState.disableIcon('right');
}
this.observableState.setCount(paginator);
}
}
render() {
const _a = this.props, { state = this.observableState, renderWrapper, renderDropDown, renderPaginationWithArrows } = _a, remainingProps = __rest(_a, ["state", "renderWrapper", "renderDropDown", "renderPaginationWithArrows"]);
const dropdownView = renderDropDown(remainingProps, this.observableState);
const paginationWithArrowView = renderPaginationWithArrows(remainingProps, this.observableState);
const children = (react_1.default.createElement(react_1.default.Fragment, null,
dropdownView,
paginationWithArrowView));
const view = renderWrapper(Object.assign({}, this.props, { children }), this.observableState);
return view;
}
};
Pagination.defaultProps = {
className: '',
paginationLimit: 10,
defaultIndex: 1,
list: fixtures_1.productsPerPageList,
renderWrapper: renderProps_1.defaultRenderWrapper,
renderPaginationWithArrows: renderProps_1.defaultRenderPaginationWithArrows,
renderLeftButton: renderProps_1.defaultRenderLeftButton,
renderRightButton: renderProps_1.defaultRenderRightButton,
renderDropDown: renderProps_1.defaultRenderDropDown,
renderPaginationInput: renderProps_1.defaultRenderPaginationInput,
onDecrement: renderProps_1.defaultOnDecrement,
onIncrement: renderProps_1.defaultOnIncrement,
onDropdownChange: exotic_1.NO_OP,
onPaginationInputChange: exotic_1.NO_OP,
onPaginationInputBlur: exotic_1.NO_OP,
};
Pagination = __decorate([
mobx_react_1.observer
], Pagination);
exports.Pagination = Pagination;
exports.default = Pagination;
//# sourceMappingURL=Pagination.js.map