/*Downloaded from https://www.codeseek.co/0x1000/image-slide-show-in-react-using-react-motion-MjMYge */
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; }
var TransitionMotion = ReactMotion.TransitionMotion;
var spring = ReactMotion.spring;
var BackgroundImage = function (_React$Component) {
_inherits(BackgroundImage, _React$Component);
function BackgroundImage() {
_classCallCheck(this, BackgroundImage);
return _possibleConstructorReturn(this, (BackgroundImage.__proto__ || Object.getPrototypeOf(BackgroundImage)).apply(this, arguments));
}
_createClass(BackgroundImage, [{
key: 'render',
value: function render() {
var style = {
position: 'fixed',
top: 0,
margin: 0,
left: 0,
zIndex: -1000,
backgroundColor: ['red', 'green', 'blue', 'gray', 'black'][this.props.page],
width: '100%',
height: '100%',
transform: this.props.style.transform
};
return React.createElement('div', { key: this.props.page, style: style });
}
}]);
return BackgroundImage;
}(React.Component);
var Animation = function (_React$Component2) {
_inherits(Animation, _React$Component2);
function Animation(props) {
_classCallCheck(this, Animation);
var _this2 = _possibleConstructorReturn(this, (Animation.__proto__ || Object.getPrototypeOf(Animation)).call(this, props));
_this2.state = {
page: 0
};
return _this2;
}
_createClass(Animation, [{
key: 'handleChange',
value: function handleChange() {
console.log('changed: ' + this.state.page);
this.setState({ page: (this.state.page + 1) % 5 });
setTimeout(this.handleChange.bind(this), 2000);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
setTimeout(this.handleChange.bind(this), 2000);
}
}, {
key: 'willLeave',
value: function willLeave() {
return { x: spring(-100) };
}
}, {
key: 'willEnter',
value: function willEnter() {
return { x: 100 };
}
}, {
key: 'render',
value: function render() {
return React.createElement(
TransitionMotion,
{ willEnter: this.willEnter.bind(this), willLeave: this.willLeave.bind(this),
defaultStyles: [{
key: this.state.page,
style: {
x: -100
}
}],
styles: [{ key: this.state.page, style: { x: spring(0) } }]
},
function (interpolatingStyles) {
return React.createElement(
'div',
null,
' ',
interpolatingStyles.map(function (config) {
return React.createElement(BackgroundImage, { page: config.key, key: config.key, style: { transform: 'translateX(' + config.style.x + '%)' } });
})
);
}
);
}
}]);
return Animation;
}(React.Component);
ReactDOM.render(React.createElement(Animation, null), document.getElementById('react-mount-point'));