@@ -6,32 +6,50 @@ import { makeStyles, createStyles } from '@material-ui/core/styles'
66
77import { NavLink , NavLinkProps } from 'react-router-dom'
88
9- export const NavItemLink = forwardRef < HTMLAnchorElement , NavLinkProps > ( ( props , ref ) => (
10- < NavLink exact { ...props } innerRef = { ref } />
11- ) )
12-
13- export interface INavItemComponent {
9+ type NavItemComponentProps = {
1410 link ?: string
1511 className ?: string
1612 isCollapsed ?: boolean
1713 style ?: any
1814 onClick ( e : MouseEvent ) : void
1915}
2016
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+
2136// Can be a link, or button
2237export const NavItemComponent = forwardRef <
2338 HTMLDivElement ,
24- React . PropsWithChildren < INavItemComponent >
39+ React . PropsWithChildren < NavItemComponentProps >
2540> ( ( props , ref ) => {
2641 const { isCollapsed, ...newProps } = props
2742 const classes = useStyles ( )
2843
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+ } ) ( )
3553
3654 return (
3755 < div ref = { ref } className = { clsx ( isCollapsed && classes . navItemCollapsedWrapper ) } >
0 commit comments