-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLayout.tsx
68 lines (59 loc) · 1.88 KB
/
Layout.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require('../css/base.css');
import 'focus-visible/dist/focus-visible';
import React from 'react';
import { Container, useDisclosure } from '@chakra-ui/react';
import { useLocation } from '@reach/router';
import { graphql } from 'gatsby';
import { Helmet } from 'react-helmet';
import Footer from './Footer';
import Header from './Header';
import Navigation from './Navigation';
interface Props {
data: GatsbyTypes.LayoutFragment;
children: React.ReactChild | React.ReactChild[];
pageName?: string;
}
function Layout({ data, children, pageName }: Props): JSX.Element {
// Hook to manage side-navigation drawer
const { isOpen, onOpen, onClose } = useDisclosure();
if (typeof window !== 'undefined') {
window.onbeforeprint = () => {
window.scrollTo(0, 0);
};
}
const { pathname } = useLocation();
const metadata = data?.site?.siteMetadata;
const title = metadata?.defaultTitle ?? 'Healthy Families Healthy Futures';
const image = `${metadata?.url ?? ''}${metadata?.image ?? ''}`;
const url = `${metadata?.url ?? ''}${pathname}`;
return (
<Container size="full" maxW="none" p={0}>
<Helmet defaultTitle={title} titleTemplate={`%s - ${title}`}>
{pageName != null ? <title>{pageName}</title> : null}
<meta name="description" content={metadata?.description ?? ''} />
<meta name="image" content={image} />
<meta name="og:image" content={image} />
<meta property="og:url" content={url} />
</Helmet>
<Header data={data} onHamburgerClick={onOpen} />
<Navigation isDrawerOpen={isOpen} onDrawerClose={onClose} />
{children}
<Footer data={data} />
</Container>
);
}
export default Layout;
export const fragment = graphql`
fragment Layout on Query {
site {
siteMetadata {
defaultTitle: title
description
url
image
}
}
...Header
...Footer
}
`;