1
1
import { Icon , IconProps } from '@iconify/react' ;
2
- import { styled , Tooltip } from '@mui/material' ;
3
- import ListItem from '@mui/material/ListItem' ;
2
+ import { alpha , ListItemButton , styled , Tooltip } from '@mui/material' ;
4
3
import ListItemIcon from '@mui/material/ListItemIcon' ;
5
4
import ListItemText from '@mui/material/ListItemText' ;
6
5
import React from 'react' ;
@@ -17,17 +16,32 @@ interface ListItemLinkProps {
17
16
subtitle ?: string ;
18
17
icon ?: IconProps [ 'icon' ] ;
19
18
iconOnly ?: boolean ;
19
+ hasParent ?: boolean ;
20
+ fullWidth ?: boolean ;
20
21
containerProps ?: {
21
22
[ prop : string ] : any ;
22
23
} ;
23
24
}
24
25
25
- // make a styled() li
26
- const StyledLi = styled ( 'li' ) ( ) ;
26
+ const StyledLi = styled ( 'li' ) < { hasParent ?: boolean } > ( ( { hasParent } ) => ( {
27
+ marginRight : '5px' ,
28
+ marginLeft : hasParent ? '35px' : '5px' ,
29
+ marginBottom : '1px' ,
30
+ } ) ) ;
27
31
28
32
export default function ListItemLink ( props : ListItemLinkProps ) {
29
- const { primary, pathname, search, icon, name, containerProps, iconOnly, subtitle, ...other } =
30
- props ;
33
+ const {
34
+ primary,
35
+ pathname,
36
+ search,
37
+ icon,
38
+ name,
39
+ iconOnly,
40
+ subtitle,
41
+ hasParent,
42
+ fullWidth,
43
+ ...other
44
+ } = props ;
31
45
32
46
const iconSize = React . useMemo (
33
47
( ) => ( iconOnly ? CollapsedIconSize : ExpandedIconSize ) ,
@@ -72,12 +86,118 @@ export default function ListItemLink(props: ListItemLinkProps) {
72
86
) ;
73
87
}
74
88
89
+ const hasSubtitle = Boolean ( subtitle ) ;
90
+
75
91
return (
76
- < StyledLi { ...containerProps } >
77
- < ListItem button component = { renderLink } { ...other } >
92
+ < StyledLi hasParent = { hasParent } >
93
+ < ListItemButton
94
+ component = { renderLink }
95
+ { ...other }
96
+ sx = { theme => ( {
97
+ color :
98
+ theme . palette . sidebar . color ??
99
+ theme . palette . getContrastText ( theme . palette . sidebar . background ) ,
100
+ margin : 0 ,
101
+ borderRadius : theme . shape . borderRadius + 'px' ,
102
+ height : iconOnly ? '50px' : undefined ,
103
+ opacity : hasParent ? 0.9 : 1.0 ,
104
+ fontSize : hasParent ? '0.85rem' : '1rem' ,
105
+
106
+ svg : {
107
+ color : 'currentColor' ,
108
+ } ,
109
+
110
+ '&.Mui-selected' : hasParent
111
+ ? {
112
+ ':before' : {
113
+ content : "''" ,
114
+ width : '4px' ,
115
+ borderRadius : theme . shape . borderRadius + 'px' ,
116
+ background : theme . palette . sidebar . selectedColor ,
117
+ position : 'absolute' ,
118
+ left : '4px' ,
119
+ top : '7px' ,
120
+ bottom : '7px' ,
121
+ } ,
122
+ opacity : 1.0 ,
123
+ color : theme . palette . sidebar . selectedColor ,
124
+ background : 'none' ,
125
+ }
126
+ : {
127
+ opacity : 1.0 ,
128
+ boxShadow : '1px 1px 4px rgb(0 0 0 / 12%)' ,
129
+ background : theme . palette . sidebar . selectedBackground ,
130
+ color : theme . palette . getContrastText ( theme . palette . sidebar . selectedBackground ) ,
131
+ } ,
132
+
133
+ '&.Mui-selected:hover' : hasParent
134
+ ? {
135
+ backgroundColor : alpha (
136
+ theme . palette . getContrastText ( theme . palette . sidebar . background ) ,
137
+ 0.07
138
+ ) ,
139
+ }
140
+ : {
141
+ backgroundColor : alpha ( theme . palette . sidebar . selectedBackground , 0.8 ) ,
142
+ } ,
143
+
144
+ ':hover' : {
145
+ backgroundColor : alpha (
146
+ theme . palette . getContrastText ( theme . palette . sidebar . background ) ,
147
+ 0.07
148
+ ) ,
149
+ } ,
150
+
151
+ '.MuiListItemIcon-root' : {
152
+ color : 'unset' ,
153
+ } ,
154
+
155
+ '.MuiListItemText-root' : {
156
+ margin : 0 ,
157
+ } ,
158
+
159
+ '& *' : {
160
+ fontSize : '.875rem' ,
161
+ textTransform : 'none' ,
162
+ } ,
163
+ '& .MuiListItem-root' : {
164
+ paddingTop : '4px' ,
165
+ paddingBottom : '4px' ,
166
+ } ,
167
+
168
+ '& .MuiListItemIcon-root' : {
169
+ minWidth : 0 ,
170
+ alignSelf : fullWidth && hasSubtitle ? 'stretch' : 'auto' ,
171
+ paddingTop : fullWidth && hasSubtitle ? theme . spacing ( 1 ) : 0 ,
172
+ marginRight : fullWidth ? '8px' : '0' ,
173
+ } ,
174
+ '& .MuiListItemText-secondary' : {
175
+ fontSize : '.85rem' ,
176
+ fontStyle : 'italic' ,
177
+ whiteSpace : 'nowrap' ,
178
+ textOverflow : 'ellipsis' ,
179
+ overflowWrap : 'anywhere' ,
180
+ overflow : 'hidden' ,
181
+ color : 'currentColor' ,
182
+ } ,
183
+
184
+ ...( ! hasParent && {
185
+ '& .MuiListItem-root' : {
186
+ paddingTop : hasSubtitle ? '0' : '7px' ,
187
+ paddingBottom : hasSubtitle ? '0' : '7px' ,
188
+ paddingLeft : '19px' ,
189
+ minHeight : ! fullWidth ? '56px' : 'unset' ,
190
+ } ,
191
+
192
+ '& *' : {
193
+ fontSize : '1rem' ,
194
+ } ,
195
+ } ) ,
196
+ } ) }
197
+ >
78
198
{ listItemLinkContainer }
79
199
{ ! iconOnly && < ListItemText primary = { primary } secondary = { subtitle } /> }
80
- </ ListItem >
200
+ </ ListItemButton >
81
201
</ StyledLi >
82
202
) ;
83
203
}
0 commit comments