diff --git a/package.json b/package.json index df2f8de..5e4a4dc 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "react-height": "^2.0.3", "react-helmet": "^2.3.1", "react-intl": "=2.0.0-beta-2", - "react-motion": "^0.3.1", + "react-motion": "^0.4.0", "react-redux": "^4.0.0", "react-router": "^2.0.0", "react-router-redux": "^2.1.0", diff --git a/src/components/auth/PanelTransition.jsx b/src/components/auth/PanelTransition.jsx index ae3bc43..84aac19 100644 --- a/src/components/auth/PanelTransition.jsx +++ b/src/components/auth/PanelTransition.jsx @@ -13,9 +13,9 @@ import authFlow from 'services/authFlow'; import * as actions from './actions'; -const opacitySpringConfig = [300, 20]; -const transformSpringConfig = [500, 50]; -const changeContextSpringConfig = [500, 20]; +const opacitySpringConfig = {stiffness: 300, damping: 20}; +const transformSpringConfig = {stiffness: 500, damping: 50}; +const changeContextSpringConfig = {stiffness: 500, damping: 20}; class PanelTransition extends Component { static displayName = 'PanelTransition'; @@ -72,58 +72,54 @@ class PanelTransition extends Component { return ( {(items) => { - const keys = Object.keys(items).filter((key) => key !== 'common'); + const panels = items.filter(({key}) => key !== 'common'); + const common = items.filter(({key}) => key === 'common')[0]; const contentHeight = { overflow: 'hidden', - height: forceHeight ? items.common.switchContextHeightSpring : 'auto' + height: forceHeight ? common.switchContextHeightSpring : 'auto' }; const bodyHeight = { position: 'relative', - height: `${canAnimateHeight ? items.common.heightSpring : height[path]}px` + height: `${canAnimateHeight ? common.style.heightSpring : height[path]}px` }; return (
- {keys.map((key) => this.getHeader(key, items[key]))} + {panels.map((config) => this.getHeader(config))}
- {keys.map((key) => this.getBody(key, items[key]))} + {panels.map((config) => this.getBody(config))}
- {keys.map((key) => this.getFooter(key, items[key]))} + {panels.map((config) => this.getFooter(config))}
- {keys.map((key) => this.getLinks(key, items[key]))} + {panels.map((config) => this.getLinks(config))}
); @@ -140,21 +136,20 @@ class PanelTransition extends Component { this.props.setError(errorMessage); }; - willEnter = (key, styles) => this.getTransitionStyles(key, styles); - willLeave = (key, styles) => this.getTransitionStyles(key, styles, {isLeave: true}); + willEnter = (config) => this.getTransitionStyles(config); + willLeave = (config) => this.getTransitionStyles(config, {isLeave: true}); /** - * @param {string} key - * @param {Object} styles + * @param {Object} config * @param {Object} [options] * @param {Object} [options.isLeave=false] - true, if this is a leave transition * * @return {Object} */ - getTransitionStyles(key, styles, options = {}) { - var {isLeave = false} = options; + getTransitionStyles({key}, options = {}) { + const {isLeave = false} = options; - var map = { + const map = { '/login': -1, '/register': -1, '/password': 1, @@ -163,13 +158,13 @@ class PanelTransition extends Component { '/password-change': 1, '/forgot-password': 1 }; - var sign = map[key]; + const sign = map[key]; + + const transform = sign * 100; return { - ...styles, - pointerEvents: isLeave ? 'none' : 'auto', - transformSpring: spring(sign * 100, transformSpringConfig), - opacitySpring: spring(isLeave ? 0 : 1, opacitySpringConfig) + transformSpring: isLeave ? spring(transform, transformSpringConfig) : transform, + opacitySpring: isLeave ? spring(0, opacitySpringConfig) : 1 }; } @@ -213,23 +208,24 @@ class PanelTransition extends Component { authFlow.goBack(); }; - getHeader(key, props) { - var {hasBackButton, transformSpring, Title} = props; + getHeader({key, style, data}) { + const {Title, hasBackButton} = data; + const {transformSpring} = style; - var style = { - ...this.getDefaultTransitionStyles(props), + style = { + ...this.getDefaultTransitionStyles(key, style), opacity: 1 // reset default }; - var scrollStyle = this.translate(transformSpring, 'Y'); + const scrollStyle = this.translate(transformSpring, 'Y'); - var sideScrollStyle = { + const sideScrollStyle = { position: 'relative', zIndex: 2, ...this.translate(-Math.abs(transformSpring)) }; - var backButton = ( + const backButton = ( @@ -245,21 +241,20 @@ class PanelTransition extends Component { ); } - getBody(key, props) { - var {transformSpring, Body} = props; - var {direction} = this.state; + getBody({key, style, data}) { + const {Body} = data; + const {transformSpring} = style; + const {direction} = this.state; - var transform = this.translate(transformSpring, direction); - - - var verticalOrigin = 'top'; + let transform = this.translate(transformSpring, direction); + let verticalOrigin = 'top'; if (direction === 'Y') { verticalOrigin = 'bottom'; transform = {}; } - var style = { - ...this.getDefaultTransitionStyles(props), + style = { + ...this.getDefaultTransitionStyles(key, style), top: 'auto', // reset default [verticalOrigin]: 0, ...transform @@ -277,10 +272,10 @@ class PanelTransition extends Component { ); } - getFooter(key, props) { - var {Footer} = props; + getFooter({key, style, data}) { + const {Footer} = data; - var style = this.getDefaultTransitionStyles(props); + style = this.getDefaultTransitionStyles(key, style); return (
@@ -289,10 +284,10 @@ class PanelTransition extends Component { ); } - getLinks(key, props) { - var {Links} = props; + getLinks({key, style, data}) { + const {Links} = data; - var style = this.getDefaultTransitionStyles(props); + style = this.getDefaultTransitionStyles(key, style); return (
@@ -302,22 +297,20 @@ class PanelTransition extends Component { } /** + * @param {string} key * @param {Object} props - * @param {string} props.pointerEvents * @param {number} props.opacitySpring * * @return {Object} */ - getDefaultTransitionStyles(props) { - var {pointerEvents, opacitySpring} = props; - + getDefaultTransitionStyles(key, {opacitySpring}) { return { position: 'absolute', top: 0, left: 0, width: '100%', opacity: opacitySpring, - pointerEvents + pointerEvents: key === this.props.path ? 'auto' : 'none' }; }