import { Badge, Box, Center, chakra, HStack, List, ListItem, ListProps, } from '@chakra-ui/react' import NextLink from 'next/link' import { useRouter } from 'next/router' import { Fragment, ReactElement, ReactNode, useRef } from 'react' import { AiFillPlayCircle } from 'react-icons/ai' import { BsFillGridFill } from 'react-icons/bs' import { FaCompass, FaGlobe, FaPalette, FaTools } from 'react-icons/fa' import { FiFigma } from 'react-icons/fi' import { convertBackticksToInlineCode } from 'utils/convert-backticks-to-inline-code' import { RouteItem, Routes } from 'utils/get-route-context' import SidebarCategory from './sidebar-category' import SidebarLink from './sidebar-link' const sortRoutes = (routes: RouteItem[]) => { return routes.sort(({ title: titleA }, { title: titleB }) => { if (titleA < titleB) return -1 if (titleA > titleB) return 1 return 0 }) } export type SidebarContentProps = Routes & { pathname?: string contentRef?: any } function NewBadge() { return ( New ) } export function SidebarContent({ routes, pathname, contentRef, }: SidebarContentProps) { return ( <> {routes.map((lvl1, idx) => { return ( {lvl1.heading && ( {lvl1.title} )} {lvl1.routes.map((lvl2, index) => { if (!lvl2.routes) { return ( {lvl2.title} ) } const selected = pathname.startsWith(lvl2.path) const opened = selected || lvl2.open const sortedRoutes = lvl2.sort ? sortRoutes(lvl2.routes) : lvl2.routes return ( {sortedRoutes.map((lvl3) => ( {convertBackticksToInlineCode(lvl3.title)} {lvl3.new && } ))} ) })} ) })} ) } type MainNavLinkProps = { href: string icon: ReactElement children: ReactNode label?: string isActive?: boolean isExternal?: boolean } const MainNavLink = ({ href, icon, children, isActive, isExternal, }: MainNavLinkProps) => { const router = useRouter() const active = router.asPath.startsWith(href) || !!isActive return (
{icon}
{children}
) } export const mainNavLinks = [ { icon: , href: '/getting-started', label: 'Getting Started', }, { icon: , href: '/docs/styled-system/style-props', label: 'Styled System', match: (asPath: string, href: string) => href.startsWith('/docs/styled-system') && asPath.startsWith('/docs/styled-system'), }, { icon: , href: '/docs/components', label: 'Components', }, { icon: , href: '/docs/hooks/use-boolean', label: 'Hooks', match: (asPath: string, href: string) => href.startsWith('/docs/hooks') && asPath.startsWith('/docs/hooks'), }, { icon: , href: '/figma/ui-kit', label: 'Figma', match: (asPath: string, href: string) => href.startsWith('/figma') && asPath.startsWith('/figma'), }, { icon: , href: '/community/team', label: 'Community', match: (asPath: string, href: string) => href.startsWith('/community') && asPath.startsWith('/community'), }, { icon: , href: 'https://play.chakra-ui.com', label: 'Playground', new: false, external: true, }, // { // icon: , // href: '/blog', // label: 'Blog', // }, ] export const MainNavLinkGroup = (props: ListProps) => { const router = useRouter() return ( {mainNavLinks.map((item) => ( {item.label} {item.new && } ))} ) } const Sidebar = ({ routes }) => { const { pathname } = useRouter() const ref = useRef(null) return ( ) } export default Sidebar