UNPKG

4.01 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _react = _interopRequireDefault(require("react"));
8var _propTypes = _interopRequireDefault(require("prop-types"));
9var _classnames = _interopRequireDefault(require("classnames"));
10var _utils = require("./utils");
11const _excluded = ["className", "cssModule", "next", "previous", "first", "last", "tag"];
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13function _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); }
14function _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; }
15function _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; }
16const propTypes = {
17 'aria-label': _propTypes.default.string,
18 children: _propTypes.default.node,
19 /** Add custom class */
20 className: _propTypes.default.string,
21 /** Change underlying component's CSS base class name */
22 cssModule: _propTypes.default.object,
23 /** Add to next button to add default aria label and icon */
24 next: _propTypes.default.bool,
25 /** Add to previous button to add default aria label and icon */
26 previous: _propTypes.default.bool,
27 /** Add to first button to add default aria label and icon */
28 first: _propTypes.default.bool,
29 /** Add to last button to add default aria label and icon */
30 last: _propTypes.default.bool,
31 /** Set a custom element for this component */
32 tag: _utils.tagPropType
33};
34function 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 = [/*#__PURE__*/_react.default.createElement("span", {
78 "aria-hidden": "true",
79 key: "caret"
80 }, children || defaultCaret), /*#__PURE__*/_react.default.createElement("span", {
81 className: "visually-hidden",
82 key: "ariaLabel"
83 }, ariaLabel)];
84 }
85 return /*#__PURE__*/_react.default.createElement(Tag, _extends({}, attributes, {
86 className: classes,
87 "aria-label": ariaLabel
88 }), children);
89}
90PaginationLink.propTypes = propTypes;
91var _default = PaginationLink;
92exports.default = _default;
\No newline at end of file