portfolio/src/components/Layout.jsx

67 lines
2.1 KiB
React
Raw Normal View History

2019-11-10 15:15:34 +01:00
import React from 'react'
import PropTypes from 'prop-types'
import { motion, AnimatePresence, useReducedMotion } from 'framer-motion'
import { fadeIn, moveInBottom, getAnimationProps } from './atoms/Transitions'
2018-11-25 00:15:02 +01:00
import Typekit from './atoms/Typekit'
2018-12-09 15:14:20 +01:00
import HostnameCheck from './atoms/HostnameCheck'
2021-03-13 03:35:50 +01:00
import ThemeSwitch from './molecules/ThemeSwitch'
import Header from './organisms/Header'
import Footer from './organisms/Footer'
2021-03-12 23:47:28 +01:00
import { screen } from './Layout.module.css'
2019-11-11 21:46:14 +01:00
import { useMeta } from '../hooks/use-meta'
2019-11-26 18:25:42 +01:00
// https://github.com/welldone-software/why-did-you-render
2021-03-13 01:03:23 +01:00
// if (process.env.NODE_ENV !== 'production') {
// // eslint-disable-next-line
// const whyDidYouRender = require('@welldone-software/why-did-you-render')
// whyDidYouRender(React, { trackAllPureComponents: true })
// }
2019-11-10 15:15:34 +01:00
Layout.propTypes = {
children: PropTypes.any.isRequired,
location: PropTypes.shape({
pathname: PropTypes.string.isRequired
}).isRequired
}
2019-04-28 22:30:20 +02:00
2019-11-10 15:15:34 +01:00
export default function Layout({ children, location }) {
2019-11-11 21:46:14 +01:00
const { allowedHosts } = useMeta()
const shouldReduceMotion = useReducedMotion()
const isSsr = typeof window === 'undefined'
2020-11-20 23:36:55 +01:00
2019-11-10 15:15:34 +01:00
const isHomepage =
location.pathname === '/' ||
location.pathname === '/offline-plugin-app-shell-fallback/'
2019-11-19 23:25:49 +01:00
const isResume =
location.pathname === '/resume' || location.pathname === '/resume/'
2019-11-10 15:15:34 +01:00
return (
<>
<Typekit />
2019-11-11 21:46:14 +01:00
<HostnameCheck allowedHosts={allowedHosts} />
2021-03-13 03:35:50 +01:00
<ThemeSwitch />
2019-11-10 15:15:34 +01:00
2022-11-05 20:16:56 +01:00
<AnimatePresence mode="wait">
<motion.div
2020-11-20 23:36:55 +01:00
key={location.pathname}
variants={fadeIn}
{...getAnimationProps(shouldReduceMotion, isSsr)}
2019-11-10 15:15:34 +01:00
>
2019-11-19 23:25:49 +01:00
<Header minimal={!isHomepage} hide={isResume} />
<motion.main
key={location.pathname}
variants={moveInBottom}
initial={`${shouldReduceMotion || isSsr ? 'enter' : 'initial'}`}
animate={`${shouldReduceMotion || isSsr ? null : 'enter'}`}
className={screen}
>
{children}
</motion.main>
</motion.div>
</AnimatePresence>
2019-11-10 15:15:34 +01:00
<Footer />
</>
)
}