-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomNavLink.js
58 lines (51 loc) · 1.22 KB
/
customNavLink.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
import { forwardRef } from 'react'
import { NavLink as BaseNavLink } from 'react-router-dom'
/* //> Custom NavLink Code
Modified version from react router official docs
https://reactrouter.com/en/main/components/nav-link
*/
/* //> ORIGINAL CODE from source:
import * as React from "react";
import { NavLink as BaseNavLink } from "react-router-dom";
const NavLink = React.forwardRef(
({ activeClassName, activeStyle, ...props }, ref) => {
return (
<BaseNavLink
ref={ref}
{...props}
className={({ isActive }) =>
[
props.className,
isActive ? activeClassName : null,
]
.filter(Boolean)
.join(" ")
}
style={({ isActive }) => ({
...props.style,
...(isActive ? activeStyle : null),
})}
/>
);
}
);
*/
const activeLink = {
backgroundColor: '#760817',
color: '#7edf7e',
}
const CustomNavLink = forwardRef(
({ activeStyle, ...props }, ref) => {
return (
<BaseNavLink
ref={ref}
{...props}
style={({ isActive }) => ({
...props.style,
...(isActive ? activeLink : undefined)
})}
/>
);
}
);
export { CustomNavLink }