AnimateGroupChild.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. var _excluded = ["children", "appearOptions", "enterOptions", "leaveOptions"];
  2. function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
  3. function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
  4. function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  5. 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; }
  6. function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
  7. function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
  8. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  9. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
  10. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
  11. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
  12. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  13. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  14. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
  15. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  16. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
  17. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18. function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  19. function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
  20. function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
  21. import React, { Component, Children } from 'react';
  22. import { Transition } from 'react-transition-group';
  23. import PropTypes from 'prop-types';
  24. import Animate from './Animate';
  25. var parseDurationOfSingleTransition = function parseDurationOfSingleTransition() {
  26. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  27. var steps = options.steps,
  28. duration = options.duration;
  29. if (steps && steps.length) {
  30. return steps.reduce(function (result, entry) {
  31. return result + (Number.isFinite(entry.duration) && entry.duration > 0 ? entry.duration : 0);
  32. }, 0);
  33. }
  34. if (Number.isFinite(duration)) {
  35. return duration;
  36. }
  37. return 0;
  38. };
  39. var AnimateGroupChild = /*#__PURE__*/function (_Component) {
  40. _inherits(AnimateGroupChild, _Component);
  41. var _super = _createSuper(AnimateGroupChild);
  42. function AnimateGroupChild() {
  43. var _this;
  44. _classCallCheck(this, AnimateGroupChild);
  45. _this = _super.call(this);
  46. _defineProperty(_assertThisInitialized(_this), "handleEnter", function (node, isAppearing) {
  47. var _this$props = _this.props,
  48. appearOptions = _this$props.appearOptions,
  49. enterOptions = _this$props.enterOptions;
  50. _this.handleStyleActive(isAppearing ? appearOptions : enterOptions);
  51. });
  52. _defineProperty(_assertThisInitialized(_this), "handleExit", function () {
  53. var leaveOptions = _this.props.leaveOptions;
  54. _this.handleStyleActive(leaveOptions);
  55. });
  56. _this.state = {
  57. isActive: false
  58. };
  59. return _this;
  60. }
  61. _createClass(AnimateGroupChild, [{
  62. key: "handleStyleActive",
  63. value: function handleStyleActive(style) {
  64. if (style) {
  65. var onAnimationEnd = style.onAnimationEnd ? function () {
  66. style.onAnimationEnd();
  67. } : null;
  68. this.setState(_objectSpread(_objectSpread({}, style), {}, {
  69. onAnimationEnd: onAnimationEnd,
  70. isActive: true
  71. }));
  72. }
  73. }
  74. }, {
  75. key: "parseTimeout",
  76. value: function parseTimeout() {
  77. var _this$props2 = this.props,
  78. appearOptions = _this$props2.appearOptions,
  79. enterOptions = _this$props2.enterOptions,
  80. leaveOptions = _this$props2.leaveOptions;
  81. return parseDurationOfSingleTransition(appearOptions) + parseDurationOfSingleTransition(enterOptions) + parseDurationOfSingleTransition(leaveOptions);
  82. }
  83. }, {
  84. key: "render",
  85. value: function render() {
  86. var _this2 = this;
  87. var _this$props3 = this.props,
  88. children = _this$props3.children,
  89. appearOptions = _this$props3.appearOptions,
  90. enterOptions = _this$props3.enterOptions,
  91. leaveOptions = _this$props3.leaveOptions,
  92. props = _objectWithoutProperties(_this$props3, _excluded);
  93. return /*#__PURE__*/React.createElement(Transition, _extends({}, props, {
  94. onEnter: this.handleEnter,
  95. onExit: this.handleExit,
  96. timeout: this.parseTimeout()
  97. }), function () {
  98. return /*#__PURE__*/React.createElement(Animate, _this2.state, Children.only(children));
  99. });
  100. }
  101. }]);
  102. return AnimateGroupChild;
  103. }(Component);
  104. AnimateGroupChild.propTypes = {
  105. appearOptions: PropTypes.object,
  106. enterOptions: PropTypes.object,
  107. leaveOptions: PropTypes.object,
  108. children: PropTypes.element
  109. };
  110. export default AnimateGroupChild;