feat: transitions animations direction
This commit is contained in:
parent
68050fd4ba
commit
de4a767b21
2 changed files with 40 additions and 11 deletions
|
|
@ -15,6 +15,8 @@ import styles from './Header.styles'
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
const Subheader = ({ item, classes }) => {
|
const Subheader = ({ item, classes }) => {
|
||||||
|
const [prev, setPrev] = useState(null)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.subheader}>
|
<div className={classes.subheader}>
|
||||||
<div className={classes.content}>
|
<div className={classes.content}>
|
||||||
|
|
@ -23,9 +25,14 @@ const Subheader = ({ item, classes }) => {
|
||||||
{item.children.map((it, idx) => (
|
{item.children.map((it, idx) => (
|
||||||
<li key={idx} className={classes.subheaderLi}>
|
<li key={idx} className={classes.subheaderLi}>
|
||||||
<NavLink
|
<NavLink
|
||||||
to={it.route}
|
to={{ pathname: it.route, state: { prev: prev } }}
|
||||||
className={classes.subheaderLink}
|
className={classes.subheaderLink}
|
||||||
activeClassName={classes.activeSubheaderLink}>
|
activeClassName={classes.activeSubheaderLink}
|
||||||
|
isActive={match => {
|
||||||
|
if (!match) return false
|
||||||
|
setPrev(it.route)
|
||||||
|
return true
|
||||||
|
}}>
|
||||||
{it.label}
|
{it.label}
|
||||||
</NavLink>
|
</NavLink>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import Fade from '@material-ui/core/Fade'
|
import Fade from '@material-ui/core/Fade'
|
||||||
import Slide from '@material-ui/core/Slide'
|
import Slide from '@material-ui/core/Slide'
|
||||||
|
import { makeStyles } from '@material-ui/core/styles'
|
||||||
import * as R from 'ramda'
|
import * as R from 'ramda'
|
||||||
import React, { useContext } from 'react'
|
import React, { useContext } from 'react'
|
||||||
import {
|
import {
|
||||||
|
|
@ -35,6 +36,14 @@ import WalletSettings from 'src/pages/Wallet/Wallet'
|
||||||
import Wizard from 'src/pages/Wizard'
|
import Wizard from 'src/pages/Wizard'
|
||||||
import { namespaces } from 'src/utils/config'
|
import { namespaces } from 'src/utils/config'
|
||||||
|
|
||||||
|
const useStyles = makeStyles({
|
||||||
|
wrapper: {
|
||||||
|
flex: 1,
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const tree = [
|
const tree = [
|
||||||
{
|
{
|
||||||
key: 'transactions',
|
key: 'transactions',
|
||||||
|
|
@ -244,6 +253,8 @@ const getParent = route =>
|
||||||
)(flattened)
|
)(flattened)
|
||||||
|
|
||||||
const Routes = () => {
|
const Routes = () => {
|
||||||
|
const classes = useStyles()
|
||||||
|
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const action = history.action
|
const action = history.action
|
||||||
|
|
@ -256,10 +267,18 @@ const Routes = () => {
|
||||||
history.push('/wizard')
|
history.push('/wizard')
|
||||||
}
|
}
|
||||||
|
|
||||||
const Transition =
|
const Transition = action === 'PUSH' && location.state ? Slide : Fade
|
||||||
action === 'PUSH' && location.pathname !== '/transactions' ? 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 (
|
return (
|
||||||
<Switch>
|
<Switch>
|
||||||
|
|
@ -271,14 +290,17 @@ const Routes = () => {
|
||||||
{flattened.map(({ route, component: Page, key }) => (
|
{flattened.map(({ route, component: Page, key }) => (
|
||||||
<Route path={route} key={key}>
|
<Route path={route} key={key}>
|
||||||
<Transition
|
<Transition
|
||||||
direction="left"
|
className={classes.wrapper}
|
||||||
|
{...transitionProps}
|
||||||
in={location.pathname === route}
|
in={location.pathname === route}
|
||||||
mountOnEnter
|
mountOnEnter
|
||||||
unmountOnExit>
|
unmountOnExit
|
||||||
<div>
|
children={
|
||||||
<Page name={key} action={action} />
|
<div>
|
||||||
</div>
|
<Page name={key} />
|
||||||
</Transition>
|
</div>
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
))}
|
))}
|
||||||
<Route path="/404" />
|
<Route path="/404" />
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue