UNPKG

2.63 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 _classnames = require('classnames');
14
15var _classnames2 = _interopRequireDefault(_classnames);
16
17var _utils = require('./utils');
18
19function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21function _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; }
22
23var propTypes = {
24 'aria-label': _react.PropTypes.string,
25 children: _react.PropTypes.node,
26 className: _react.PropTypes.string,
27 cssModule: _react.PropTypes.object,
28 next: _react.PropTypes.bool,
29 previous: _react.PropTypes.bool,
30 tag: _react.PropTypes.oneOfType([_react.PropTypes.func, _react.PropTypes.string])
31};
32
33var defaultProps = {
34 tag: 'a'
35};
36
37var PaginationLink = function PaginationLink(props) {
38 var className = props.className,
39 cssModule = props.cssModule,
40 next = props.next,
41 previous = props.previous,
42 Tag = props.tag,
43 attributes = _objectWithoutProperties(props, ['className', 'cssModule', 'next', 'previous', 'tag']);
44
45 var classes = (0, _utils.mapToCssModules)((0, _classnames2.default)(className, 'page-link'), cssModule);
46
47 var defaultAriaLabel = void 0;
48 if (previous) {
49 defaultAriaLabel = 'Previous';
50 } else if (next) {
51 defaultAriaLabel = 'Next';
52 }
53 var ariaLabel = props['aria-label'] || defaultAriaLabel;
54
55 var defaultCaret = void 0;
56 if (previous) {
57 defaultCaret = '\xAB';
58 } else if (next) {
59 defaultCaret = '\xBB';
60 }
61
62 var children = props.children;
63 if (previous || next) {
64 children = [_react2.default.createElement(
65 'span',
66 {
67 'aria-hidden': 'true',
68 key: 'caret'
69 },
70 children || defaultCaret
71 ), _react2.default.createElement(
72 'span',
73 {
74 className: 'sr-only',
75 key: 'sr'
76 },
77 ariaLabel
78 )];
79 }
80
81 return _react2.default.createElement(
82 Tag,
83 _extends({}, attributes, {
84 className: classes,
85 'aria-label': ariaLabel
86 }),
87 children
88 );
89};
90
91PaginationLink.propTypes = propTypes;
92PaginationLink.defaultProps = defaultProps;
93
94exports.default = PaginationLink;
\No newline at end of file