"use strict"; exports.__esModule = true; exports.default = void 0; var PropTypes = _interopRequireWildcard(require("prop-types")); var _addClass = _interopRequireDefault(require("dom-helpers/class/addClass")); var _removeClass = _interopRequireDefault(require("dom-helpers/class/removeClass")); var _react = _interopRequireDefault(require("react")); var _Transition = _interopRequireDefault(require("./Transition")); var _PropTypes = require("./utils/PropTypes"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } function _extends() { _extends = Object.assign || 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); } var addClass = function addClass(node, classes) { return node && classes && classes.split(' ').forEach(function (c) { return (0, _addClass.default)(node, c); }); }; var removeClass = function removeClass(node, classes) { return node && classes && classes.split(' ').forEach(function (c) { return (0, _removeClass.default)(node, c); }); }; var propTypes = process.env.NODE_ENV !== "production" ? _extends({}, _Transition.default.propTypes, { /** * The animation classNames applied to the component as it enters, exits or has finished the transition. * A single name can be provided and it will be suffixed for each stage: e.g. * * `classNames="fade"` applies `fade-enter`, `fade-enter-active`, `fade-enter-done`, * `fade-exit`, `fade-exit-active`, `fade-exit-done`, `fade-appear`, and `fade-appear-active`. * Each individual classNames can also be specified independently like: * * ```js * classNames={{ * appear: 'my-appear', * appearActive: 'my-active-appear', * enter: 'my-enter', * enterActive: 'my-active-enter', * enterDone: 'my-done-enter', * exit: 'my-exit', * exitActive: 'my-active-exit', * exitDone: 'my-done-exit', * }} * ``` * * If you want to set these classes using CSS Modules: * * ```js * import styles from './styles.css'; * ``` * * you might want to use camelCase in your CSS file, that way could simply spread * them instead of listing them one by one: * * ```js * classNames={{ ...styles }} * ``` * * @type {string | { * appear?: string, * appearActive?: string, * enter?: string, * enterActive?: string, * enterDone?: string, * exit?: string, * exitActive?: string, * exitDone?: string, * }} */ classNames: _PropTypes.classNamesShape, /** * A `` callback fired immediately after the 'enter' or 'appear' class is * applied. * * @type Function(node: HtmlElement, isAppearing: bool) */ onEnter: PropTypes.func, /** * A `` callback fired immediately after the 'enter-active' or * 'appear-active' class is applied. * * @type Function(node: HtmlElement, isAppearing: bool) */ onEntering: PropTypes.func, /** * A `` callback fired immediately after the 'enter' or * 'appear' classes are **removed** and the `done` class is added to the DOM node. * * @type Function(node: HtmlElement, isAppearing: bool) */ onEntered: PropTypes.func, /** * A `` callback fired immediately after the 'exit' class is * applied. * * @type Function(node: HtmlElement) */ onExit: PropTypes.func, /** * A `` callback fired immediately after the 'exit-active' is applied. * * @type Function(node: HtmlElement */ onExiting: PropTypes.func, /** * A `` callback fired immediately after the 'exit' classes * are **removed** and the `exit-done` class is added to the DOM node. * * @type Function(node: HtmlElement) */ onExited: PropTypes.func }) : {};; /** * A `Transition` component using CSS transitions and animations. * It's inspired by the excellent [ng-animate](http://www.nganimate.org/) library. * * `CSSTransition` applies a pair of class names during the `appear`, `enter`, * and `exit` stages of the transition. The first class is applied and then a * second "active" class in order to activate the css animation. After the animation, * matching `done` class names are applied to persist the animation state. * * When the `in` prop is toggled to `true` the Component will get * the `example-enter` CSS class and the `example-enter-active` CSS class * added in the next tick. This is a convention based on the `classNames` prop. */ var CSSTransition = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(CSSTransition, _React$Component); function CSSTransition() { var _this; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this; _this.onEnter = function (node, appearing) { var _this$getClassNames = _this.getClassNames(appearing ? 'appear' : 'enter'), className = _this$getClassNames.className; _this.removeClasses(node, 'exit'); addClass(node, className); if (_this.props.onEnter) { _this.props.onEnter(node); } }; _this.onEntering = function (node, appearing) { var _this$getClassNames2 = _this.getClassNames(appearing ? 'appear' : 'enter'), activeClassName = _this$getClassNames2.activeClassName; _this.reflowAndAddClass(node, activeClassName); if (_this.props.onEntering) { _this.props.onEntering(node); } }; _this.onEntered = function (node, appearing) { var _this$getClassNames3 = _this.getClassNames('enter'), doneClassName = _this$getClassNames3.doneClassName; _this.removeClasses(node, appearing ? 'appear' : 'enter'); addClass(node, doneClassName); if (_this.props.onEntered) { _this.props.onEntered(node); } }; _this.onExit = function (node) { var _this$getClassNames4 = _this.getClassNames('exit'), className = _this$getClassNames4.className; _this.removeClasses(node, 'appear'); _this.removeClasses(node, 'enter'); addClass(node, className); if (_this.props.onExit) { _this.props.onExit(node); } }; _this.onExiting = function (node) { var _this$getClassNames5 = _this.getClassNames('exit'), activeClassName = _this$getClassNames5.activeClassName; _this.reflowAndAddClass(node, activeClassName); if (_this.props.onExiting) { _this.props.onExiting(node); } }; _this.onExited = function (node) { var _this$getClassNames6 = _this.getClassNames('exit'), doneClassName = _this$getClassNames6.doneClassName; _this.removeClasses(node, 'exit'); addClass(node, doneClassName); if (_this.props.onExited) { _this.props.onExited(node); } }; _this.getClassNames = function (type) { var classNames = _this.props.classNames; var className = typeof classNames !== 'string' ? classNames[type] : classNames + '-' + type; var activeClassName = typeof classNames !== 'string' ? classNames[type + 'Active'] : className + '-active'; var doneClassName = typeof classNames !== 'string' ? classNames[type + 'Done'] : className + '-done'; return { className: className, activeClassName: activeClassName, doneClassName: doneClassName }; }; return _this; } var _proto = CSSTransition.prototype; _proto.removeClasses = function removeClasses(node, type) { var _this$getClassNames7 = this.getClassNames(type), className = _this$getClassNames7.className, activeClassName = _this$getClassNames7.activeClassName, doneClassName = _this$getClassNames7.doneClassName; className && removeClass(node, className); activeClassName && removeClass(node, activeClassName); doneClassName && removeClass(node, doneClassName); }; _proto.reflowAndAddClass = function reflowAndAddClass(node, className) { // This is for to force a repaint, // which is necessary in order to transition styles when adding a class name. if (className) { /* eslint-disable no-unused-expressions */ node && node.scrollTop; /* eslint-enable no-unused-expressions */ addClass(node, className); } }; _proto.render = function render() { var props = _extends({}, this.props); delete props.classNames; return _react.default.createElement(_Transition.default, _extends({}, props, { onEnter: this.onEnter, onEntered: this.onEntered, onEntering: this.onEntering, onExit: this.onExit, onExiting: this.onExiting, onExited: this.onExited })); }; return CSSTransition; }(_react.default.Component); CSSTransition.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {}; var _default = CSSTransition; exports.default = _default; module.exports = exports["default"];