1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 |
|
4 | import React, { useCallback, useEffect, useState } from 'react';
|
5 | import { Transition } from 'react-transition-group';
|
6 | import classNames from 'classnames';
|
7 |
|
8 | var OverlayAnimate = function OverlayAnimate(props) {
|
9 | var animation = props.animation,
|
10 | visible = props.visible,
|
11 | children = props.children,
|
12 | _props$timeout = props.timeout,
|
13 | timeout = _props$timeout === undefined ? 300 : _props$timeout,
|
14 | style = props.style,
|
15 | mountOnEnter = props.mountOnEnter,
|
16 | unmountOnExit = props.unmountOnExit,
|
17 | appear = props.appear,
|
18 | enter = props.enter,
|
19 | exit = props.exit,
|
20 | onEnter = props.onEnter,
|
21 | onEntering = props.onEntering,
|
22 | onEntered = props.onEntered,
|
23 | onExit = props.onExit,
|
24 | onExiting = props.onExiting,
|
25 | onExited = props.onExited,
|
26 | others = _objectWithoutProperties(props, ['animation', 'visible', 'children', 'timeout', 'style', 'mountOnEnter', 'unmountOnExit', 'appear', 'enter', 'exit', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited']);
|
27 |
|
28 | var animateProps = {
|
29 | mountOnEnter: mountOnEnter,
|
30 | unmountOnExit: unmountOnExit,
|
31 | appear: appear,
|
32 | enter: enter,
|
33 | exit: exit,
|
34 | onEnter: onEnter,
|
35 | onEntering: onEntering,
|
36 | onEntered: onEntered,
|
37 | onExit: onExit,
|
38 | onExiting: onExiting,
|
39 | onExited: onExited
|
40 | };
|
41 |
|
42 | Object.keys(animateProps).forEach(function (k) {
|
43 | if (!(k in props) || typeof props[k] === 'undefined') {
|
44 | delete animateProps[k];
|
45 | }
|
46 | });
|
47 |
|
48 | var animationMap = typeof animation === 'string' ? { in: animation, out: animation } : animation;
|
49 |
|
50 | var animateClsMap = animation ? {
|
51 | entering: animationMap.in,
|
52 | exiting: animationMap.out
|
53 | } : {};
|
54 |
|
55 | if (animation === false) {
|
56 | animateClsMap.entering = '';
|
57 | animateClsMap.exiting = '';
|
58 | }
|
59 |
|
60 | return React.createElement(
|
61 | Transition,
|
62 | _extends({}, animateProps, { 'in': visible, timeout: animation ? timeout : 0, appear: true }),
|
63 | function (state) {
|
64 | var _classNames;
|
65 |
|
66 | var cls = classNames((_classNames = {}, _classNames[children.props.className] = !!children.props.className, _classNames[animateClsMap[state]] = state in animateClsMap && animateClsMap[state], _classNames));
|
67 |
|
68 | var childProps = _extends({}, others, {
|
69 | className: cls
|
70 | });
|
71 |
|
72 | if (style && children.props && children.props.style) {
|
73 | childProps.style = _extends({}, children.props.style, style);
|
74 | }
|
75 |
|
76 | return React.cloneElement(children, childProps);
|
77 | }
|
78 | );
|
79 | };
|
80 |
|
81 | export default OverlayAnimate; |
\ | No newline at end of file |