1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | 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; }; }();
|
8 |
|
9 | var _templateObject = _taggedTemplateLiteral(['\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n list-style-type: none;\n\n li a {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n }\n\n li {\n background-color: ', ';\n display: none;\n }\n\n a {\n font-weight: 300;\n padding-top: 1px;\n text-decoration: none;\n border: 1px solid rgba(0, 0, 0, .25);\n border-left-width: 0;\n min-width: 44px;\n min-height: 44px;\n color: rgba(255, 255, 255, .85);\n box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, .35);\n }\n\n li:not([class*="current"]) a:hover {\n background-color: rgba(255, 255, 255, .2);\n border-top-color: rgba(0, 0, 0, .35);\n border-bottom-color: rgba(0, 0, 0, .5);\n }\n\n li:not([class*="current"]) a:focus,\n li:not([class*="current"]) a:active {\n box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, .25);\n border-left-width: 1px;\n }\n\n li:first-of-type a {\n border-left-width: 1px;\n }\n\n li:first-of-type span,\n li:last-of-type span,\n li:nth-of-type(2) span,\n li:nth-last-of-type(2) span {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n\n li:first-child a::before,\n li:last-child a::after,\n li:nth-of-type(2) a::before,\n li:nth-last-of-type(2) a::after {\n display: inline-block;\n font-size: inherit;\n text-rendering: auto;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n transform: translate(0, 0);\n }\n\n li:first-child a::before,\n li:last-child a::after {\n content: "<<";\n }\n\n li:nth-of-type(2) a::before,\n li:nth-last-of-type(2) a::after {\n content: "<";\n }\n\n li:last-child a::after,\n li:nth-last-of-type(2) a::after {\n transform: rotate(180deg);\n }\n\n li:nth-last-child(-n + 2) {\n display: inline-block;\n }\n\n li:nth-child(n + ', '):nth-child(-n + ', ') {\n display: inline-block;\n }\n li:nth-child(-n + 2) {\n display: inline-block;\n }\n\n li.current a {\n color: rgba(255, 255, 255, 1);\n background-color: rgba(255, 255, 255, .15);\n box-shadow: inset 0px 2px 1px 0px rgba(0, 0, 0, .25);\n cursor: default;\n pointer-events: none;\n }\n\n @media only screen and (max-width: 64.063em) {\n li:first-child,\n li:last-child {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n li:nth-of-type(2) a {\n border-left-width: 1px;\n }\n }\n\n @media only screen and (max-width: 40.063em) {\n li {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n\n li.current,\n li:first-of-type,\n li:last-of-type,\n li:nth-of-type(2),\n li:nth-last-of-type(2) {\n position: initial;\n top: initial;\n left: initial;\n }\n li:nth-of-type(2) a {\n border-left-width: 0;\n }\n }\n\n @media only screen and (max-width: 30.063em) {\n h1 {\n font-size: 1.35em !important;\n }\n li:first-child,\n li:last-child {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n li:nth-of-type(2) a {\n border-left-width: 1px;\n }\n }\n\n @media only screen and (max-width: 15.063em) {\n /* For watches? */\n li {\n width: 50%;\n }\n li.current {\n order: 2;\n width: 100%;\n border-left-width: 1px;\n }\n }\n'], ['\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n list-style-type: none;\n\n li a {\n display: flex;\n flex-wrap: nowrap;\n justify-content: center;\n align-items: center;\n }\n\n li {\n background-color: ', ';\n display: none;\n }\n\n a {\n font-weight: 300;\n padding-top: 1px;\n text-decoration: none;\n border: 1px solid rgba(0, 0, 0, .25);\n border-left-width: 0;\n min-width: 44px;\n min-height: 44px;\n color: rgba(255, 255, 255, .85);\n box-shadow: inset 0px 1px 0px 0px rgba(255, 255, 255, .35);\n }\n\n li:not([class*="current"]) a:hover {\n background-color: rgba(255, 255, 255, .2);\n border-top-color: rgba(0, 0, 0, .35);\n border-bottom-color: rgba(0, 0, 0, .5);\n }\n\n li:not([class*="current"]) a:focus,\n li:not([class*="current"]) a:active {\n box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, .25);\n border-left-width: 1px;\n }\n\n li:first-of-type a {\n border-left-width: 1px;\n }\n\n li:first-of-type span,\n li:last-of-type span,\n li:nth-of-type(2) span,\n li:nth-last-of-type(2) span {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n\n li:first-child a::before,\n li:last-child a::after,\n li:nth-of-type(2) a::before,\n li:nth-last-of-type(2) a::after {\n display: inline-block;\n font-size: inherit;\n text-rendering: auto;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n transform: translate(0, 0);\n }\n\n li:first-child a::before,\n li:last-child a::after {\n content: "<<";\n }\n\n li:nth-of-type(2) a::before,\n li:nth-last-of-type(2) a::after {\n content: "<";\n }\n\n li:last-child a::after,\n li:nth-last-of-type(2) a::after {\n transform: rotate(180deg);\n }\n\n li:nth-last-child(-n + 2) {\n display: inline-block;\n }\n\n li:nth-child(n + ', '):nth-child(-n + ', ') {\n display: inline-block;\n }\n li:nth-child(-n + 2) {\n display: inline-block;\n }\n\n li.current a {\n color: rgba(255, 255, 255, 1);\n background-color: rgba(255, 255, 255, .15);\n box-shadow: inset 0px 2px 1px 0px rgba(0, 0, 0, .25);\n cursor: default;\n pointer-events: none;\n }\n\n @media only screen and (max-width: 64.063em) {\n li:first-child,\n li:last-child {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n li:nth-of-type(2) a {\n border-left-width: 1px;\n }\n }\n\n @media only screen and (max-width: 40.063em) {\n li {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n\n li.current,\n li:first-of-type,\n li:last-of-type,\n li:nth-of-type(2),\n li:nth-last-of-type(2) {\n position: initial;\n top: initial;\n left: initial;\n }\n li:nth-of-type(2) a {\n border-left-width: 0;\n }\n }\n\n @media only screen and (max-width: 30.063em) {\n h1 {\n font-size: 1.35em !important;\n }\n li:first-child,\n li:last-child {\n /* screen readers only */\n position: absolute;\n top: -9999px;\n left: -9999px;\n }\n li:nth-of-type(2) a {\n border-left-width: 1px;\n }\n }\n\n @media only screen and (max-width: 15.063em) {\n /* For watches? */\n li {\n width: 50%;\n }\n li.current {\n order: 2;\n width: 100%;\n border-left-width: 1px;\n }\n }\n']);
|
10 |
|
11 | var _react = require('react');
|
12 |
|
13 | var _react2 = _interopRequireDefault(_react);
|
14 |
|
15 | var _propTypes = require('prop-types');
|
16 |
|
17 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
18 |
|
19 | var _styledComponents = require('styled-components');
|
20 |
|
21 | var _styledComponents2 = _interopRequireDefault(_styledComponents);
|
22 |
|
23 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
24 |
|
25 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
26 |
|
27 | 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; }
|
28 |
|
29 | 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; }
|
30 |
|
31 | function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
32 |
|
33 |
|
34 | var PaginateStyled = _styledComponents2.default.ul(_templateObject, function (props) {
|
35 | return props.theme.bahPaginateBackgroundColor;
|
36 | }, function (props) {
|
37 | return props.start;
|
38 | }, function (props) {
|
39 | return props.end;
|
40 | });
|
41 |
|
42 | var Paginate = function (_PureComponent) {
|
43 | _inherits(Paginate, _PureComponent);
|
44 |
|
45 | function Paginate(props) {
|
46 | _classCallCheck(this, Paginate);
|
47 |
|
48 | var _this = _possibleConstructorReturn(this, (Paginate.__proto__ || Object.getPrototypeOf(Paginate)).call(this, props));
|
49 |
|
50 | _this.state = { linkId: 0, linkActive: false, skip: 0, start: 3, end: 12 };
|
51 |
|
52 | _this.handleClick = function (link) {
|
53 | return function () {
|
54 | var newSkip = void 0;
|
55 | var _this$state = _this.state,
|
56 | start = _this$state.start,
|
57 | end = _this$state.end,
|
58 | skip = _this$state.skip;
|
59 | var _this$props = _this.props,
|
60 | perPage = _this$props.perPage,
|
61 | count = _this$props.count,
|
62 | func = _this$props.func;
|
63 |
|
64 |
|
65 | if (link.id === 'Previous') {
|
66 | newSkip = skip !== 0 ? skip - perPage : skip;
|
67 | } else if (link.id === 'Next') {
|
68 | newSkip = skip <= count && skip + perPage < count ? skip + perPage : skip;
|
69 | } else if (link.id === 'First') {
|
70 | newSkip = 0;
|
71 | if (start - 3 < link.pages && start !== 3) {
|
72 | _this.setState({ start: start - 10, end: end - 10 });
|
73 | }
|
74 | } else if (link.id === 'Last') {
|
75 | newSkip = link.skip;
|
76 | if (end - 2 < link.pages) {
|
77 | _this.setState({ start: start + 10, end: end + 10 });
|
78 | }
|
79 | } else {
|
80 | newSkip = link.skip;
|
81 | }
|
82 | func(perPage, newSkip);
|
83 | _this.setState({ linkId: link.id, linkActive: true, skip: newSkip });
|
84 | };
|
85 | };
|
86 |
|
87 | _this.buttonPages = function (link) {
|
88 | return _react2.default.createElement(
|
89 | 'li',
|
90 | {
|
91 | key: 'li-' + link.id,
|
92 | className: _this.state.linkId === link.id && _this.state.linkActive && link.id !== 'First' && link.id !== 'Previous' && link.id !== 'Next' && link.id !== 'Last' ? 'current' : ''
|
93 | },
|
94 | _react2.default.createElement(
|
95 | 'a',
|
96 | { href: '#', onClick: _this.handleClick(link) },
|
97 | _react2.default.createElement(
|
98 | 'span',
|
99 | null,
|
100 | link.id
|
101 | )
|
102 | )
|
103 | );
|
104 | };
|
105 |
|
106 | _this.generatePageLinks = function () {
|
107 | var pagesCount = _this.props.count / _this.props.perPage;
|
108 | pagesCount = Math.ceil(pagesCount);
|
109 |
|
110 | var links = [];
|
111 | var skip = 0;
|
112 |
|
113 | for (var i = 1; i <= pagesCount; i++) {
|
114 | if (i === 1) {
|
115 | links.push({ id: 'First', skip: skip, pages: pagesCount });
|
116 | links.push({
|
117 | id: 'Previous',
|
118 | skip: skip,
|
119 | pages: pagesCount
|
120 | });
|
121 | }
|
122 |
|
123 | links.push({ id: i, skip: skip, pages: pagesCount });
|
124 |
|
125 | if (i === pagesCount) {
|
126 | links.push({ id: 'Next', skip: skip, pages: pagesCount });
|
127 | links.push({
|
128 | id: 'Last',
|
129 | skip: skip,
|
130 | pages: pagesCount
|
131 | });
|
132 | }
|
133 | skip += _this.props.perPage;
|
134 | }
|
135 |
|
136 | return links.map(function (link) {
|
137 | return _this.buttonPages(link);
|
138 | });
|
139 | };
|
140 | return _this;
|
141 | }
|
142 |
|
143 | _createClass(Paginate, [{
|
144 | key: 'render',
|
145 | value: function render() {
|
146 | return _react2.default.createElement(
|
147 | PaginateStyled,
|
148 | { start: this.state.start, end: this.state.end },
|
149 | this.generatePageLinks()
|
150 | );
|
151 | }
|
152 | }]);
|
153 |
|
154 | return Paginate;
|
155 | }(_react.PureComponent);
|
156 |
|
157 | Paginate.defaultProps = {
|
158 | count: 0,
|
159 | perPage: 5,
|
160 | func: {}
|
161 | };
|
162 |
|
163 | Paginate.propTypes = {
|
164 | count: _propTypes2.default.number,
|
165 | perPage: _propTypes2.default.number,
|
166 | func: _propTypes2.default.func
|
167 | };
|
168 |
|
169 | exports.default = Paginate; |
\ | No newline at end of file |