1
1
import React from 'react' ;
2
2
import classNames from 'classnames' ;
3
- import PropTypes from 'prop-types' ;
4
3
import { NavLink } from 'react-router-dom' ;
5
4
import { makeStyles } from '@material-ui/core/styles' ;
6
5
import Drawer from '@material-ui/core/Drawer' ;
@@ -11,30 +10,53 @@ import ListItemText from '@material-ui/core/ListItemText';
11
10
import Icon from '@material-ui/core/Icon' ;
12
11
import styles from '../../assets/jss/material-dashboard-react/components/sidebarStyle' ;
13
12
14
- const useStyles = makeStyles ( styles ) ;
13
+ const useStyles = makeStyles ( styles as any ) ;
15
14
16
- export default function Sidebar ( props ) {
15
+ interface Route {
16
+ path : string ;
17
+ layout : string ;
18
+ name : string ;
19
+ icon : string | React . ComponentType ;
20
+ visible ?: boolean ;
21
+ rtlName ?: string ;
22
+ component : React . ComponentType ;
23
+ }
24
+
25
+ interface SidebarProps {
26
+ color : 'purple' | 'blue' | 'green' | 'orange' | 'red' ;
27
+ logo : string ;
28
+ routes : Route [ ] ;
29
+ background : string ;
30
+ rtlActive ?: boolean ;
31
+ handleDrawerToggle : ( ) => void ;
32
+ open : boolean ;
33
+ }
34
+
35
+ const Sidebar : React . FC < SidebarProps > = ( props ) => {
17
36
const classes = useStyles ( ) ;
18
- // verifies if routeName is the one active (in browser input)
19
- function activeRoute ( routeName ) {
20
- return window . location . href . indexOf ( routeName ) > - 1 ? true : false ;
21
- }
22
- const { color, logo, routes, background } = props ;
37
+
38
+ const activeRoute = ( routeName : string ) : boolean => {
39
+ return window . location . href . indexOf ( routeName ) > - 1 ;
40
+ } ;
41
+
42
+ const { color, logo, routes, background, rtlActive, open, handleDrawerToggle } = props ;
43
+
23
44
const links = (
24
45
< List className = { classes . list } >
25
46
{ routes . map ( ( prop , key ) => {
26
47
const activePro = ' ' ;
27
48
const listItemClasses = classNames ( {
28
- [ ' ' + classes [ color ] ] : activeRoute ( prop . layout + prop . path ) ,
49
+ [ ` ${ classes [ color ] } ` ] : activeRoute ( prop . layout + prop . path ) ,
29
50
} ) ;
30
51
31
52
const whiteFontClasses = classNames ( {
32
- [ ' ' + classes . whiteFont ] : activeRoute ( prop . layout + prop . path ) ,
53
+ [ ` ${ classes . whiteFont } ` ] : activeRoute ( prop . layout + prop . path ) ,
33
54
} ) ;
34
55
35
56
if ( ! prop . visible ) {
36
57
return < div key = { key } > </ div > ;
37
58
}
59
+
38
60
return (
39
61
< NavLink
40
62
to = { prop . layout + prop . path }
@@ -46,22 +68,22 @@ export default function Sidebar(props) {
46
68
{ typeof prop . icon === 'string' ? (
47
69
< Icon
48
70
className = { classNames ( classes . itemIcon , whiteFontClasses , {
49
- [ classes . itemIconRTL ] : props . rtlActive ,
71
+ [ classes . itemIconRTL ] : rtlActive ,
50
72
} ) }
51
73
>
52
74
{ prop . icon }
53
75
</ Icon >
54
76
) : (
55
77
< prop . icon
56
78
className = { classNames ( classes . itemIcon , whiteFontClasses , {
57
- [ classes . itemIconRTL ] : props . rtlActive ,
79
+ [ classes . itemIconRTL ] : rtlActive ,
58
80
} ) }
59
81
/>
60
82
) }
61
83
< ListItemText
62
- primary = { props . rtlActive ? prop . rtlName : prop . name }
84
+ primary = { rtlActive ? prop . rtlName : prop . name }
63
85
className = { classNames ( classes . itemText , whiteFontClasses , {
64
- [ classes . itemTextRTL ] : props . rtlActive ,
86
+ [ classes . itemTextRTL ] : rtlActive ,
65
87
} ) }
66
88
disableTypography = { true }
67
89
/>
@@ -71,6 +93,7 @@ export default function Sidebar(props) {
71
93
} ) }
72
94
</ List >
73
95
) ;
96
+
74
97
const brand = (
75
98
< div className = { classes . logo } >
76
99
< a style = { { textDecoration : 'none' } } href = '/dashboard/repo' >
@@ -85,21 +108,22 @@ export default function Sidebar(props) {
85
108
</ a >
86
109
</ div >
87
110
) ;
111
+
88
112
return (
89
113
< div style = { { borderRight : '1px solid #d3d3d3' } } >
90
114
< Hidden mdUp implementation = 'css' >
91
115
< Drawer
92
116
variant = 'temporary'
93
- anchor = { props . rtlActive ? 'left' : 'right' }
94
- open = { props . open }
117
+ anchor = { rtlActive ? 'left' : 'right' }
118
+ open = { open }
95
119
classes = { {
96
120
paper : classNames ( classes . drawerPaper , {
97
- [ classes . drawerPaperRTL ] : props . rtlActive ,
121
+ [ classes . drawerPaperRTL ] : rtlActive ,
98
122
} ) ,
99
123
} }
100
- onClose = { props . handleDrawerToggle }
124
+ onClose = { handleDrawerToggle }
101
125
ModalProps = { {
102
- keepMounted : true , // Better open performance on mobile.
126
+ keepMounted : true ,
103
127
} }
104
128
>
105
129
{ brand }
@@ -109,12 +133,12 @@ export default function Sidebar(props) {
109
133
</ Hidden >
110
134
< Hidden smDown implementation = 'css' >
111
135
< Drawer
112
- anchor = { props . rtlActive ? 'right' : 'left' }
136
+ anchor = { rtlActive ? 'right' : 'left' }
113
137
variant = 'permanent'
114
138
open
115
139
classes = { {
116
140
paper : classNames ( classes . drawerPaper , {
117
- [ classes . drawerPaperRTL ] : props . rtlActive ,
141
+ [ classes . drawerPaperRTL ] : rtlActive ,
118
142
} ) ,
119
143
} }
120
144
>
@@ -125,14 +149,6 @@ export default function Sidebar(props) {
125
149
</ Hidden >
126
150
</ div >
127
151
) ;
128
- }
129
-
130
- Sidebar . propTypes = {
131
- rtlActive : PropTypes . bool ,
132
- handleDrawerToggle : PropTypes . func ,
133
- bgColor : PropTypes . oneOf ( [ 'purple' , 'blue' , 'green' , 'orange' , 'red' ] ) ,
134
- logo : PropTypes . string ,
135
- image : PropTypes . string ,
136
- routes : PropTypes . arrayOf ( PropTypes . object ) ,
137
- open : PropTypes . bool ,
138
152
} ;
153
+
154
+ export default Sidebar ;
0 commit comments