diff --git a/lib/shuffle.js b/lib/shuffle.js index 7e5b90d..115ec38 100644 --- a/lib/shuffle.js +++ b/lib/shuffle.js @@ -26,12 +26,20 @@ var _reactAddonsTransitionGroup = require('react-addons-transition-group'); var _reactAddonsTransitionGroup2 = _interopRequireDefault(_reactAddonsTransitionGroup); +var _createReactClass = require('create-react-class'); + +var _createReactClass2 = _interopRequireDefault(_createReactClass); + +var _propTypes = require('prop-types'); + +var _propTypes2 = _interopRequireDefault(_propTypes); + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } /* eslint no-unused-vars:0 */ /*global window, document, getComputedStyle*/ -var Clones = _react2.default.createClass({ +var Clones = (0, _createReactClass2.default)({ displayName: 'ShuffleClones', _childrenWithPositions: function _childrenWithPositions() { @@ -67,7 +75,7 @@ var Clones = _react2.default.createClass({ } }); -var Clone = _react2.default.createClass({ +var Clone = (0, _createReactClass2.default)({ mixins: [_reactTweenState2.default.Mixin], displayName: 'ShuffleClone', getInitialState: function getInitialState() { @@ -141,15 +149,15 @@ var Clone = _react2.default.createClass({ } }); -var Shuffle = _react2.default.createClass({ +var Shuffle = (0, _createReactClass2.default)({ displayName: 'Shuffle', propTypes: { - duration: _react2.default.PropTypes.number, - scale: _react2.default.PropTypes.bool, - fade: _react2.default.PropTypes.bool, - initial: _react2.default.PropTypes.bool + duration: _propTypes2.default.number, + scale: _propTypes2.default.bool, + fade: _propTypes2.default.bool, + initial: _propTypes2.default.bool }, getDefaultProps: function getDefaultProps() { @@ -171,6 +179,7 @@ var Shuffle = _react2.default.createClass({ window.addEventListener('resize', this._renderClonesInitially); }, componentWillUnmount: function componentWillUnmount() { + clearTimeout(this._timeout); _reactDom2.default.unmountComponentAtNode(this._portalNode); _reactDom2.default.findDOMNode(this.refs.container).removeChild(this._portalNode); window.removeEventListener('resize', this._renderClonesInitially); @@ -197,7 +206,8 @@ var Shuffle = _react2.default.createClass({ _reactDom2.default.findDOMNode(this.refs.container).appendChild(this._portalNode); }, _addTransitionEndEvent: function _addTransitionEndEvent() { - setTimeout(this._finishAnimation, this.props.duration); + clearTimeout(this._timeout); + this._timeout = setTimeout(this._finishAnimation, this.props.duration); }, _startAnimation: function _startAnimation(nextProps) { var _this3 = this; @@ -280,6 +290,7 @@ var Shuffle = _react2.default.createClass({ duration = _props.duration, props = _objectWithoutProperties(_props, ['initial', 'fade', 'duration']); + props.scale = !!this.props.scale + ''; var showContainer = initial ? 0 : 1; if (this.state.ready) { showContainer = 0; diff --git a/package.json b/package.json index f29b5fc..611a81b 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,11 @@ "main": "index.js", "dependencies": { "babel-plugin-transform-object-rest-spread": "^6.16.0", + "create-react-class": "^15.5.3", "object-assign": "^4.0.1", + "prop-types": "^15.5.10", "react-addons-transition-group": "^15.0.0 || ^0.14.0", + "react-tween-state": "^0.1.5" }, "peerDependencies": { diff --git a/src/shuffle.js b/src/shuffle.js index 04bd685..995d798 100644 --- a/src/shuffle.js +++ b/src/shuffle.js @@ -6,8 +6,10 @@ import ReactDom from 'react-dom'; import assign from 'object-assign'; import tweenState from 'react-tween-state'; import ReactTransitionGroup from 'react-addons-transition-group'; +import createReactClass from 'create-react-class' +import PropTypes from 'prop-types'; -const Clones = React.createClass({ +const Clones = createReactClass({ displayName: 'ShuffleClones', _childrenWithPositions() { @@ -40,7 +42,7 @@ const Clones = React.createClass({ } }); -const Clone = React.createClass({ +const Clone = createReactClass({ mixins: [tweenState.Mixin], displayName: 'ShuffleClone', getInitialState() { @@ -116,15 +118,15 @@ const Clone = React.createClass({ } }) -const Shuffle = React.createClass({ +const Shuffle = createReactClass({ displayName: 'Shuffle', propTypes: { - duration: React.PropTypes.number, - scale: React.PropTypes.bool, - fade: React.PropTypes.bool, - initial: React.PropTypes.bool + duration: PropTypes.number, + scale: PropTypes.bool, + fade: PropTypes.bool, + initial: PropTypes.bool }, getDefaultProps() { @@ -149,6 +151,7 @@ const Shuffle = React.createClass({ }, componentWillUnmount() { + clearTimeout(this._timeout); ReactDom.unmountComponentAtNode(this._portalNode); ReactDom.findDOMNode(this.refs.container).removeChild(this._portalNode); window.removeEventListener('resize', this._renderClonesInitially); @@ -177,7 +180,8 @@ const Shuffle = React.createClass({ }, _addTransitionEndEvent() { - setTimeout(this._finishAnimation, this.props.duration); + clearTimeout(this._timeout); + this._timeout = setTimeout(this._finishAnimation, this.props.duration); }, _startAnimation(nextProps) { @@ -259,6 +263,7 @@ const Shuffle = React.createClass({ render() { let { initial, fade, duration, ...props } = this.props; + props.scale = (!!this.props.scale)+''; var showContainer = initial ? 0 : 1; if (this.state.ready) { showContainer = 0;