"use client"; import { ChevronRight, Menu } from "lucide-react"; import Link from "next/link"; import { Fragment, createContext, useContext, useState } from "react"; import { Accordion, AccordionContent, AccordionItem, AccordionTrigger, } from "@/components/ui/accordion"; import { contents, examples } from "./sidebar-content"; import { usePathname } from "next/navigation"; import { cn } from "@/lib/utils"; interface NavbarMobileContextProps { isOpen: boolean; toggleNavbar: () => void; isDocsOpen: boolean; toggleDocsNavbar: () => void; } const NavbarContext = createContext( undefined, ); export const NavbarProvider = ({ children }: { children: React.ReactNode }) => { const [isOpen, setIsOpen] = useState(false); const [isDocsOpen, setIsDocsOpen] = useState(false); const toggleNavbar = () => { setIsOpen((prevIsOpen) => !prevIsOpen); }; const toggleDocsNavbar = () => { setIsDocsOpen((prevIsOpen) => !prevIsOpen); }; return ( {children} ); }; export const useNavbarMobile = (): NavbarMobileContextProps => { const context = useContext(NavbarContext); if (!context) { throw new Error( "useNavbarMobile must be used within a NavbarMobileProvider", ); } return context; }; export const NavbarMobileBtn: React.FC = () => { const { toggleNavbar } = useNavbarMobile(); return (
); }; export const NavbarMobile = () => { const { isOpen, toggleNavbar } = useNavbarMobile(); const pathname = usePathname(); const isDocs = pathname.startsWith("/docs"); return (
{navMenu.map((menu) => ( {menu.child ? ( {menu.name} {menu.child.map((child, j) => ( {child.name} ))} ) : ( {isDocs && ( )} {menu.name} )} ))}
); }; function DocsNavBarContent() { const pathname = usePathname(); const { toggleNavbar } = useNavbarMobile(); if (!pathname.startsWith("/docs")) return null; const content = pathname.startsWith("/docs/examples") ? examples : contents; return ( <> {content.map((menu) => (
{!!menu.Icon && } {menu.title}
{menu.list.map((child, index) => child.group ? ( // Group header rendered as div (just a divider)

{child.title}

) : ( // Regular menu item rendered as Link
{child.title}
), )} ))} ); } export const navMenu: { name: string; path: string; child?: { name: string; path: string; }[]; }[] = [ { name: "_helo", path: "/", }, { name: "docs", path: "/docs", }, { name: "examples", path: "/docs/examples/next-js", }, { name: "changelogs", path: "/changelogs", }, { name: "blogs", path: "/blog", }, { name: "community", path: "/community", }, ];