UNPKG

wix-style-react

Version:
95 lines (79 loc) 3.85 kB
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; }; }(); 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; } import React, { Component } from 'react'; import { node, bool, oneOf, func } from 'prop-types'; import { CSSTransition } from 'react-transition-group'; import slideIn from './SlideInAnimation.scss'; import slideOut from './SlideOutAnimation.scss'; export var 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 ? slideIn : slideOut; var childTimeout = { enter: animateEnter ? animationDuration : 0, exit: animateLeave ? animationDuration : 0 }; return React.createElement( CSSTransition, { 'in': isVisible, appear: animateAppear, exit: animateLeave, classNames: transitionNames, timeout: childTimeout, unmountOnExit: true, onEnter: onEnter, onExit: onExit, onEntered: onEntered, onExited: onExited }, children || React.createElement('span', null) ); } }]); return SlideAnimation; }(Component); SlideAnimation.propTypes = { isVisible: bool.isRequired, direction: oneOf([SlideDirection.in, SlideDirection.out]), animateAppear: bool, animateEnter: bool, animateLeave: bool, children: node, onEnter: func, onEntered: func, onExit: func, onExited: func }; SlideAnimation.defaultProps = { direction: SlideDirection.in, animateAppear: true, animateEnter: true, animateLeave: true, children: null }; export default SlideAnimation;