11import React from 'react'
2- import { NavLink , useLocation } from 'react-router-dom'
2+ import { NavLink } from 'react-router-dom'
33import PropTypes from 'prop-types'
44
5- import { CBadge } from '@coreui/react'
5+ import SimpleBar from 'simplebar-react'
6+ import 'simplebar-react/dist/simplebar.min.css'
7+
8+ import { CBadge , CNavLink , CSidebarNav } from '@coreui/react'
69
710export const AppSidebarNav = ( { items } ) => {
8- const location = useLocation ( )
911 const navLink = ( name , icon , badge , indent = false ) => {
1012 return (
1113 < >
@@ -30,30 +32,23 @@ export const AppSidebarNav = ({ items }) => {
3032 const { component, name, badge, icon, ...rest } = item
3133 const Component = component
3234 return (
33- < Component
34- { ...( rest . to &&
35- ! rest . items && {
36- component : NavLink ,
37- } ) }
38- key = { index }
39- { ...rest }
40- >
41- { navLink ( name , icon , badge , indent ) }
35+ < Component as = "div" key = { index } >
36+ { rest . to || rest . href ? (
37+ < CNavLink { ...( rest . to && { as : NavLink } ) } { ...rest } >
38+ { navLink ( name , icon , badge , indent ) }
39+ </ CNavLink >
40+ ) : (
41+ navLink ( name , icon , badge , indent )
42+ ) }
4243 </ Component >
4344 )
4445 }
46+
4547 const navGroup = ( item , index ) => {
4648 const { component, name, icon, items, to, ...rest } = item
4749 const Component = component
4850 return (
49- < Component
50- compact
51- idx = { String ( index ) }
52- key = { index }
53- toggler = { navLink ( name , icon ) }
54- visible = { location . pathname . startsWith ( to ) }
55- { ...rest }
56- >
51+ < Component compact as = "div" key = { index } toggler = { navLink ( name , icon ) } { ...rest } >
5752 { item . items ?. map ( ( item , index ) =>
5853 item . items ? navGroup ( item , index ) : navItem ( item , index , true ) ,
5954 ) }
@@ -62,10 +57,10 @@ export const AppSidebarNav = ({ items }) => {
6257 }
6358
6459 return (
65- < React . Fragment >
60+ < CSidebarNav as = { SimpleBar } >
6661 { items &&
6762 items . map ( ( item , index ) => ( item . items ? navGroup ( item , index ) : navItem ( item , index ) ) ) }
68- </ React . Fragment >
63+ </ CSidebarNav >
6964 )
7065}
7166
0 commit comments