UNPKG

2.75 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _extends = Object.assign || 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; };
8
9var _react = require('react');
10
11var _react2 = _interopRequireDefault(_react);
12
13var _propTypes = require('prop-types');
14
15var _propTypes2 = _interopRequireDefault(_propTypes);
16
17var _classnames = require('classnames');
18
19var _classnames2 = _interopRequireDefault(_classnames);
20
21var _utils = require('./utils');
22
23function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
25function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
26
27var propTypes = {
28 'aria-label': _propTypes2.default.string,
29 children: _propTypes2.default.node,
30 className: _propTypes2.default.string,
31 cssModule: _propTypes2.default.object,
32 next: _propTypes2.default.bool,
33 previous: _propTypes2.default.bool,
34 tag: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.string])
35};
36
37var defaultProps = {
38 tag: 'a'
39};
40
41var PaginationLink = function PaginationLink(props) {
42 var className = props.className,
43 cssModule = props.cssModule,
44 next = props.next,
45 previous = props.previous,
46 Tag = props.tag,
47 attributes = _objectWithoutProperties(props, ['className', 'cssModule', 'next', 'previous', 'tag']);
48
49 var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, 'page-link'), cssModule);
50
51 var defaultAriaLabel = void 0;
52 if (previous) {
53 defaultAriaLabel = 'Previous';
54 } else if (next) {
55 defaultAriaLabel = 'Next';
56 }
57 var ariaLabel = props['aria-label'] || defaultAriaLabel;
58
59 var defaultCaret = void 0;
60 if (previous) {
61 defaultCaret = '\xAB';
62 } else if (next) {
63 defaultCaret = '\xBB';
64 }
65
66 var children = props.children;
67 if (previous || next) {
68 children = [_react2.default.createElement(
69 'span',
70 {
71 'aria-hidden': 'true',
72 key: 'caret'
73 },
74 children || defaultCaret
75 ), _react2.default.createElement(
76 'span',
77 {
78 className: 'sr-only',
79 key: 'sr'
80 },
81 ariaLabel
82 )];
83 }
84
85 return _react2.default.createElement(
86 Tag,
87 _extends({}, attributes, {
88 className: classes,
89 'aria-label': ariaLabel
90 }),
91 children
92 );
93};
94
95PaginationLink.propTypes = propTypes;
96PaginationLink.defaultProps = defaultProps;
97
98exports.default = PaginationLink;
\No newline at end of file