UNPKG

react-mdc-web

Version:

React web components for Material Design

75 lines (55 loc) 3.42 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _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; }; 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 _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _react = require('react'); var _react2 = _interopRequireDefault(_react); 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 AnimationController = function AnimationController(WrappedComponent) { var _class, _temp; return _temp = _class = function (_PureComponent) { _inherits(_class, _PureComponent); function _class(props) { _classCallCheck(this, _class); var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this, props)); _this.state = {}; return _this; } _createClass(_class, [{ key: 'componentWillReceiveProps', value: function componentWillReceiveProps(_ref) { var nextOpen = _ref.open; var open = this.props.open; if (nextOpen !== open) { this.setState({ animation: true }); } } }, { key: 'finishAnimation', value: function finishAnimation() { this.setState({ animation: false }); } }, { key: 'render', value: function render() { var _this2 = this; return _react2.default.createElement(WrappedComponent, _extends({ onAnimationFinish: function onAnimationFinish() { _this2.finishAnimation(); } }, this.props, this.state)); } }]); return _class; }(_react.PureComponent), _class.propTypes = { open: _propTypes2.default.bool }, _temp; }; exports.default = AnimationController;