UNPKG

3.7 kBJavaScriptView Raw
1var _excluded = ["className", "cssModule", "next", "previous", "first", "last", "tag"];
2function _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); }
3function _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; }
4function _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; }
5import React from 'react';
6import PropTypes from 'prop-types';
7import classNames from 'classnames';
8import { mapToCssModules, tagPropType } from './utils';
9var propTypes = {
10 'aria-label': PropTypes.string,
11 children: PropTypes.node,
12 /** Add custom class */
13 className: PropTypes.string,
14 /** Change underlying component's CSS base class name */
15 cssModule: PropTypes.object,
16 /** Add to next button to add default aria label and icon */
17 next: PropTypes.bool,
18 /** Add to previous button to add default aria label and icon */
19 previous: PropTypes.bool,
20 /** Add to first button to add default aria label and icon */
21 first: PropTypes.bool,
22 /** Add to last button to add default aria label and icon */
23 last: PropTypes.bool,
24 /** Set a custom element for this component */
25 tag: tagPropType
26};
27function 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 = [/*#__PURE__*/React.createElement("span", {
68 "aria-hidden": "true",
69 key: "caret"
70 }, children || defaultCaret), /*#__PURE__*/React.createElement("span", {
71 className: "visually-hidden",
72 key: "ariaLabel"
73 }, ariaLabel)];
74 }
75 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
76 className: classes,
77 "aria-label": ariaLabel
78 }), children);
79}
80PaginationLink.propTypes = propTypes;
81export default PaginationLink;
\No newline at end of file