1
- // Import External Dependencies
2
1
import { useEffect , useState } from 'react' ;
3
2
import PropTypes from 'prop-types' ;
4
3
import { DocSearch } from '@docsearch/react' ;
5
4
import { Link as ReactDOMLink , NavLink , useLocation } from 'react-router-dom' ;
6
-
7
- // Import Components
8
5
import Link from '../Link/Link' ;
9
6
import Logo from '../Logo/Logo' ;
10
7
import Dropdown from '../Dropdown/Dropdown' ;
11
-
12
- // Load Styling
13
8
import '@docsearch/css' ;
14
9
15
10
import GithubIcon from '../../styles/icons/github.svg' ;
@@ -18,23 +13,18 @@ import StackOverflowIcon from '../../styles/icons/stack-overflow.svg';
18
13
import Hamburger from '../../styles/icons/hamburger.svg' ;
19
14
import HelloDarkness from '../HelloDarkness' ;
20
15
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 } ) {
28
18
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 ) {
32
20
obj = {
33
- isactive ,
21
+ isActive ,
34
22
} ;
35
23
}
24
+
36
25
const classes =
37
26
'text-gray-100 dark:text-gray-100 text-sm font-light uppercase hover:text-blue-200' ;
27
+
38
28
if ( url . startsWith ( 'http' ) || url . startsWith ( '//' ) ) {
39
29
return (
40
30
< a
@@ -47,6 +37,7 @@ function NavigationItem({ children, url, isactive }) {
47
37
</ a >
48
38
) ;
49
39
}
40
+
50
41
return (
51
42
< NavLink
52
43
{ ...obj }
@@ -60,40 +51,45 @@ function NavigationItem({ children, url, isactive }) {
60
51
) ;
61
52
}
62
53
63
- NavigationIcon . propTypes = {
54
+ NavigationItem . propTypes = {
64
55
children : PropTypes . node . isRequired ,
65
- to : PropTypes . string . isRequired ,
66
- title : PropTypes . string . isRequired ,
56
+ url : PropTypes . string . isRequired ,
57
+ isActive : PropTypes . func ,
67
58
} ;
59
+
60
+ // NavigationIcon component with tooltip
68
61
function NavigationIcon ( { children, to, title } ) {
69
62
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 >
77
76
) ;
78
77
}
78
+
79
+ NavigationIcon . propTypes = {
80
+ children : PropTypes . node . isRequired ,
81
+ to : PropTypes . string . isRequired ,
82
+ title : PropTypes . string . isRequired ,
83
+ } ;
84
+
79
85
const navigationIconProps = {
80
86
'aria-hidden' : true ,
81
87
fill : 'currentColor' ,
82
88
width : 16 ,
83
89
} ;
84
90
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
-
94
91
function Navigation ( { links, pathname, hash = '' , toggleSidebar } ) {
95
92
const [ locationHash , setLocationHash ] = useState ( hash ) ;
96
-
97
93
const location = useLocation ( ) ;
98
94
99
95
useEffect ( ( ) => {
@@ -123,6 +119,7 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
123
119
{ content }
124
120
</ NavigationItem >
125
121
) ) }
122
+ { /* Social Media Icons with Tooltips */ }
126
123
{ [
127
124
{
128
125
to : 'https://github.com/webpack/webpack' ,
@@ -188,18 +185,12 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
188
185
/>
189
186
</ div >
190
187
</ div >
191
- { /* sub navigation */ }
188
+ { /* Sub navigation */ }
192
189
{ links
193
- . filter ( ( link ) => {
194
- // only those with children are displayed
195
- return link . children ;
196
- } )
190
+ . filter ( ( link ) => link . children )
197
191
. 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 ;
203
194
}
204
195
return (
205
196
< div
@@ -240,4 +231,11 @@ function Navigation({ links, pathname, hash = '', toggleSidebar }) {
240
231
) ;
241
232
}
242
233
234
+ Navigation . propTypes = {
235
+ pathname : PropTypes . string ,
236
+ hash : PropTypes . string ,
237
+ links : PropTypes . array ,
238
+ toggleSidebar : PropTypes . func ,
239
+ } ;
240
+
243
241
export default Navigation ;
0 commit comments