@@ -6,32 +6,50 @@ import { makeStyles, createStyles } from '@material-ui/core/styles'
6
6
7
7
import { NavLink , NavLinkProps } from 'react-router-dom'
8
8
9
- export const NavItemLink = forwardRef < HTMLAnchorElement , NavLinkProps > ( ( props , ref ) => (
10
- < NavLink exact { ...props } innerRef = { ref } />
11
- ) )
12
-
13
- export interface INavItemComponent {
9
+ type NavItemComponentProps = {
14
10
link ?: string
15
11
className ?: string
16
12
isCollapsed ?: boolean
17
13
style ?: any
18
14
onClick ( e : MouseEvent ) : void
19
15
}
20
16
17
+ interface NavItemLinkInternalProps extends NavLinkProps { }
18
+
19
+ export const NavItemLinkInternal = forwardRef <
20
+ HTMLAnchorElement ,
21
+ NavItemLinkInternalProps
22
+ > ( ( props , ref ) => {
23
+ return < NavLink exact { ...props } innerRef = { ref } />
24
+ } )
25
+
26
+ export const NavItemLinkExternal = forwardRef < HTMLAnchorElement , NavItemComponentProps > (
27
+ ( props , ref ) => {
28
+ return (
29
+ < a { ...props } href = { props . link } ref = { ref } >
30
+ { props . children }
31
+ </ a >
32
+ )
33
+ } ,
34
+ )
35
+
21
36
// Can be a link, or button
22
37
export const NavItemComponent = forwardRef <
23
38
HTMLDivElement ,
24
- React . PropsWithChildren < INavItemComponent >
39
+ React . PropsWithChildren < NavItemComponentProps >
25
40
> ( ( props , ref ) => {
26
41
const { isCollapsed, ...newProps } = props
27
42
const classes = useStyles ( )
28
43
29
- const component =
30
- typeof props . link === 'string' ? (
31
- < ListItem { ...newProps } component = { NavItemLink } to = { props . link } />
32
- ) : (
33
- < ListItem { ...newProps } button />
34
- )
44
+ const component = ( ( ) => {
45
+ if ( ! props . link ) {
46
+ return < ListItem { ...newProps } button />
47
+ } else if ( typeof props . link === 'string' && ! props . link . includes ( 'http' ) ) {
48
+ return < ListItem { ...newProps } component = { NavItemLinkInternal } to = { props . link } />
49
+ } else if ( typeof props . link === 'string' && props . link . includes ( 'http' ) ) {
50
+ return < ListItem { ...newProps } component = { NavItemLinkExternal } />
51
+ }
52
+ } ) ( )
35
53
36
54
return (
37
55
< div ref = { ref } className = { clsx ( isCollapsed && classes . navItemCollapsedWrapper ) } >
0 commit comments