1- // Import External Dependencies
21import { useEffect , useState } from 'react' ;
32import PropTypes from 'prop-types' ;
43import { DocSearch } from '@docsearch/react' ;
54import { Link as ReactDOMLink , NavLink , useLocation } from 'react-router-dom' ;
6-
7- // Import Components
85import Link from '../Link/Link' ;
96import Logo from '../Logo/Logo' ;
107import Dropdown from '../Dropdown/Dropdown' ;
11-
12- // Load Styling
138import '@docsearch/css' ;
149
1510import GithubIcon from '../../styles/icons/github.svg' ;
@@ -18,23 +13,18 @@ import StackOverflowIcon from '../../styles/icons/stack-overflow.svg';
1813import Hamburger from '../../styles/icons/hamburger.svg' ;
1914import HelloDarkness from '../HelloDarkness' ;
2015
21- NavigationItem . propTypes = {
22- children : PropTypes . node . isRequired ,
23- url : PropTypes . string . isRequired ,
24- isactive : PropTypes . func ,
25- } ;
26-
27- function NavigationItem ( { children, url, isactive } ) {
16+ // NavigationItem Component
17+ function NavigationItem ( { children, url, isActive } ) {
2818 let obj = { } ;
29- // decide if the link is active or not by providing a function
30- // otherwise we'll let react-dom makes the decision for us
31- if ( isactive ) {
19+ if ( isActive ) {
3220 obj = {
33- isactive ,
21+ isActive ,
3422 } ;
3523 }
24+
3625 const classes =
3726 'text-gray-100 dark:text-gray-100 text-sm font-light uppercase hover:text-blue-200' ;
27+
3828 if ( url . startsWith ( 'http' ) || url . startsWith ( '//' ) ) {
3929 return (
4030 < a
@@ -47,6 +37,7 @@ function NavigationItem({ children, url, isactive }) {
4737 </ a >
4838 ) ;
4939 }
40+
5041 return (
5142 < NavLink
5243 { ...obj }
@@ -60,40 +51,45 @@ function NavigationItem({ children, url, isactive }) {
6051 ) ;
6152}
6253
63- NavigationIcon . propTypes = {
54+ NavigationItem . propTypes = {
6455 children : PropTypes . node . isRequired ,
65- to : PropTypes . string . isRequired ,
66- title : PropTypes . string . isRequired ,
56+ url : PropTypes . string . isRequired ,
57+ isActive : PropTypes . func ,
6758} ;
59+
60+ // NavigationIcon component with tooltip
6861function NavigationIcon ( { children, to, title } ) {
6962 return (
70- < Link
71- to = { to }
72- className = "inline-flex items-center text-gray-100 dark:text-gray-200 hover:text-blue-200"
73- title = { `webpack on ${ title } ` }
74- >
75- { children }
76- </ Link >
63+ < div className = "relative group inline-flex flex-col items-center" >
64+ < Link
65+ to = { to }
66+ className = "inline-flex items-center text-gray-100 dark:text-gray-200 hover:text-blue-200"
67+ title = { `webpack on ${ title } ` }
68+ >
69+ { children }
70+ </ Link >
71+ { /* Tooltip */ }
72+ < div className = "absolute top-full mt-2 px-3 py-1 bg-blue-500 text-white text-sm rounded shadow-md opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none" >
73+ { title }
74+ </ div >
75+ </ div >
7776 ) ;
7877}
78+
79+ NavigationIcon . propTypes = {
80+ children : PropTypes . node . isRequired ,
81+ to : PropTypes . string . isRequired ,
82+ title : PropTypes . string . isRequired ,
83+ } ;
84+
7985const navigationIconProps = {
8086 'aria-hidden' : true ,
8187 fill : 'currentColor' ,
8288 width : 16 ,
8389} ;
8490
85- Navigation . propTypes = {
86- pathname : PropTypes . string ,
87- hash : PropTypes . string ,
88- links : PropTypes . array ,
89- toggleSidebar : PropTypes . func ,
90- theme : PropTypes . string ,
91- switchTheme : PropTypes . func ,
92- } ;
93-
9491function Navigation ( { links, pathname, hash = '' , toggleSidebar } ) {
9592 const [ locationHash , setLocationHash ] = useState ( hash ) ;
96-
9793 const location = useLocation ( ) ;
9894
9995 useEffect ( ( ) => {
@@ -123,6 +119,7 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
123119 { content }
124120 </ NavigationItem >
125121 ) ) }
122+ { /* Social Media Icons with Tooltips */ }
126123 { [
127124 {
128125 to : 'https://github.com/webpack/webpack' ,
@@ -188,18 +185,12 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
188185 />
189186 </ div >
190187 </ div >
191- { /* sub navigation */ }
188+ { /* Sub navigation */ }
192189 { links
193- . filter ( ( link ) => {
194- // only those with children are displayed
195- return link . children ;
196- } )
190+ . filter ( ( link ) => link . children )
197191 . map ( ( link ) => {
198- if ( link . isactive ) {
199- // hide the children if the link is not active
200- if ( ! link . isactive ( { } , location ) ) {
201- return null ;
202- }
192+ if ( link . isActive && ! link . isActive ( { } , location ) ) {
193+ return null ;
203194 }
204195 return (
205196 < div
@@ -240,4 +231,11 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
240231 ) ;
241232}
242233
234+ Navigation . propTypes = {
235+ pathname : PropTypes . string ,
236+ hash : PropTypes . string ,
237+ links : PropTypes . array ,
238+ toggleSidebar : PropTypes . func ,
239+ } ;
240+
243241export default Navigation ;
0 commit comments