You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.7 KiB

4 years ago
import { Box, Heading, Stack, VStack } from "@chakra-ui/react"
import Card from "components/card"
import { useRouter } from "next/router"
import * as React from "react"
import { Route } from "src/types/route"
import SidebarLink from "./sidebar-link"
export function SidebarContent(props) {
const { routes, pathname, contentRef } = props
return (
<>
<Stack as="ul">
{routes.map((route:Route) => {
if (route.disabled) {return null}
return <SidebarLink as="li" key={route.path} href={route.path} icon={route.icon}>
<span>{route.title}</span>
</SidebarLink>
})}
</Stack>
</>
)
}
4 years ago
const Sidebar = ({ routes,title, ...props }) => {
const { pathname } = useRouter()
const ref = React.useRef<HTMLDivElement>(null)
return (
4 years ago
<VStack alignItems="left">
<Card p="5"><Heading size="sm">{title}</Heading></Card>
<Card p="0" {...props}>
<Box
ref={ref}
as="nav"
aria-label="Main Navigation"
pos="sticky"
sx={{
overscrollBehavior: "contain",
}}
4 years ago
top="8.5rem"
pr="3"
pb="6"
pl="3"
pt="6"
overflowY="auto"
className="sidebar-content"
flexShrink={0}
4 years ago
// display={{ base: "none", md: "block" }}
>
<SidebarContent routes={routes} pathname={pathname} contentRef={ref} />
</Box>
</Card>
4 years ago
</VStack>
)
}
export default Sidebar