1- let link = "no-underline block hover:cursor-pointer hover:text-fire-30 mb-px"
2- let activeLink = "font-medium text-fire-30 border-b border-fire"
3-
4- let linkOrActiveLink = (~target : Path .t , ~route : Path .t ) => target === route ? activeLink : link
5-
6- let isActiveLink = (~includes : string , ~excludes : option <string >= ?, ~route : Path .t ) => {
7- let route = (route :> string )
8- // includes means we want the lnk to be active if it contains the expected text
9- let includes = route -> String .includes (includes )
10- // excludes allows us to not have links be active even if they do have the includes text
11- let excludes = switch excludes {
12- | Some (excludes ) => route -> String .includes (excludes )
13- | None => false
14- }
15- includes && ! excludes ? activeLink : link
16- }
1+ open ReactRouter
2+ open NavbarUtils
173
184module MobileDrawerButton = {
195 @react.component
@@ -24,7 +10,10 @@ module MobileDrawerButton = {
2410}
2511
2612@react.component
27- let make = (~children ) => {
13+ let make = () => {
14+ let location = ReactRouter .useLocation ()
15+ let route = location .pathname
16+
2817 let scrollDirection = Hooks .useScrollDirection (~topMargin = 64 , ~threshold = 32 )
2918
3019 let navbarClasses = switch scrollDirection {
@@ -34,12 +23,36 @@ let make = (~children) => {
3423
3524 <nav
3625 dataTestId = "navbar-secondary"
37- className = {"text-12 md:text-14 shadow h-12 w-full bg-white sticky z-95 top-16 transition-transform duration-300 " ++
26+ className = {"text-12 md:text-14 shadow h-12 w-full bg-white sticky z-95 top-16 transition-transform duration-300 px-4 " ++
3827 navbarClasses }
3928 >
40- <div className = "px-4 flex gap-6 lg:gap-10 items-center h-full w-full max-w-1280 m-auto" >
41- <MobileDrawerButton hidden = false />
42- {children }
29+ <div className = "flex gap-6 lg:gap-10 items-center h-full w-full max-w-1280 m-auto" >
30+ <Link
31+ prefetch = #intent
32+ to = # "/docs/manual/introduction"
33+ className = {isActiveLink (~includes = "/docs/manual/" , ~excludes = "/api" , ~route )}
34+ >
35+ {React .string ("Language Manual" )}
36+ </Link >
37+ <Link
38+ prefetch = #intent to = # "/docs/manual/api" className = {isActiveLink (~includes = "/api" , ~route )}
39+ >
40+ {React .string ("API" )}
41+ </Link >
42+ <Link
43+ prefetch = #intent
44+ to = # "/syntax-lookup"
45+ className = {isActiveLink (~includes = "/syntax-lookup" , ~route )}
46+ >
47+ {React .string ("Syntax Lookup" )}
48+ </Link >
49+ <Link
50+ prefetch = #intent
51+ to = # "/docs/react/introduction"
52+ className = {isActiveLink (~includes = "/docs/react/" , ~route )}
53+ >
54+ {React .string ("React" )}
55+ </Link >
4356 </div >
4457 </nav >
4558}
0 commit comments