️ Add mobile drawer for navigation

This commit is contained in:
Manuel
2023-07-29 21:44:16 +02:00
parent 3d2e909237
commit d13347fd4e

View File

@@ -2,6 +2,8 @@ import {
AppShell, AppShell,
Avatar, Avatar,
Box, Box,
Burger,
Drawer,
Flex, Flex,
Footer, Footer,
Group, Group,
@@ -16,6 +18,7 @@ import {
UnstyledButton, UnstyledButton,
useMantineTheme, useMantineTheme,
} from '@mantine/core'; } from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { import {
IconAlertTriangle, IconAlertTriangle,
IconBook2, IconBook2,
@@ -37,6 +40,7 @@ import { useTranslation } from 'next-i18next';
import Image from 'next/image'; import Image from 'next/image';
import Link from 'next/link'; import Link from 'next/link';
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import { useScreenLargerThan } from '~/hooks/useScreenLargerThan';
import { usePackageAttributesStore } from '~/tools/client/zustands/usePackageAttributesStore'; import { usePackageAttributesStore } from '~/tools/client/zustands/usePackageAttributesStore';
import { Logo } from '../Logo'; import { Logo } from '../Logo';
@@ -49,16 +53,13 @@ export const MainLayout = ({ children }: MainLayoutProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const { attributes } = usePackageAttributesStore(); const { attributes } = usePackageAttributesStore();
const theme = useMantineTheme(); const theme = useMantineTheme();
return (
<AppShell const screenLargerThanMd = useScreenLargerThan('md');
styles={{
root: { const [burgerMenuOpen, { toggle: toggleBurgerMenu, close: closeBurgerMenu }] = useDisclosure(false);
background: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1],
}, const navigationLinks = (
}} <>
navbar={
<Navbar width={{ base: 220 }}>
<Navbar.Section pt="xs" grow>
<NavLink <NavLink
icon={ icon={
<ThemeIcon size="md" variant="light" color="red"> <ThemeIcon size="md" variant="light" color="red">
@@ -123,6 +124,20 @@ export const MainLayout = ({ children }: MainLayoutProps) => {
label="Contribute" label="Contribute"
/> />
</NavLink> </NavLink>
</>
);
return (
<>
<AppShell
styles={{
root: {
background: theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1],
},
}}
navbar={
<Navbar width={{ base: !screenLargerThanMd ? 0 : 220 }} hidden={!screenLargerThanMd}>
<Navbar.Section pt="xs" grow>
{navigationLinks}
</Navbar.Section> </Navbar.Section>
</Navbar> </Navbar>
} }
@@ -132,15 +147,20 @@ export const MainLayout = ({ children }: MainLayoutProps) => {
<Flex h="100%" align="center" columnGap={7}> <Flex h="100%" align="center" columnGap={7}>
<IconAlertTriangle color="white" size="1rem" /> <IconAlertTriangle color="white" size="1rem" />
<Text color="white" lineClamp={1}> <Text color="white" lineClamp={1}>
This is an experimental feature of Homarr. Please report any issues to the official This is an experimental feature of Homarr. Please report any issues to the
Homarr team. official Homarr team.
</Text> </Text>
</Flex> </Flex>
</Box> </Box>
<Group spacing="xl" mt="xs" px="md" position="apart" noWrap> <Group spacing="xl" mt="xs" px="md" position="apart" noWrap>
<Group noWrap>
{!screenLargerThanMd && (
<Burger opened={burgerMenuOpen} onClick={toggleBurgerMenu} />
)}
<UnstyledButton component={Link} href="/manage"> <UnstyledButton component={Link} href="/manage">
<Logo /> <Logo />
</UnstyledButton> </UnstyledButton>
</Group>
<TextInput radius="xl" w={400} placeholder="Search..." variant="filled" /> <TextInput radius="xl" w={400} placeholder="Search..." variant="filled" />
<Group noWrap> <Group noWrap>
@@ -190,5 +210,9 @@ export const MainLayout = ({ children }: MainLayoutProps) => {
{children} {children}
</Paper> </Paper>
</AppShell> </AppShell>
<Drawer opened={burgerMenuOpen} onClose={closeBurgerMenu}>
{navigationLinks}
</Drawer>
</>
); );
}; };