您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PaginationLink.js 1.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  3. import React from 'react';
  4. import PropTypes from 'prop-types';
  5. import classNames from 'classnames';
  6. import { mapToCssModules, tagPropType } from './utils';
  7. var propTypes = {
  8. 'aria-label': PropTypes.string,
  9. children: PropTypes.node,
  10. className: PropTypes.string,
  11. cssModule: PropTypes.object,
  12. next: PropTypes.bool,
  13. previous: PropTypes.bool,
  14. tag: tagPropType
  15. };
  16. var defaultProps = {
  17. tag: 'a'
  18. };
  19. var PaginationLink = function PaginationLink(props) {
  20. var className = props.className,
  21. cssModule = props.cssModule,
  22. next = props.next,
  23. previous = props.previous,
  24. Tag = props.tag,
  25. attributes = _objectWithoutPropertiesLoose(props, ["className", "cssModule", "next", "previous", "tag"]);
  26. var classes = mapToCssModules(classNames(className, 'page-link'), cssModule);
  27. var defaultAriaLabel;
  28. if (previous) {
  29. defaultAriaLabel = 'Previous';
  30. } else if (next) {
  31. defaultAriaLabel = 'Next';
  32. }
  33. var ariaLabel = props['aria-label'] || defaultAriaLabel;
  34. var defaultCaret;
  35. if (previous) {
  36. defaultCaret = "\xAB";
  37. } else if (next) {
  38. defaultCaret = "\xBB";
  39. }
  40. var children = props.children;
  41. if (children && Array.isArray(children) && children.length === 0) {
  42. children = null;
  43. }
  44. if (!attributes.href && Tag === 'a') {
  45. Tag = 'button';
  46. }
  47. if (previous || next) {
  48. children = [React.createElement("span", {
  49. "aria-hidden": "true",
  50. key: "caret"
  51. }, children || defaultCaret), React.createElement("span", {
  52. className: "sr-only",
  53. key: "sr"
  54. }, ariaLabel)];
  55. }
  56. return React.createElement(Tag, _extends({}, attributes, {
  57. className: classes,
  58. "aria-label": ariaLabel
  59. }), children);
  60. };
  61. PaginationLink.propTypes = propTypes;
  62. PaginationLink.defaultProps = defaultProps;
  63. export default PaginationLink;