From de4a767b21b35f17631451cf6232d9c8f6c6e81b Mon Sep 17 00:00:00 2001 From: Jose Sousa Date: Thu, 19 Nov 2020 16:46:10 +0000 Subject: [PATCH] feat: transitions animations direction --- .../src/components/layout/Header.js | 11 ++++- new-lamassu-admin/src/routing/routes.js | 40 ++++++++++++++----- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/new-lamassu-admin/src/components/layout/Header.js b/new-lamassu-admin/src/components/layout/Header.js index d21acb46..a5fbe801 100644 --- a/new-lamassu-admin/src/components/layout/Header.js +++ b/new-lamassu-admin/src/components/layout/Header.js @@ -15,6 +15,8 @@ import styles from './Header.styles' const useStyles = makeStyles(styles) const Subheader = ({ item, classes }) => { + const [prev, setPrev] = useState(null) + return (
@@ -23,9 +25,14 @@ const Subheader = ({ item, classes }) => { {item.children.map((it, idx) => (
  • + activeClassName={classes.activeSubheaderLink} + isActive={match => { + if (!match) return false + setPrev(it.route) + return true + }}> {it.label}
  • diff --git a/new-lamassu-admin/src/routing/routes.js b/new-lamassu-admin/src/routing/routes.js index 8a3ccd39..29dc8895 100644 --- a/new-lamassu-admin/src/routing/routes.js +++ b/new-lamassu-admin/src/routing/routes.js @@ -1,5 +1,6 @@ import Fade from '@material-ui/core/Fade' import Slide from '@material-ui/core/Slide' +import { makeStyles } from '@material-ui/core/styles' import * as R from 'ramda' import React, { useContext } from 'react' import { @@ -35,6 +36,14 @@ import WalletSettings from 'src/pages/Wallet/Wallet' import Wizard from 'src/pages/Wizard' import { namespaces } from 'src/utils/config' +const useStyles = makeStyles({ + wrapper: { + flex: 1, + display: 'flex', + flexDirection: 'column' + } +}) + const tree = [ { key: 'transactions', @@ -244,6 +253,8 @@ const getParent = route => )(flattened) const Routes = () => { + const classes = useStyles() + const history = useHistory() const location = useLocation() const action = history.action @@ -256,10 +267,18 @@ const Routes = () => { history.push('/wizard') } - const Transition = - action === 'PUSH' && location.pathname !== '/transactions' ? Slide : Fade + const Transition = action === 'PUSH' && location.state ? Slide : Fade - // const props = Transition === Slide ? { direction: 'right' } : {} + const transitionProps = + Transition === Slide + ? { + direction: + R.findIndex(R.propEq('route', location.state.prev))(leafRoutes) > + R.findIndex(R.propEq('route', location.pathname))(leafRoutes) + ? 'right' + : 'left' + } + : { timeout: 400 } return ( @@ -271,14 +290,17 @@ const Routes = () => { {flattened.map(({ route, component: Page, key }) => ( -
    - -
    -
    + unmountOnExit + children={ +
    + +
    + } + />
    ))}