2021-08-15 20:47:59 +02:00
|
|
|
import {
|
|
|
|
|
Box,
|
|
|
|
|
Divider,
|
|
|
|
|
Flex,
|
|
|
|
|
Link,
|
|
|
|
|
useColorMode,
|
|
|
|
|
useColorModeValue,
|
|
|
|
|
IconButton,
|
2021-10-01 09:19:36 +02:00
|
|
|
useBreakpointValue,
|
2022-02-01 19:26:07 +01:00
|
|
|
BoxProps,
|
2021-08-15 20:47:59 +02:00
|
|
|
} from '@chakra-ui/react';
|
|
|
|
|
import { useKeyBindings } from '../lib/key';
|
|
|
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
import NextLink from 'next/link';
|
2021-10-01 09:19:36 +02:00
|
|
|
import { Moon, Sun, Menu, X } from 'lucide-react';
|
|
|
|
|
import { useMobileNavigationContext, useMobileNavigationValue } from './MobileNavigationProvider';
|
|
|
|
|
import Logo from './Logo';
|
2023-04-09 16:49:11 +02:00
|
|
|
import menuItems from '../static/menuItems';
|
2020-08-29 22:16:38 +01:00
|
|
|
|
2022-02-01 19:26:07 +01:00
|
|
|
interface LayoutProps extends BoxProps {
|
|
|
|
|
aside?: BoxProps['children'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Layout = ({ aside, children }: LayoutProps) => {
|
2020-10-07 11:47:41 -04:00
|
|
|
const router = useRouter();
|
2021-10-01 09:19:36 +02:00
|
|
|
const { toggleMobileMenu } = useMobileNavigationContext();
|
2021-08-15 20:47:59 +02:00
|
|
|
const { toggleColorMode } = useColorMode();
|
2021-10-01 09:19:36 +02:00
|
|
|
const currentColorMode = useColorModeValue('dark', 'light');
|
2020-10-26 08:59:56 +01:00
|
|
|
const ColorModeToggle = useColorModeValue(Moon, Sun);
|
2021-10-01 09:19:36 +02:00
|
|
|
const MobileMenuToggle = useMobileNavigationValue(Menu, X);
|
|
|
|
|
const showBaseNavigation = useBreakpointValue({ base: false, md: true });
|
|
|
|
|
const IconbuttonProps = {
|
|
|
|
|
size: 'md',
|
|
|
|
|
fontSize: 'lg',
|
|
|
|
|
variant: 'ghost',
|
|
|
|
|
color: 'current',
|
|
|
|
|
ml: '3',
|
|
|
|
|
};
|
2020-08-29 22:16:38 +01:00
|
|
|
|
2021-08-15 20:47:59 +02:00
|
|
|
function setQuery(query) {
|
2023-04-09 16:49:11 +02:00
|
|
|
router.push(
|
|
|
|
|
{
|
2021-08-15 20:47:59 +02:00
|
|
|
pathname: '/',
|
|
|
|
|
query: { query: query },
|
2023-04-09 16:49:11 +02:00
|
|
|
},
|
|
|
|
|
undefined,
|
|
|
|
|
{ shallow: true },
|
|
|
|
|
);
|
2020-10-07 11:47:41 -04:00
|
|
|
}
|
2020-10-26 08:59:56 +01:00
|
|
|
|
2020-08-29 22:16:38 +01:00
|
|
|
useKeyBindings({
|
|
|
|
|
Escape: {
|
2021-08-15 20:47:59 +02:00
|
|
|
fn: () => setQuery(''),
|
2020-08-29 22:16:38 +01:00
|
|
|
},
|
|
|
|
|
KeyT: {
|
|
|
|
|
fn: () => toggleColorMode(),
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box h="100vh">
|
2023-04-09 16:49:11 +02:00
|
|
|
<Flex w="full">
|
2020-08-29 22:16:38 +01:00
|
|
|
<Flex
|
|
|
|
|
alignItems="center"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
pt={4}
|
|
|
|
|
pb={4}
|
|
|
|
|
margin="0 auto"
|
|
|
|
|
w="full"
|
2021-02-12 20:38:47 +01:00
|
|
|
px={5}
|
2020-08-29 22:16:38 +01:00
|
|
|
>
|
|
|
|
|
<Flex justifyContent="center" alignItems="center">
|
2021-10-01 09:19:36 +02:00
|
|
|
<Logo />
|
2020-08-29 22:16:38 +01:00
|
|
|
</Flex>
|
|
|
|
|
<Flex justifyContent="center" alignItems="center">
|
2021-10-01 09:19:36 +02:00
|
|
|
{showBaseNavigation ? (
|
|
|
|
|
<>
|
2023-04-09 16:49:11 +02:00
|
|
|
{menuItems.map(menuItem => {
|
|
|
|
|
if (menuItem.isExternal) {
|
|
|
|
|
return (
|
|
|
|
|
<Link
|
|
|
|
|
href={menuItem.href}
|
|
|
|
|
isExternal
|
|
|
|
|
marginRight={6}
|
|
|
|
|
fontSize="lg"
|
|
|
|
|
key={menuItem.name}
|
|
|
|
|
>
|
|
|
|
|
{menuItem.name}
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<NextLink href={menuItem.href} passHref key={menuItem.name}>
|
|
|
|
|
<Link marginRight={8} fontSize="lg">
|
|
|
|
|
{menuItem.name}
|
|
|
|
|
</Link>
|
|
|
|
|
</NextLink>
|
|
|
|
|
);
|
|
|
|
|
})}
|
2021-10-01 09:19:36 +02:00
|
|
|
</>
|
|
|
|
|
) : null}
|
2021-08-15 20:47:59 +02:00
|
|
|
<IconButton
|
2021-10-01 09:19:36 +02:00
|
|
|
aria-label={`Switch to ${currentColorMode} mode`}
|
2021-08-15 20:47:59 +02:00
|
|
|
onClick={toggleColorMode}
|
2021-10-01 09:19:36 +02:00
|
|
|
{...IconbuttonProps}
|
2021-08-15 20:47:59 +02:00
|
|
|
icon={<ColorModeToggle />}
|
|
|
|
|
/>
|
2021-10-01 09:19:36 +02:00
|
|
|
{!showBaseNavigation ? (
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label={`Open Mobile menu`}
|
|
|
|
|
onClick={toggleMobileMenu}
|
|
|
|
|
{...IconbuttonProps}
|
|
|
|
|
icon={<MobileMenuToggle />}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
2020-08-29 22:16:38 +01:00
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Flex>
|
2022-02-01 19:26:07 +01:00
|
|
|
<Flex>
|
2023-04-09 16:49:11 +02:00
|
|
|
{aside ? (
|
|
|
|
|
<Box as="aside" marginRight={{ base: 0, lg: -240 }}>
|
|
|
|
|
{aside}
|
|
|
|
|
</Box>
|
|
|
|
|
) : null}
|
|
|
|
|
<Flex margin="0 auto" direction="column" width="100%">
|
2022-02-01 19:26:07 +01:00
|
|
|
{children}
|
|
|
|
|
<Divider mb={6} mt={12} />
|
|
|
|
|
<p style={{ alignSelf: 'center' }}>
|
|
|
|
|
<a href="https://vercel.com?utm_source=lucide&utm_campaign=oss">
|
2022-09-13 09:03:13 +02:00
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
2022-02-01 19:26:07 +01:00
|
|
|
<img src="/vercel.svg" alt="Powered by Vercel" width="200" />
|
|
|
|
|
</a>
|
|
|
|
|
</p>
|
|
|
|
|
<br />
|
|
|
|
|
</Flex>
|
2020-08-29 22:16:38 +01:00
|
|
|
</Flex>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Layout;
|