1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _react = _interopRequireDefault(require("react"));
|
8 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
9 | var _classnames = _interopRequireDefault(require("classnames"));
|
10 | var _utils = require("./utils");
|
11 | const _excluded = ["className", "cssModule", "next", "previous", "first", "last", "tag"];
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 | function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
|
14 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
15 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
16 | const propTypes = {
|
17 | 'aria-label': _propTypes.default.string,
|
18 | children: _propTypes.default.node,
|
19 |
|
20 | className: _propTypes.default.string,
|
21 |
|
22 | cssModule: _propTypes.default.object,
|
23 |
|
24 | next: _propTypes.default.bool,
|
25 |
|
26 | previous: _propTypes.default.bool,
|
27 |
|
28 | first: _propTypes.default.bool,
|
29 |
|
30 | last: _propTypes.default.bool,
|
31 |
|
32 | tag: _utils.tagPropType
|
33 | };
|
34 | function PaginationLink(props) {
|
35 | let {
|
36 | className,
|
37 | cssModule,
|
38 | next,
|
39 | previous,
|
40 | first,
|
41 | last,
|
42 | tag: Tag = 'a'
|
43 | } = props,
|
44 | attributes = _objectWithoutProperties(props, _excluded);
|
45 | const classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, 'page-link'), cssModule);
|
46 | let defaultAriaLabel;
|
47 | if (previous) {
|
48 | defaultAriaLabel = 'Previous';
|
49 | } else if (next) {
|
50 | defaultAriaLabel = 'Next';
|
51 | } else if (first) {
|
52 | defaultAriaLabel = 'First';
|
53 | } else if (last) {
|
54 | defaultAriaLabel = 'Last';
|
55 | }
|
56 | const ariaLabel = props['aria-label'] || defaultAriaLabel;
|
57 | let defaultCaret;
|
58 | if (previous) {
|
59 | defaultCaret = '\u2039';
|
60 | } else if (next) {
|
61 | defaultCaret = '\u203A';
|
62 | } else if (first) {
|
63 | defaultCaret = '\u00ab';
|
64 | } else if (last) {
|
65 | defaultCaret = '\u00bb';
|
66 | }
|
67 | let {
|
68 | children
|
69 | } = props;
|
70 | if (children && Array.isArray(children) && children.length === 0) {
|
71 | children = null;
|
72 | }
|
73 | if (!attributes.href && Tag === 'a') {
|
74 | Tag = 'button';
|
75 | }
|
76 | if (previous || next || first || last) {
|
77 | children = [_react.default.createElement("span", {
|
78 | "aria-hidden": "true",
|
79 | key: "caret"
|
80 | }, children || defaultCaret), _react.default.createElement("span", {
|
81 | className: "visually-hidden",
|
82 | key: "ariaLabel"
|
83 | }, ariaLabel)];
|
84 | }
|
85 | return _react.default.createElement(Tag, _extends({}, attributes, {
|
86 | className: classes,
|
87 | "aria-label": ariaLabel
|
88 | }), children);
|
89 | }
|
90 | PaginationLink.propTypes = propTypes;
|
91 | var _default = PaginationLink;
|
92 | exports.default = _default; |
\ | No newline at end of file |