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

ReplaceTransition.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
  2. import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
  3. import PropTypes from 'prop-types';
  4. import React from 'react';
  5. import ReactDOM from 'react-dom';
  6. import TransitionGroup from './TransitionGroup';
  7. /**
  8. * The `<ReplaceTransition>` component is a specialized `Transition` component
  9. * that animates between two children.
  10. *
  11. * ```jsx
  12. * <ReplaceTransition in>
  13. * <Fade><div>I appear first</div></Fade>
  14. * <Fade><div>I replace the above</div></Fade>
  15. * </ReplaceTransition>
  16. * ```
  17. */
  18. var ReplaceTransition =
  19. /*#__PURE__*/
  20. function (_React$Component) {
  21. _inheritsLoose(ReplaceTransition, _React$Component);
  22. function ReplaceTransition() {
  23. var _this;
  24. for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
  25. _args[_key] = arguments[_key];
  26. }
  27. _this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
  28. _this.handleEnter = function () {
  29. for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  30. args[_key2] = arguments[_key2];
  31. }
  32. return _this.handleLifecycle('onEnter', 0, args);
  33. };
  34. _this.handleEntering = function () {
  35. for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  36. args[_key3] = arguments[_key3];
  37. }
  38. return _this.handleLifecycle('onEntering', 0, args);
  39. };
  40. _this.handleEntered = function () {
  41. for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
  42. args[_key4] = arguments[_key4];
  43. }
  44. return _this.handleLifecycle('onEntered', 0, args);
  45. };
  46. _this.handleExit = function () {
  47. for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
  48. args[_key5] = arguments[_key5];
  49. }
  50. return _this.handleLifecycle('onExit', 1, args);
  51. };
  52. _this.handleExiting = function () {
  53. for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
  54. args[_key6] = arguments[_key6];
  55. }
  56. return _this.handleLifecycle('onExiting', 1, args);
  57. };
  58. _this.handleExited = function () {
  59. for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
  60. args[_key7] = arguments[_key7];
  61. }
  62. return _this.handleLifecycle('onExited', 1, args);
  63. };
  64. return _this;
  65. }
  66. var _proto = ReplaceTransition.prototype;
  67. _proto.handleLifecycle = function handleLifecycle(handler, idx, originalArgs) {
  68. var _child$props;
  69. var children = this.props.children;
  70. var child = React.Children.toArray(children)[idx];
  71. if (child.props[handler]) (_child$props = child.props)[handler].apply(_child$props, originalArgs);
  72. if (this.props[handler]) this.props[handler](ReactDOM.findDOMNode(this));
  73. };
  74. _proto.render = function render() {
  75. var _this$props = this.props,
  76. children = _this$props.children,
  77. inProp = _this$props.in,
  78. props = _objectWithoutPropertiesLoose(_this$props, ["children", "in"]);
  79. var _React$Children$toArr = React.Children.toArray(children),
  80. first = _React$Children$toArr[0],
  81. second = _React$Children$toArr[1];
  82. delete props.onEnter;
  83. delete props.onEntering;
  84. delete props.onEntered;
  85. delete props.onExit;
  86. delete props.onExiting;
  87. delete props.onExited;
  88. return React.createElement(TransitionGroup, props, inProp ? React.cloneElement(first, {
  89. key: 'first',
  90. onEnter: this.handleEnter,
  91. onEntering: this.handleEntering,
  92. onEntered: this.handleEntered
  93. }) : React.cloneElement(second, {
  94. key: 'second',
  95. onEnter: this.handleExit,
  96. onEntering: this.handleExiting,
  97. onEntered: this.handleExited
  98. }));
  99. };
  100. return ReplaceTransition;
  101. }(React.Component);
  102. ReplaceTransition.propTypes = process.env.NODE_ENV !== "production" ? {
  103. in: PropTypes.bool.isRequired,
  104. children: function children(props, propName) {
  105. if (React.Children.count(props[propName]) !== 2) return new Error("\"" + propName + "\" must be exactly two transition components.");
  106. return null;
  107. }
  108. } : {};
  109. export default ReplaceTransition;