UNPKG

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