({ title, link, links, basePath, autoOpen }: NavPartProps)
| 17 | const trimLink = (str: string) => str.replace(/\/$/, ""); |
| 18 | |
| 19 | function NavPart({ title, link, links, basePath, autoOpen }: NavPartProps) { |
| 20 | const pathname = usePathname(); |
| 21 | const [isOpen, setOpen] = useState( |
| 22 | autoOpen && (pathname === link || pathname.startsWith(basePath)) |
| 23 | ); |
| 24 | |
| 25 | useEffect(() => { |
| 26 | if (!autoOpen) return; |
| 27 | if (pathname === link || pathname.startsWith(basePath)) setOpen(true); |
| 28 | else setOpen(false); |
| 29 | }, [pathname, autoOpen, basePath, link]); |
| 30 | |
| 31 | return ( |
| 32 | <div |
| 33 | className={classNames( |
| 34 | "doc-nav transition-all duration-300", |
| 35 | isOpen && links?.length ? "mb-8" : "mb-4" |
| 36 | )} |
| 37 | > |
| 38 | <div |
| 39 | className={classNames( |
| 40 | "flex flex-row items-center text-left", |
| 41 | pathname === link || |
| 42 | (pathname.startsWith(basePath) && basePath !== "") |
| 43 | ? "text-blue" |
| 44 | : "text-gray-700 dark:text-white" |
| 45 | )} |
| 46 | > |
| 47 | {link ? ( |
| 48 | <Link |
| 49 | href={link} |
| 50 | prefetch={false} |
| 51 | className={classNames( |
| 52 | "flex-1 font-semibold uppercase doc-category", |
| 53 | pathname === link || |
| 54 | (pathname.startsWith(basePath) && |
| 55 | basePath !== "" && |
| 56 | "is-active") // for docsearch |
| 57 | )} |
| 58 | > |
| 59 | {title} |
| 60 | </Link> |
| 61 | ) : ( |
| 62 | <p |
| 63 | role="button" |
| 64 | onClick={() => setOpen(!isOpen)} |
| 65 | className={classNames( |
| 66 | "flex-1 font-semibold uppercase doc-category", |
| 67 | pathname === link || |
| 68 | (pathname.startsWith(basePath) && |
| 69 | basePath !== "" && |
| 70 | "is-active") // for docsearch |
| 71 | )} |
| 72 | > |
| 73 | {title} |
| 74 | </p> |
| 75 | )} |
| 76 | <button |
nothing calls this directly
no test coverage detected