2021-06-27 12:44:22 +02:00
|
|
|
import {
|
|
|
|
Box,
|
|
|
|
Flex,
|
|
|
|
Text,
|
|
|
|
IconButton,
|
|
|
|
Button,
|
|
|
|
Stack,
|
|
|
|
Collapse,
|
|
|
|
Icon,
|
|
|
|
Link,
|
|
|
|
Popover,
|
|
|
|
PopoverTrigger,
|
|
|
|
PopoverContent,
|
|
|
|
useColorModeValue,
|
|
|
|
useBreakpointValue,
|
|
|
|
useDisclosure,
|
2022-01-08 22:38:17 +01:00
|
|
|
} from "@chakra-ui/react";
|
2021-06-27 12:44:22 +02:00
|
|
|
import {
|
|
|
|
HamburgerIcon,
|
|
|
|
CloseIcon,
|
|
|
|
ChevronDownIcon,
|
|
|
|
ChevronRightIcon,
|
2022-01-08 22:38:17 +01:00
|
|
|
} from "@chakra-ui/icons";
|
|
|
|
import AuthButton from "../AuthButton";
|
|
|
|
import { signIn, signOut, useSession } from "next-auth/client";
|
2021-06-27 12:44:22 +02:00
|
|
|
|
|
|
|
export default function WithSubnavigation() {
|
|
|
|
const { isOpen, onToggle } = useDisclosure();
|
2022-01-08 22:38:17 +01:00
|
|
|
const [session, loading] = useSession();
|
2021-06-27 12:44:22 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Box>
|
|
|
|
<Flex
|
2022-01-08 22:38:17 +01:00
|
|
|
bg={useColorModeValue("white", "gray.800")}
|
|
|
|
color={useColorModeValue("gray.600", "white")}
|
|
|
|
minH={"60px"}
|
2021-06-27 12:44:22 +02:00
|
|
|
py={{ base: 2 }}
|
|
|
|
px={{ base: 4 }}
|
|
|
|
borderBottom={1}
|
2022-01-08 22:38:17 +01:00
|
|
|
borderStyle={"solid"}
|
|
|
|
borderColor={useColorModeValue("gray.200", "gray.900")}
|
|
|
|
align={"center"}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Flex
|
2022-01-08 22:38:17 +01:00
|
|
|
flex={{ base: 1, md: "auto" }}
|
2021-06-27 12:44:22 +02:00
|
|
|
ml={{ base: -2 }}
|
2022-01-08 22:38:17 +01:00
|
|
|
display={{ base: "flex", md: "none" }}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
<IconButton
|
|
|
|
onClick={onToggle}
|
|
|
|
icon={
|
|
|
|
isOpen ? <CloseIcon w={3} h={3} /> : <HamburgerIcon w={5} h={5} />
|
|
|
|
}
|
2022-01-08 22:38:17 +01:00
|
|
|
variant={"ghost"}
|
|
|
|
aria-label={"Toggle Navigation"}
|
2021-06-27 12:44:22 +02:00
|
|
|
/>
|
|
|
|
</Flex>
|
2022-01-08 22:38:17 +01:00
|
|
|
<Flex flex={{ base: 1 }} justify={{ base: "center", md: "start" }}>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Text
|
2022-01-08 22:38:17 +01:00
|
|
|
textAlign={useBreakpointValue({ base: "center", md: "left" })}
|
|
|
|
fontFamily={"heading"}
|
|
|
|
color={useColorModeValue("gray.800", "white")}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
Cath.exe
|
|
|
|
</Text>
|
|
|
|
|
2022-01-08 22:38:17 +01:00
|
|
|
<Flex display={{ base: "none", md: "flex" }} ml={10}>
|
2021-06-27 12:44:22 +02:00
|
|
|
<DesktopNav />
|
|
|
|
</Flex>
|
|
|
|
</Flex>
|
|
|
|
|
|
|
|
<Stack
|
|
|
|
flex={{ base: 1, md: 0 }}
|
2022-01-08 22:38:17 +01:00
|
|
|
justify={"flex-end"}
|
|
|
|
direction={"row"}
|
|
|
|
spacing={6}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Button
|
2022-01-08 22:38:17 +01:00
|
|
|
as={"a"}
|
|
|
|
fontSize={"sm"}
|
2021-06-27 12:44:22 +02:00
|
|
|
fontWeight={400}
|
2022-01-08 22:38:17 +01:00
|
|
|
variant={"link"}
|
|
|
|
onClick={
|
|
|
|
session
|
|
|
|
? () => {
|
|
|
|
signOut();
|
|
|
|
}
|
|
|
|
: () => {
|
|
|
|
signIn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
>
|
|
|
|
{session ? "Sign Out" : "Sign In"}
|
2021-06-27 12:44:22 +02:00
|
|
|
</Button>
|
|
|
|
</Stack>
|
|
|
|
</Flex>
|
|
|
|
|
|
|
|
<Collapse in={isOpen} animateOpacity>
|
|
|
|
<MobileNav />
|
|
|
|
</Collapse>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const DesktopNav = () => {
|
2022-01-08 22:38:17 +01:00
|
|
|
const linkColor = useColorModeValue("gray.600", "gray.200");
|
|
|
|
const linkHoverColor = useColorModeValue("gray.800", "white");
|
|
|
|
const popoverContentBgColor = useColorModeValue("white", "gray.800");
|
2021-06-27 12:44:22 +02:00
|
|
|
|
|
|
|
return (
|
2022-01-08 22:38:17 +01:00
|
|
|
<Stack direction={"row"} spacing={4}>
|
|
|
|
{NAV_ITEMS.map(navItem => (
|
2021-06-27 12:44:22 +02:00
|
|
|
<Box key={navItem.label}>
|
2022-01-08 22:38:17 +01:00
|
|
|
<Popover trigger={"hover"} placement={"bottom-start"}>
|
2021-06-27 12:44:22 +02:00
|
|
|
<PopoverTrigger>
|
|
|
|
<Link
|
|
|
|
p={2}
|
2022-01-08 22:38:17 +01:00
|
|
|
href={navItem.href ?? "#"}
|
|
|
|
fontSize={"sm"}
|
2021-06-27 12:44:22 +02:00
|
|
|
fontWeight={500}
|
|
|
|
color={linkColor}
|
|
|
|
_hover={{
|
2022-01-08 22:38:17 +01:00
|
|
|
textDecoration: "none",
|
2021-06-27 12:44:22 +02:00
|
|
|
color: linkHoverColor,
|
2022-01-08 22:38:17 +01:00
|
|
|
}}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
{navItem.label}
|
|
|
|
</Link>
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
|
|
|
{navItem.children && (
|
|
|
|
<PopoverContent
|
|
|
|
border={0}
|
2022-01-08 22:38:17 +01:00
|
|
|
boxShadow={"xl"}
|
2021-06-27 12:44:22 +02:00
|
|
|
bg={popoverContentBgColor}
|
|
|
|
p={4}
|
2022-01-08 22:38:17 +01:00
|
|
|
rounded={"xl"}
|
|
|
|
minW={"sm"}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Stack>
|
2022-01-08 22:38:17 +01:00
|
|
|
{navItem.children.map(child => (
|
2021-06-27 12:44:22 +02:00
|
|
|
<DesktopSubNav key={child.label} {...child} />
|
|
|
|
))}
|
|
|
|
</Stack>
|
|
|
|
</PopoverContent>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
</Box>
|
|
|
|
))}
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const DesktopSubNav = ({ label, href, subLabel }) => {
|
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
href={href}
|
2022-01-08 22:38:17 +01:00
|
|
|
role={"group"}
|
|
|
|
display={"block"}
|
2021-06-27 12:44:22 +02:00
|
|
|
p={2}
|
2022-01-08 22:38:17 +01:00
|
|
|
rounded={"md"}
|
|
|
|
_hover={{ bg: useColorModeValue("teal.50", "gray.900") }}
|
|
|
|
>
|
|
|
|
<Stack direction={"row"} align={"center"}>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Box>
|
|
|
|
<Text
|
2022-01-08 22:38:17 +01:00
|
|
|
transition={"all .3s ease"}
|
|
|
|
_groupHover={{ color: "teal.200" }}
|
|
|
|
fontWeight={500}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
{label}
|
|
|
|
</Text>
|
2022-01-08 22:38:17 +01:00
|
|
|
<Text fontSize={"sm"}>{subLabel}</Text>
|
2021-06-27 12:44:22 +02:00
|
|
|
</Box>
|
|
|
|
<Flex
|
2022-01-08 22:38:17 +01:00
|
|
|
transition={"all .3s ease"}
|
|
|
|
transform={"translateX(-10px)"}
|
2021-06-27 12:44:22 +02:00
|
|
|
opacity={0}
|
2022-01-08 22:38:17 +01:00
|
|
|
_groupHover={{ opacity: "100%", transform: "translateX(0)" }}
|
|
|
|
justify={"flex-end"}
|
|
|
|
align={"center"}
|
|
|
|
flex={1}
|
|
|
|
>
|
|
|
|
<Icon color={"teal.200"} w={5} h={5} as={ChevronRightIcon} />
|
2021-06-27 12:44:22 +02:00
|
|
|
</Flex>
|
|
|
|
</Stack>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MobileNav = () => {
|
|
|
|
return (
|
|
|
|
<Stack
|
2022-01-08 22:38:17 +01:00
|
|
|
bg={useColorModeValue("white", "gray.800")}
|
2021-06-27 12:44:22 +02:00
|
|
|
p={4}
|
2022-01-08 22:38:17 +01:00
|
|
|
display={{ md: "none" }}
|
|
|
|
>
|
|
|
|
{NAV_ITEMS.map(navItem => (
|
2021-06-27 12:44:22 +02:00
|
|
|
<MobileNavItem key={navItem.label} {...navItem} />
|
|
|
|
))}
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const MobileNavItem = ({ label, children, href }) => {
|
|
|
|
const { isOpen, onToggle } = useDisclosure();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Stack spacing={4} onClick={children && onToggle}>
|
|
|
|
<Flex
|
|
|
|
py={2}
|
|
|
|
as={Link}
|
2022-01-08 22:38:17 +01:00
|
|
|
href={href ?? "#"}
|
|
|
|
justify={"space-between"}
|
|
|
|
align={"center"}
|
2021-06-27 12:44:22 +02:00
|
|
|
_hover={{
|
2022-01-08 22:38:17 +01:00
|
|
|
textDecoration: "none",
|
|
|
|
}}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Text
|
|
|
|
fontWeight={600}
|
2022-01-08 22:38:17 +01:00
|
|
|
color={useColorModeValue("gray.600", "gray.200")}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
{label}
|
|
|
|
</Text>
|
|
|
|
{children && (
|
|
|
|
<Icon
|
|
|
|
as={ChevronDownIcon}
|
2022-01-08 22:38:17 +01:00
|
|
|
transition={"all .25s ease-in-out"}
|
|
|
|
transform={isOpen ? "rotate(180deg)" : ""}
|
2021-06-27 12:44:22 +02:00
|
|
|
w={6}
|
|
|
|
h={6}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Flex>
|
|
|
|
|
2022-01-08 22:38:17 +01:00
|
|
|
<Collapse in={isOpen} animateOpacity style={{ marginTop: "0!important" }}>
|
2021-06-27 12:44:22 +02:00
|
|
|
<Stack
|
|
|
|
mt={2}
|
|
|
|
pl={4}
|
|
|
|
borderLeft={1}
|
2022-01-08 22:38:17 +01:00
|
|
|
borderStyle={"solid"}
|
|
|
|
borderColor={useColorModeValue("gray.200", "gray.700")}
|
|
|
|
align={"start"}
|
|
|
|
>
|
2021-06-27 12:44:22 +02:00
|
|
|
{children &&
|
2022-01-08 22:38:17 +01:00
|
|
|
children.map(child => (
|
2021-06-27 12:44:22 +02:00
|
|
|
<Link key={child.label} py={2} href={child.href}>
|
|
|
|
{child.label}
|
|
|
|
</Link>
|
|
|
|
))}
|
|
|
|
</Stack>
|
|
|
|
</Collapse>
|
|
|
|
</Stack>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const NAV_ITEMS = [
|
|
|
|
{
|
2022-01-08 22:38:17 +01:00
|
|
|
label: "Home",
|
|
|
|
href: "/",
|
2021-06-27 12:44:22 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-08 22:38:17 +01:00
|
|
|
label: "Control Panel",
|
2021-06-27 12:44:22 +02:00
|
|
|
children: [
|
|
|
|
{
|
2022-01-08 22:38:17 +01:00
|
|
|
label: "Main",
|
|
|
|
subLabel: "Control Everything",
|
|
|
|
href: "/controlpanel",
|
2021-06-27 12:44:22 +02:00
|
|
|
},
|
|
|
|
{
|
2022-01-08 22:38:17 +01:00
|
|
|
label: "Commands",
|
|
|
|
subLabel: "Control Caths commands",
|
|
|
|
href: "/controlpanel/commands",
|
2021-06-27 12:44:22 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
2022-01-08 22:38:17 +01:00
|
|
|
label: "Coming soon...",
|
|
|
|
href: "#",
|
2021-06-27 12:44:22 +02:00
|
|
|
},
|
2022-01-08 22:38:17 +01:00
|
|
|
];
|