UNPKG

4.62 kBJavaScriptView Raw
1/**
2 * Copyright (c) 2013-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 */
8
9'use strict';
10
11var _assign = require('object-assign');
12
13function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
15function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
16
17function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
18
19var React = require('./React');
20var propTypesFactory = require('prop-types/factory');
21var PropTypes = propTypesFactory(React.isValidElement);
22
23var ReactTransitionGroup = require('./ReactTransitionGroup');
24var ReactCSSTransitionGroupChild = require('./ReactCSSTransitionGroupChild');
25
26function createTransitionTimeoutPropValidator(transitionType) {
27 var timeoutPropName = 'transition' + transitionType + 'Timeout';
28 var enabledPropName = 'transition' + transitionType;
29
30 return function (props) {
31 // If the transition is enabled
32 if (props[enabledPropName]) {
33 // If no timeout duration is provided
34 if (props[timeoutPropName] == null) {
35 return new Error(timeoutPropName + " wasn't supplied to ReactCSSTransitionGroup: " + "this can cause unreliable animations and won't be supported in " + 'a future version of React. See ' + 'https://fb.me/react-animation-transition-group-timeout for more ' + 'information.');
36
37 // If the duration isn't a number
38 } else if (typeof props[timeoutPropName] !== 'number') {
39 return new Error(timeoutPropName + ' must be a number (in milliseconds)');
40 }
41 }
42 };
43}
44
45/**
46 * An easy way to perform CSS transitions and animations when a React component
47 * enters or leaves the DOM.
48 * See https://facebook.github.io/react/docs/animation.html#high-level-api-reactcsstransitiongroup
49 */
50
51var ReactCSSTransitionGroup = function (_React$Component) {
52 _inherits(ReactCSSTransitionGroup, _React$Component);
53
54 function ReactCSSTransitionGroup() {
55 var _temp, _this, _ret;
56
57 _classCallCheck(this, ReactCSSTransitionGroup);
58
59 for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
60 args[_key] = arguments[_key];
61 }
62
63 return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this._wrapChild = function (child) {
64 // We need to provide this childFactory so that
65 // ReactCSSTransitionGroupChild can receive updates to name, enter, and
66 // leave while it is leaving.
67 return React.createElement(ReactCSSTransitionGroupChild, {
68 name: _this.props.transitionName,
69 appear: _this.props.transitionAppear,
70 enter: _this.props.transitionEnter,
71 leave: _this.props.transitionLeave,
72 appearTimeout: _this.props.transitionAppearTimeout,
73 enterTimeout: _this.props.transitionEnterTimeout,
74 leaveTimeout: _this.props.transitionLeaveTimeout
75 }, child);
76 }, _temp), _possibleConstructorReturn(_this, _ret);
77 }
78
79 ReactCSSTransitionGroup.prototype.render = function render() {
80 return React.createElement(ReactTransitionGroup, _assign({}, this.props, { childFactory: this._wrapChild }));
81 };
82
83 return ReactCSSTransitionGroup;
84}(React.Component);
85
86ReactCSSTransitionGroup.displayName = 'ReactCSSTransitionGroup';
87ReactCSSTransitionGroup.propTypes = {
88 transitionName: ReactCSSTransitionGroupChild.propTypes.name,
89
90 transitionAppear: PropTypes.bool,
91 transitionEnter: PropTypes.bool,
92 transitionLeave: PropTypes.bool,
93 transitionAppearTimeout: createTransitionTimeoutPropValidator('Appear'),
94 transitionEnterTimeout: createTransitionTimeoutPropValidator('Enter'),
95 transitionLeaveTimeout: createTransitionTimeoutPropValidator('Leave')
96};
97ReactCSSTransitionGroup.defaultProps = {
98 transitionAppear: false,
99 transitionEnter: true,
100 transitionLeave: true
101};
102
103
104module.exports = ReactCSSTransitionGroup;
\No newline at end of file