"use client"; import {useRef, useState, FC, ReactNode, Key, useMemo, useCallback} from "react"; import { link, Navbar as HeroUINavbar, NavbarContent, NavbarMenu, NavbarMenuToggle, NavbarBrand, NavbarItem, Link, Button, Kbd, Dropdown, DropdownMenu, DropdownItem, DropdownTrigger, Chip, Divider, } from "@heroui/react"; import {dataFocusVisibleClasses} from "@heroui/theme"; import {ChevronDownIcon, LinkIcon} from "@heroui/shared-icons"; import {isAppleDevice} from "@react-aria/utils"; import {clsx} from "@heroui/shared-utils"; import NextLink from "next/link"; import {usePathname} from "next/navigation"; import {motion, AnimatePresence} from "framer-motion"; import {useEffect} from "react"; import {usePress} from "@react-aria/interactions"; import {useFocusRing} from "@react-aria/focus"; import {usePostHog} from "posthog-js/react"; import {FbRoadmapLink} from "./featurebase/fb-roadmap-link"; import {currentVersion} from "@/utils/version"; import {siteConfig} from "@/config/site"; import {Route} from "@/libs/docs/page"; import {LargeLogo, SmallLogo, ThemeSwitch} from "@/components"; import {GithubIcon, SearchLinearIcon} from "@/components/icons"; import {useIsMounted} from "@/hooks/use-is-mounted"; import {DocsSidebar} from "@/components/docs/sidebar"; import {useCmdkStore} from "@/components/cmdk"; import githubInfo from "@/config/github-info.json"; export interface NavbarProps { routes: Route[]; mobileRoutes?: Route[]; tag?: string; slug?: string; children?: ReactNode; } export const Navbar: FC = ({children, routes, mobileRoutes = [], slug, tag}) => { const [isMenuOpen, setIsMenuOpen] = useState(false); const [commandKey, setCommandKey] = useState<"ctrl" | "command">("command"); const ref = useRef(null); const isMounted = useIsMounted(); const pathname = usePathname(); const cmdkStore = useCmdkStore(); const posthog = usePostHog(); useEffect(() => { if (isMenuOpen) { setIsMenuOpen(false); } }, [pathname]); useEffect(() => { setCommandKey(isAppleDevice() ? "command" : "ctrl"); }, []); const handleOpenCmdk = () => { cmdkStore.onOpen(); posthog.capture("Navbar - Search", { name: "navbar - search", action: "press", category: "cmdk", }); }; const {pressProps} = usePress({ onPress: handleOpenCmdk, }); const {focusProps, isFocusVisible} = useFocusRing(); const docsPaths = [ "/docs/guide/introduction", "/docs/guide/installation", "/docs/guide/upgrade-to-v2", ]; const navLinkClasses = clsx( link({color: "foreground"}), "data-[active=true]:text-primary data-[active=true]:font-semibold", ); const handleVersionChange = useCallback((key: Key) => { if (key === "v1") { const newWindow = window.open("https://v1.heroui.com", "_blank", "noopener,noreferrer"); if (newWindow) newWindow.opener = null; } }, []); const handlePressNavbarItem = useCallback( (name: string, url: string) => { posthog.capture("NavbarItem", { name, action: "press", category: "navbar", data: url, }); }, [posthog], ); const searchButton = ( ); const versionDropdown = useMemo(() => { return ref.current ? ( {isMounted && ( )} v{currentVersion} }> v1.0.0 ) : (
); }, [ref.current, isMounted]); if (pathname.includes("/examples")) { return null; } return ( handlePressNavbarItem("Home", "/")} > {versionDropdown} handlePressNavbarItem("Introducing HeroUI", "/blog/introducing-heroui")} > Introducing HeroUI  🔥 handlePressNavbarItem("Github", siteConfig.links.github)} >
    handlePressNavbarItem("Docs", "/docs/guide/introduction")} > Docs handlePressNavbarItem("Components", "/docs/components/accordion")} > Components {/* // TODO: add playground handlePressNavbarItem("playground", "/playground")} > Playground */} handlePressNavbarItem("Figma", "/docs/guide/figma")} > Figma handlePressNavbarItem("Blog", "/blog")} > Blog
{searchButton} handlePressNavbarItem("Github", siteConfig.links.github)} > {githubInfo.stars.formatted} {/* */}
{children}
); };