UNPKG

yylib-quick-mobile

Version:

yylib-quick-mobile

113 lines (85 loc) 5.09 kB
'use strict'; var _pagination = require('antd-mobile/lib/pagination'); var _pagination2 = _interopRequireDefault(_pagination); var _icon = require('antd-mobile/lib/icon'); var _icon2 = _interopRequireDefault(_icon); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); require('antd-mobile/lib/pagination/style/css'); require('antd-mobile/lib/icon/style/css'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); require('./YYPagination.less'); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _FunctionUtil = require('../../utils/FunctionUtil'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } 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; } var YYPagination = function (_React$Component) { _inherits(YYPagination, _React$Component); function YYPagination(props) { _classCallCheck(this, YYPagination); var _this = _possibleConstructorReturn(this, (YYPagination.__proto__ || Object.getPrototypeOf(YYPagination)).call(this, props)); _this.onChange = function (options) { if ((0, _FunctionUtil.isFunction)(_this.props.onChange)) { _this.props.onChange(options); } }; _this.state = {}; return _this; } _createClass(YYPagination, [{ key: 'render', value: function render() { var _props = this.props, prevText = _props.prevText, nextText = _props.nextText, total = _props.total, current = _props.current, mode = _props.mode, simple = _props.simple, disabled = _props.disabled, visible = _props.visible, restProps = _objectWithoutProperties(_props, ['prevText', 'nextText', 'total', 'current', 'mode', 'simple', 'disabled', 'visible']); var prevIcon = mode === 'icon' && _react2.default.createElement(_icon2.default, { type: 'left' }); var nextIcon = mode === 'icon' && _react2.default.createElement(_icon2.default, { type: 'right' }); var locale = { prevText: _react2.default.createElement( 'span', { className: 'arrow-align' }, prevIcon, prevText ? prevText : '上一步' ), nextText: _react2.default.createElement( 'span', { className: 'arrow-align' }, nextText ? nextText : '下一步', nextIcon ) }; var wrapClz = (0, _classnames2.default)('yy-pagination', !visible && 'hidden', this.props.className); var iconwrapClz = (0, _classnames2.default)('yy-pagination custom-pagination-with-icon', !visible && 'hidden', this.props.className); return _react2.default.createElement(_pagination2.default, _extends({}, restProps, { className: mode === 'icon' ? iconwrapClz : wrapClz, total: total, simple: simple, current: this.state.current, locale: this.props.locale || locale, mode: mode, onChange: this.onChange, disabled: disabled })); } }]); return YYPagination; }(_react2.default.Component); YYPagination.defaultProps = { current: 1, mode: 'button', total: 1, visible: true, simple: false }; module.exports = YYPagination;