From 8a05b3319093cefd2a1f44355835bb1b57625685 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Sat, 10 Oct 2015 17:36:00 -0300 Subject: [PATCH] [Ivan Diaz] - Add Widget transition component --- .../main-home/main-home-page-login-widget.js | 48 ++++-------- .../main-home-page-login-widget.scss | 7 ++ src/app/main/main-home/main-home-page.scss | 18 ----- src/core-components/widget-transition.js | 78 +++++++++++++++++++ src/core-components/widget-transition.scss | 11 +++ 5 files changed, 110 insertions(+), 52 deletions(-) create mode 100644 src/core-components/widget-transition.js create mode 100644 src/core-components/widget-transition.scss diff --git a/src/app/main/main-home/main-home-page-login-widget.js b/src/app/main/main-home/main-home-page-login-widget.js index 56867fe8..6210cde3 100644 --- a/src/app/main/main-home/main-home-page-login-widget.js +++ b/src/app/main/main-home/main-home-page-login-widget.js @@ -1,51 +1,35 @@ import React from 'react/addons'; import {ListenerMixin} from 'reflux'; -import {Motion, spring} from 'react-motion'; import UserActions from 'actions/user-actions'; import UserStore from 'stores/user-store'; -import Form from 'core-components/form'; -import Widget from 'core-components/widget'; -import Input from 'core-components/input'; import Button from 'core-components/button'; +import Form from 'core-components/form'; +import Input from 'core-components/input'; +import Widget from 'core-components/widget'; +import WidgetTransition from 'core-components/widget-transition'; var MainHomePageLoginWidget = React.createClass({ getInitialState() { return { - showed: 'login' - }; - }, - - getDefaultAnimation() { - return { - rotateY: -90 + sideToShow: 'front' }; }, render() { return ( - - {(animation) => { - return ( -
- {this.renderLogin(animation)} - {this.renderPasswordRecovery(animation)} -
- ) - }} -
+ + {this.renderLogin()} + {this.renderPasswordRecovery()} + ); }, - renderLogin(variants) { - var loginStyle = { - transform: `rotateY(${(variants.rotateY) ? variants.rotateY: 0}deg)` - }; - + renderLogin() { return ( - +
@@ -60,13 +44,9 @@ var MainHomePageLoginWidget = React.createClass({ ); }, - renderPasswordRecovery(variants) { - var passwordRecoveryStyle = { - transform: `rotateY(${-180+variants.rotateY}deg)` - }; - + renderPasswordRecovery() { return ( - +
@@ -83,7 +63,7 @@ var MainHomePageLoginWidget = React.createClass({ handleForgetPasswordClick() { this.setState({ - showed: 'password' + sideToShow: 'back' }); } }); diff --git a/src/app/main/main-home/main-home-page-login-widget.scss b/src/app/main/main-home/main-home-page-login-widget.scss index 71f5f082..00502273 100644 --- a/src/app/main/main-home/main-home-page-login-widget.scss +++ b/src/app/main/main-home/main-home-page-login-widget.scss @@ -1,4 +1,11 @@ .login-widget { + + &--container { + margin: 35px auto 0; + height: 327px; + width: 324px; + } + &--inputs { } diff --git a/src/app/main/main-home/main-home-page.scss b/src/app/main/main-home/main-home-page.scss index 21bfc9bc..2e494f51 100644 --- a/src/app/main/main-home/main-home-page.scss +++ b/src/app/main/main-home/main-home-page.scss @@ -1,21 +1,3 @@ .main-home-page { - &--widget-container { - position: relative; - display: inline-block; - margin: 35px auto 0; - height: 327px; - width: 324px; - } - - &--widget { - display: inline-block; - backface-visibility: hidden; - position: absolute; - left: 0; - } - - &--password-widget { -// backface-visibility: visible; - } } \ No newline at end of file diff --git a/src/core-components/widget-transition.js b/src/core-components/widget-transition.js new file mode 100644 index 00000000..0a5bd537 --- /dev/null +++ b/src/core-components/widget-transition.js @@ -0,0 +1,78 @@ +import React from 'react/addons'; +import classNames from 'classnames'; +import _ from 'lodash'; +import {Motion, spring} from 'react-motion'; + +import Widget from 'core-components/widget'; + +var WidgetTransition = React.createClass({ + + propTypes: { + sideToShow: React.PropTypes.string + }, + + getDefaultProps() { + return { + sideToShow: 'front' + }; + }, + + getDefaultAnimation() { + return { + rotateY: -90 + }; + }, + + render() { + return ( + + {this.renderChildren} + + ); + }, + + renderChildren: function (animation) { + return ( +
+ {React.Children.map(this.props.children, function (child, index) { + var modifiedChild; + + if (index === 0) { + modifiedChild = React.cloneElement(child, { + className: child.props.className + ' widget-transition--widget', + style: _.extend ({}, child.props.style, { + transform: `rotateY(${(animation.rotateY) ? animation.rotateY: 0}deg)` + }) + }); + } else { + modifiedChild = React.cloneElement(child, { + className: child.props.className + ' widget-transition--widget', + style: _.extend ({}, child.props.style, { + transform: `rotateY(${-180 + animation.rotateY}deg)` + }) + }); + } + + return modifiedChild; + })} +
+ ) + }, + + getClass() { + var classes = { + 'widget-transition': true, + [this.props.className]: (this.props.className) + }; + + return classNames(classes); + }, + + getAnimation() { + return { + rotateY: (this.props.sideToShow === 'front') ? spring(0, [100, 20]) : spring(180, [100, 20]) + }; + } +}); + +export default WidgetTransition; \ No newline at end of file diff --git a/src/core-components/widget-transition.scss b/src/core-components/widget-transition.scss new file mode 100644 index 00000000..9ff3c9d6 --- /dev/null +++ b/src/core-components/widget-transition.scss @@ -0,0 +1,11 @@ +.widget-transition { + position: relative; + display: inline-block; + + &--widget { + display: inline-block; + backface-visibility: hidden; + position: absolute; + left: 0; + } +} \ No newline at end of file