UNPKG

wix-style-react

Version:
114 lines (88 loc) 4.48 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.SlideDirection = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _reactTransitionGroup = require('react-transition-group'); var _SlideInAnimation = require('./SlideInAnimation.scss'); var _SlideInAnimation2 = _interopRequireDefault(_SlideInAnimation); var _SlideOutAnimation = require('./SlideOutAnimation.scss'); var _SlideOutAnimation2 = _interopRequireDefault(_SlideOutAnimation); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _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; } function _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; } var SlideDirection = exports.SlideDirection = { in: 'in', out: 'out' }; var animationDuration = 300; // Synced with SlideAnimation.scss file var SlideAnimation = function (_Component) { _inherits(SlideAnimation, _Component); function SlideAnimation() { _classCallCheck(this, SlideAnimation); return _possibleConstructorReturn(this, (SlideAnimation.__proto__ || Object.getPrototypeOf(SlideAnimation)).apply(this, arguments)); } _createClass(SlideAnimation, [{ key: 'render', value: function render() { var _props = this.props, isVisible = _props.isVisible, animateAppear = _props.animateAppear, animateEnter = _props.animateEnter, animateLeave = _props.animateLeave, children = _props.children, direction = _props.direction, onEnter = _props.onEnter, onExit = _props.onExit, onEntered = _props.onEntered, onExited = _props.onExited; var transitionNames = direction === SlideDirection.in ? _SlideInAnimation2.default : _SlideOutAnimation2.default; var childTimeout = { enter: animateEnter ? animationDuration : 0, exit: animateLeave ? animationDuration : 0 }; return _react2.default.createElement( _reactTransitionGroup.CSSTransition, { 'in': isVisible, appear: animateAppear, exit: animateLeave, classNames: transitionNames, timeout: childTimeout, unmountOnExit: true, onEnter: onEnter, onExit: onExit, onEntered: onEntered, onExited: onExited }, children || _react2.default.createElement('span', null) ); } }]); return SlideAnimation; }(_react.Component); SlideAnimation.propTypes = { isVisible: _propTypes.bool.isRequired, direction: (0, _propTypes.oneOf)([SlideDirection.in, SlideDirection.out]), animateAppear: _propTypes.bool, animateEnter: _propTypes.bool, animateLeave: _propTypes.bool, children: _propTypes.node, onEnter: _propTypes.func, onEntered: _propTypes.func, onExit: _propTypes.func, onExited: _propTypes.func }; SlideAnimation.defaultProps = { direction: SlideDirection.in, animateAppear: true, animateEnter: true, animateLeave: true, children: null }; exports.default = SlideAnimation;