|
1 | | -import React, { useEffect, useRef, useState } from 'react'; |
| 1 | +import React from 'react'; |
2 | 2 | import Link from '@docusaurus/Link'; |
3 | 3 | import clsx from 'clsx'; |
4 | 4 | import { FaChevronDown } from 'react-icons/fa'; |
5 | 5 | import { useSecondaryNavState } from '@theme/Navbar/hooks/useSecondaryNavState'; |
6 | 6 | import { ProductLink, DropdownItem } from '@site/secondaryNavbar'; |
7 | 7 | import styles from './styles.module.scss'; |
8 | 8 |
|
9 | | -export default function SecondaryNavbar(): React.JSX.Element | null { |
10 | | - const navbarRef = useRef<HTMLDivElement>(null); |
11 | | - const placeholderRef = useRef<HTMLDivElement>(null); |
12 | | - const [isFixed, setIsFixed] = useState(false); |
13 | | - |
| 9 | +export default function SecondaryNavbar(): React.JSX.Element { |
14 | 10 | // Get secondary navbar state from shared hook |
15 | 11 | const { product, productLinks, activeSidebar } = useSecondaryNavState(); |
16 | 12 |
|
17 | | - // Handle fixed positioning when scrolling past main navbar |
18 | | - useEffect(() => { |
19 | | - const handleScroll = () => { |
20 | | - const mainNavbar = document.querySelector('.navbar') as HTMLElement | null; |
21 | | - if (mainNavbar && navbarRef.current) { |
22 | | - // Check if we've scrolled past the main navbar |
23 | | - if (window.scrollY > mainNavbar.offsetHeight) { |
24 | | - setIsFixed(true); |
25 | | - } else { |
26 | | - setIsFixed(false); |
27 | | - } |
28 | | - } |
29 | | - }; |
30 | | - |
31 | | - // Check initial position (handles anchor links on page load) |
32 | | - handleScroll(); |
33 | | - |
34 | | - window.addEventListener('scroll', handleScroll); |
35 | | - window.addEventListener('load', handleScroll); |
36 | | - |
37 | | - return () => { |
38 | | - window.removeEventListener('scroll', handleScroll); |
39 | | - window.removeEventListener('load', handleScroll); |
40 | | - }; |
41 | | - }, []); |
42 | | - |
43 | | - // Signal to main navbar that secondary navbar exists |
44 | | - // COMMENTED OUT FOR TESTING - showing both navbar borders |
45 | | - // useEffect(() => { |
46 | | - // // Only add class if we're actually going to show the secondary navbar |
47 | | - // if (!product || !productLinks || productLinks.length <= 1) { |
48 | | - // return; // Don't add class if not rendering |
49 | | - // } |
50 | | - |
51 | | - // const mainNavbar = document.querySelector('.navbar:not(.secondaryNavbar)'); |
52 | | - // if (mainNavbar) { |
53 | | - // mainNavbar.classList.add('has-secondary-navbar'); |
54 | | - // } |
55 | | - |
56 | | - // return () => { |
57 | | - // const mainNavbar = document.querySelector('.navbar:not(.secondaryNavbar)'); |
58 | | - // if (mainNavbar) { |
59 | | - // mainNavbar.classList.remove('has-secondary-navbar'); |
60 | | - // } |
61 | | - // }; |
62 | | - // }, [product, productLinks]); |
63 | | - |
64 | | - // Don't show if no product or only 1 link |
65 | | - if (!product || !productLinks || productLinks.length <= 1) { |
66 | | - return null; |
67 | | - } |
68 | | - |
69 | 13 | return ( |
70 | | - <> |
71 | | - <nav |
72 | | - ref={navbarRef} |
73 | | - className={clsx('navbar', styles.secondaryNavbar, isFixed && styles.fixedTop)} |
74 | | - > |
75 | | - <div className="navbar__inner"> |
76 | | - <div className="navbar__items"> |
77 | | - {productLinks.map((item: ProductLink, index: number) => { |
78 | | - if (item.dropdown) { |
79 | | - // Dropdown support (optional) |
80 | | - return ( |
81 | | - <div key={index} className="navbar__item dropdown dropdown--hoverable"> |
82 | | - <a href="#" className="navbar__link" onClick={(e) => e.preventDefault()}> |
83 | | - {item.label} |
84 | | - <FaChevronDown aria-hidden="true" style={{ marginLeft: '0.3em', fontSize: '0.8em' }} /> |
85 | | - </a> |
86 | | - <ul className="dropdown__menu"> |
87 | | - {item.dropdown.map((subItem: DropdownItem, subIndex: number) => ( |
88 | | - <li key={subIndex}> |
89 | | - <Link |
90 | | - to={subItem.link} |
91 | | - className="dropdown__link" |
92 | | - > |
93 | | - {subItem.label} |
94 | | - </Link> |
95 | | - </li> |
96 | | - ))} |
97 | | - </ul> |
98 | | - </div> |
99 | | - ); |
100 | | - } |
101 | | - |
102 | | - // Regular link - determine if active based on sidebar name |
103 | | - const isActive = activeSidebar && item.sidebar === activeSidebar; |
104 | | - |
| 14 | + <div className={styles.secondaryNavbar}> |
| 15 | + <div className="navbar__inner"> |
| 16 | + {/* LEFT CONTAINER - Product navigation links */} |
| 17 | + <div className="theme-layout-navbar-left navbar__items"> |
| 18 | + {productLinks && productLinks.length > 1 && productLinks.map((item: ProductLink, index: number) => { |
| 19 | + if (item.dropdown) { |
| 20 | + // Dropdown support (optional) |
105 | 21 | return ( |
106 | | - <Link |
107 | | - key={index} |
108 | | - to={item.link} |
109 | | - className={clsx( |
110 | | - 'navbar__item navbar__link', |
111 | | - isActive && 'navbar__link--active' // Infima active class (color, no underline) |
112 | | - )} |
113 | | - > |
114 | | - {item.label} |
115 | | - </Link> |
| 22 | + <div key={index} className="navbar__item dropdown dropdown--hoverable"> |
| 23 | + <a href="#" className="navbar__link" onClick={(e) => e.preventDefault()}> |
| 24 | + {item.label} |
| 25 | + <FaChevronDown aria-hidden="true" style={{ marginLeft: '0.3em', fontSize: '0.8em' }} /> |
| 26 | + </a> |
| 27 | + <ul className="dropdown__menu"> |
| 28 | + {item.dropdown.map((subItem: DropdownItem, subIndex: number) => ( |
| 29 | + <li key={subIndex}> |
| 30 | + <Link |
| 31 | + to={subItem.link} |
| 32 | + className="dropdown__link" |
| 33 | + > |
| 34 | + {subItem.label} |
| 35 | + </Link> |
| 36 | + </li> |
| 37 | + ))} |
| 38 | + </ul> |
| 39 | + </div> |
116 | 40 | ); |
117 | | - })} |
118 | | - </div> |
119 | | - <div className="navbar__items navbar__items--right"> |
120 | | - {/* Empty - provides proper flex layout for full width */} |
121 | | - </div> |
| 41 | + } |
| 42 | + |
| 43 | + // Regular link - determine if active based on sidebar name |
| 44 | + const isActive = activeSidebar && item.sidebar === activeSidebar; |
| 45 | + |
| 46 | + return ( |
| 47 | + <Link |
| 48 | + key={index} |
| 49 | + to={item.link} |
| 50 | + className={clsx( |
| 51 | + 'navbar__item navbar__link', |
| 52 | + isActive && 'navbar__link--active' // Infima active class (color, no underline) |
| 53 | + )} |
| 54 | + > |
| 55 | + {item.label} |
| 56 | + </Link> |
| 57 | + ); |
| 58 | + })} |
| 59 | + </div> |
| 60 | + {/* RIGHT CONTAINER - Empty for now, ready for future right-aligned items */} |
| 61 | + <div className="theme-layout-navbar-right navbar__items navbar__items--right"> |
122 | 62 | </div> |
123 | | - </nav> |
124 | | - {/* Placeholder to prevent content jump when navbar becomes fixed */} |
125 | | - {isFixed && ( |
126 | | - <div ref={placeholderRef} className={styles.placeholder} /> |
127 | | - )} |
128 | | - </> |
| 63 | + </div> |
| 64 | + </div> |
129 | 65 | ); |
130 | 66 | } |
0 commit comments