UNPKG

2.82 kBJavaScriptView Raw
1import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
4
5var _fadeStyles;
6
7import classNames from 'classnames';
8import React from 'react';
9import PropTypes from 'prop-types';
10import Transition, { ENTERED, ENTERING } from 'react-transition-group/Transition';
11var propTypes = {
12 /**
13 * Show the component; triggers the fade in or fade out animation
14 */
15 in: PropTypes.bool,
16
17 /**
18 * Wait until the first "enter" transition to mount the component (add it to the DOM)
19 */
20 mountOnEnter: PropTypes.bool,
21
22 /**
23 * Unmount the component (remove it from the DOM) when it is faded out
24 */
25 unmountOnExit: PropTypes.bool,
26
27 /**
28 * Run the fade in animation when the component mounts, if it is initially
29 * shown
30 */
31 appear: PropTypes.bool,
32
33 /**
34 * Duration of the fade animation in milliseconds, to ensure that finishing
35 * callbacks are fired even if the original browser transition end events are
36 * canceled
37 */
38 timeout: PropTypes.number,
39
40 /**
41 * Callback fired before the component fades in
42 */
43 onEnter: PropTypes.func,
44
45 /**
46 * Callback fired after the component starts to fade in
47 */
48 onEntering: PropTypes.func,
49
50 /**
51 * Callback fired after the has component faded in
52 */
53 onEntered: PropTypes.func,
54
55 /**
56 * Callback fired before the component fades out
57 */
58 onExit: PropTypes.func,
59
60 /**
61 * Callback fired after the component starts to fade out
62 */
63 onExiting: PropTypes.func,
64
65 /**
66 * Callback fired after the component has faded out
67 */
68 onExited: PropTypes.func
69};
70var defaultProps = {
71 in: false,
72 timeout: 300,
73 mountOnEnter: false,
74 unmountOnExit: false,
75 appear: false
76};
77var fadeStyles = (_fadeStyles = {}, _fadeStyles[ENTERING] = 'in', _fadeStyles[ENTERED] = 'in', _fadeStyles);
78
79var Fade =
80/*#__PURE__*/
81function (_React$Component) {
82 _inheritsLoose(Fade, _React$Component);
83
84 function Fade() {
85 return _React$Component.apply(this, arguments) || this;
86 }
87
88 var _proto = Fade.prototype;
89
90 _proto.render = function render() {
91 var _this$props = this.props,
92 className = _this$props.className,
93 children = _this$props.children,
94 props = _objectWithoutPropertiesLoose(_this$props, ["className", "children"]);
95
96 return React.createElement(Transition, props, function (status, innerProps) {
97 return React.cloneElement(children, _extends({}, innerProps, {
98 className: classNames('fade', className, children.props.className, fadeStyles[status])
99 }));
100 });
101 };
102
103 return Fade;
104}(React.Component);
105
106Fade.propTypes = propTypes;
107Fade.defaultProps = defaultProps;
108export default Fade;
\No newline at end of file