1 | var _excluded = ["className", "cssModule", "next", "previous", "first", "last", "tag"];
|
2 | 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); }
|
3 | 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; }
|
4 | 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; }
|
5 | import React from 'react';
|
6 | import PropTypes from 'prop-types';
|
7 | import classNames from 'classnames';
|
8 | import { mapToCssModules, tagPropType } from './utils';
|
9 | var propTypes = {
|
10 | 'aria-label': PropTypes.string,
|
11 | children: PropTypes.node,
|
12 |
|
13 | className: PropTypes.string,
|
14 |
|
15 | cssModule: PropTypes.object,
|
16 |
|
17 | next: PropTypes.bool,
|
18 |
|
19 | previous: PropTypes.bool,
|
20 |
|
21 | first: PropTypes.bool,
|
22 |
|
23 | last: PropTypes.bool,
|
24 |
|
25 | tag: tagPropType
|
26 | };
|
27 | function PaginationLink(props) {
|
28 | var className = props.className,
|
29 | cssModule = props.cssModule,
|
30 | next = props.next,
|
31 | previous = props.previous,
|
32 | first = props.first,
|
33 | last = props.last,
|
34 | _props$tag = props.tag,
|
35 | Tag = _props$tag === void 0 ? 'a' : _props$tag,
|
36 | attributes = _objectWithoutProperties(props, _excluded);
|
37 | var classes = mapToCssModules(classNames(className, 'page-link'), cssModule);
|
38 | var defaultAriaLabel;
|
39 | if (previous) {
|
40 | defaultAriaLabel = 'Previous';
|
41 | } else if (next) {
|
42 | defaultAriaLabel = 'Next';
|
43 | } else if (first) {
|
44 | defaultAriaLabel = 'First';
|
45 | } else if (last) {
|
46 | defaultAriaLabel = 'Last';
|
47 | }
|
48 | var ariaLabel = props['aria-label'] || defaultAriaLabel;
|
49 | var defaultCaret;
|
50 | if (previous) {
|
51 | defaultCaret = "\u2039";
|
52 | } else if (next) {
|
53 | defaultCaret = "\u203A";
|
54 | } else if (first) {
|
55 | defaultCaret = "\xAB";
|
56 | } else if (last) {
|
57 | defaultCaret = "\xBB";
|
58 | }
|
59 | var children = props.children;
|
60 | if (children && Array.isArray(children) && children.length === 0) {
|
61 | children = null;
|
62 | }
|
63 | if (!attributes.href && Tag === 'a') {
|
64 | Tag = 'button';
|
65 | }
|
66 | if (previous || next || first || last) {
|
67 | children = [React.createElement("span", {
|
68 | "aria-hidden": "true",
|
69 | key: "caret"
|
70 | }, children || defaultCaret), React.createElement("span", {
|
71 | className: "visually-hidden",
|
72 | key: "ariaLabel"
|
73 | }, ariaLabel)];
|
74 | }
|
75 | return React.createElement(Tag, _extends({}, attributes, {
|
76 | className: classes,
|
77 | "aria-label": ariaLabel
|
78 | }), children);
|
79 | }
|
80 | PaginationLink.propTypes = propTypes;
|
81 | export default PaginationLink; |
\ | No newline at end of file |