Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/ui-presets / dist / presets / Pagination / Pagination.js
Size: Mime:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});

const tslib_1 = require("tslib");

const react_1 = tslib_1.__importDefault(require("react"));

const mobx_react_1 = require("xmobx/mobx-react");

const exotic_1 = require("exotic");

const fixture_1 = require("./fixture");

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);
  }

  setPaginator(props) {
    const {
      paginationLimit,
      defaultIndex
    } = props;
    const paginator = defaultIndex ? defaultIndex : this.observableState.count;

    if (paginationLimit > 1) {
      if (paginator === 1) {
        this.observableState.disableIcon('left');
        this.observableState.enableIcon('right');
      } else if (paginator === paginationLimit) {
        this.observableState.disableIcon('right');
        this.observableState.enableIcon('left');
      } else {
        this.observableState.enableIcon('right');
        this.observableState.enableIcon('left');
      }

      this.observableState.setCount(paginator);
    } else if (paginationLimit === 1) {
      this.observableState.setCount(1);
      this.observableState.disableIcon();
    }
  }

  componentWillMount() {
    this.setPaginator(this.props);
  }

  componentWillReceiveProps(nextProps) {
    this.setPaginator(nextProps);
  }

  render() {
    const _a = this.props,
          {
      state = this.observableState,
      renderWrapper,
      renderDropDown,
      renderPaginationWithArrows
    } = _a,
          remainingProps = tslib_1.__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: fixture_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 = tslib_1.__decorate([mobx_react_1.observer], Pagination);
exports.Pagination = Pagination;
exports.default = Pagination;