Fix route transitioning

This commit is contained in:
Dane Everitt 2020-07-04 09:46:26 -07:00
parent bcf0a0586d
commit ebe588718c
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
6 changed files with 71 additions and 14 deletions

View File

@ -29,7 +29,7 @@
"react-i18next": "^11.2.1", "react-i18next": "^11.2.1",
"react-redux": "^7.1.0", "react-redux": "^7.1.0",
"react-router-dom": "^5.1.2", "react-router-dom": "^5.1.2",
"react-transition-group": "^4.3.0", "react-transition-group": "^4.4.1",
"sockette": "^2.0.6", "sockette": "^2.0.6",
"styled-components": "^5.1.1", "styled-components": "^5.1.1",
"styled-components-breakpoint": "^3.0.0-preview.20", "styled-components-breakpoint": "^3.0.0-preview.20",
@ -66,7 +66,7 @@
"@types/react-redux": "^7.1.1", "@types/react-redux": "^7.1.1",
"@types/react-router": "^5.1.3", "@types/react-router": "^5.1.3",
"@types/react-router-dom": "^5.1.3", "@types/react-router-dom": "^5.1.3",
"@types/react-transition-group": "^2.9.2", "@types/react-transition-group": "^4.4.0",
"@types/styled-components": "^5.1.0", "@types/styled-components": "^5.1.0",
"@types/uuid": "^3.4.5", "@types/uuid": "^3.4.5",
"@types/webpack-env": "^1.15.2", "@types/webpack-env": "^1.15.2",

View File

@ -1,17 +1,28 @@
import React from 'react'; import React from 'react';
import { Route } from 'react-router'; import { Route } from 'react-router';
import { CSSTransition, TransitionGroup } from 'react-transition-group'; import { SwitchTransition } from 'react-transition-group';
import Fade from '@/components/elements/Fade';
import styled from 'styled-components/macro';
import tw from 'twin.macro';
const StyledSwitchTransition = styled(SwitchTransition)`
${tw`relative`};
& section {
${tw`absolute w-full top-0 left-0`};
}
`;
const TransitionRouter: React.FC = ({ children }) => ( const TransitionRouter: React.FC = ({ children }) => (
<Route <Route
render={({ location }) => ( render={({ location }) => (
<TransitionGroup className={'route-transition-group'}> <StyledSwitchTransition>
<CSSTransition key={location.key} timeout={250} in appear classNames={'fade'}> <Fade timeout={250} key={location.key} in appear unmountOnExit>
<section> <section>
{children} {children}
</section> </section>
</CSSTransition> </Fade>
</TransitionGroup> </StyledSwitchTransition>
)} )}
/> />
); );

View File

@ -12,6 +12,7 @@ import ProgressBar from '@/components/elements/ProgressBar';
import NotFound from '@/components/screens/NotFound'; import NotFound from '@/components/screens/NotFound';
import tw from 'twin.macro'; import tw from 'twin.macro';
import GlobalStylesheet from '@/assets/css/GlobalStylesheet'; import GlobalStylesheet from '@/assets/css/GlobalStylesheet';
import TransitionRouter from '@/TransitionRouter';
interface ExtendedWindow extends Window { interface ExtendedWindow extends Window {
SiteConfiguration?: SiteSettings; SiteConfiguration?: SiteSettings;

View File

@ -0,0 +1,43 @@
import React from 'react';
import tw from 'twin.macro';
import styled from 'styled-components/macro';
import CSSTransition, { CSSTransitionProps } from 'react-transition-group/CSSTransition';
interface Props extends Omit<CSSTransitionProps, 'timeout' | 'classNames'> {
timeout: number;
}
const Container = styled.div<{ timeout: number }>`
.fade-enter, .fade-exit {
will-change: opacity;
}
.fade-enter {
${tw`opacity-0`};
&.fade-enter-active {
${tw`opacity-100 transition-opacity ease-in`};
transition-duration: ${props => props.timeout}ms;
}
}
.fade-exit {
${tw`opacity-100`};
&.fade-exit-active {
${tw`opacity-0 transition-opacity ease-in`};
transition-duration: ${props => props.timeout}ms;
}
}
`;
const Fade: React.FC<Props> = ({ timeout, children, ...props }) => (
<Container timeout={timeout}>
<CSSTransition timeout={timeout} classNames={'fade'} {...props}>
{children}
</CSSTransition>
</Container>
);
Fade.displayName = 'Fade';
export default Fade;

View File

@ -3,12 +3,12 @@ import { NavLink, Route, RouteComponentProps, Switch } from 'react-router-dom';
import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer'; import AccountOverviewContainer from '@/components/dashboard/AccountOverviewContainer';
import NavigationBar from '@/components/NavigationBar'; import NavigationBar from '@/components/NavigationBar';
import DashboardContainer from '@/components/dashboard/DashboardContainer'; import DashboardContainer from '@/components/dashboard/DashboardContainer';
import TransitionRouter from '@/TransitionRouter';
import AccountApiContainer from '@/components/dashboard/AccountApiContainer'; import AccountApiContainer from '@/components/dashboard/AccountApiContainer';
import NotFound from '@/components/screens/NotFound'; import NotFound from '@/components/screens/NotFound';
import styled from 'styled-components/macro'; import styled from 'styled-components/macro';
import tw from 'twin.macro'; import tw from 'twin.macro';
import config from '@/../../tailwind.config.js'; import config from '@/../../tailwind.config.js';
import TransitionRouter from '@/TransitionRouter';
const SubNavigation = styled.div` const SubNavigation = styled.div`
${tw`w-full bg-neutral-700 shadow`}; ${tw`w-full bg-neutral-700 shadow`};

View File

@ -1069,9 +1069,10 @@
"@types/history" "*" "@types/history" "*"
"@types/react" "*" "@types/react" "*"
"@types/react-transition-group@^2.9.2": "@types/react-transition-group@^4.4.0":
version "2.9.2" version "4.4.0"
resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-2.9.2.tgz#c48cf2a11977c8b4ff539a1c91d259eaa627028d" resolved "https://registry.yarnpkg.com/@types/react-transition-group/-/react-transition-group-4.4.0.tgz#882839db465df1320e4753e6e9f70ca7e9b4d46d"
integrity sha512-/QfLHGpu+2fQOqQaXh8MG9q03bFENooTb/it4jr5kKaZlDQfWvjqWZg48AwzPVMBHlRuTRAY7hRHCEOXz5kV6w==
dependencies: dependencies:
"@types/react" "*" "@types/react" "*"
@ -6960,9 +6961,10 @@ react-router@5.1.2:
tiny-invariant "^1.0.2" tiny-invariant "^1.0.2"
tiny-warning "^1.0.0" tiny-warning "^1.0.0"
react-transition-group@^4.3.0: react-transition-group@^4.4.1:
version "4.3.0" version "4.4.1"
resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.3.0.tgz#fea832e386cf8796c58b61874a3319704f5ce683" resolved "https://registry.yarnpkg.com/react-transition-group/-/react-transition-group-4.4.1.tgz#63868f9325a38ea5ee9535d828327f85773345c9"
integrity sha512-Djqr7OQ2aPUiYurhPalTrVy9ddmFCCzwhqQmtN+J3+3DzLO209Fdr70QrN8Z3DsglWql6iY1lDWAfpFiBtuKGw==
dependencies: dependencies:
"@babel/runtime" "^7.5.5" "@babel/runtime" "^7.5.5"
dom-helpers "^5.0.1" dom-helpers "^5.0.1"