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

ReplaceTransition.js 5.0KB

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