-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainNav.js
72 lines (60 loc) · 2.26 KB
/
MainNav.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { NavLink } from 'react-router-dom'
import { CustomNavLink } from './shared/customNavLink'
import navigationStyles from './shared/navigation.module.css'
import './shared/_navigation.css'
const { mainNav, specialLink, activeNavLink } = navigationStyles
/* only used for NavLink to='/' */
const activeLink = {
backgroundColor: '#a258bb',
backgroundImage: 'linear-gradient(40deg, #61762e 24%, #6e26a4 80%)',
}
const MainNav = ({ handleUIChange }) => {
return (
<nav className={mainNav} >
<ul>
{/* //> Using NavLink's `isActive` prop to conditionally apply style (activeLink) */}
<li><NavLink
to='/'
end /* //> forces to only add 'active' class if current path is EXACTLY '/' */
style={({ isActive }) => (isActive ? activeLink : {})}
>
Home
</NavLink></li>
{/* //> Notice that all `to` values beyond this comment are in 'relative path' */}
<li><CustomNavLink to='about' >About</CustomNavLink></li>
<li><CustomNavLink to='challenges' >Challenges</CustomNavLink></li>
{/* //! Unable to combine 'active' class from NavLink and class from css module
code below uses NavLink's isActive prop to
conditionally apply .activeNavLink from css module
//NOTE: a custom NavLink can also be created similar to
import { CustomNavLink } from './shared/customNavLink' */}
<li><NavLink
to='contact'
className={({ isActive }) => (isActive ? activeNavLink : null)}
>
Contact
</NavLink></li>
<li><NavLink
to='blog'
className={({ isActive }) => (isActive ? activeNavLink : null)}
>
Blog
</NavLink></li>
{/* //> Using plain .css to style NavLink */}
<li><NavLink className='cssNavLink' to='updates' >Updates</NavLink></li>
<li><NavLink className='cssNavLink' to='navigate' >Navigate</NavLink></li>
<li><CustomNavLink to='search'>Live Search</CustomNavLink></li>
<li>
<NavLink
to='useRoutes'
onClick={handleUIChange}
className={specialLink}
>
useRoutes
</NavLink>
</li>
</ul>
</nav>
)
}
export { MainNav }