@@ -6,9 +6,9 @@ interface ComponentWithRouter extends Sidebar {
6
6
router ?: Router
7
7
}
8
8
9
- type SidebarItem = {
9
+ export type SidebarItem = {
10
10
text : string
11
- href : string
11
+ href ? : string
12
12
target : string
13
13
name : string
14
14
path : string
@@ -35,11 +35,18 @@ export class Sidebar extends Component<Props> {
35
35
:host {
36
36
display: block;
37
37
}
38
+ .selected-item {
39
+ background-color: #e2e8f0; /* Light gray background */
40
+ }
41
+ .dark .selected-item {
42
+ background-color: #4a5568; /* Darker gray for dark mode */
43
+ }
38
44
`
39
45
40
46
state = {
41
47
isOpen : false ,
42
48
active : '' ,
49
+ selectedItem : null as SidebarItem | null
43
50
}
44
51
45
52
onMouseEnter ( item : SidebarItem ) {
@@ -106,12 +113,18 @@ export class Sidebar extends Component<Props> {
106
113
107
114
@bind
108
115
select ( item : SidebarItem ) {
109
- ; ( this as ComponentWithRouter ) . router ?. push ( item . href . replace ( '#' , '' ) )
110
-
111
- this . state . active = this . props . active
116
+ if ( this . state . selectedItem === item ) {
117
+ // If the clicked item is already selected, deselect it
118
+ this . state . selectedItem = null ;
119
+ this . state . active = '' ;
120
+ } else {
121
+ // Otherwise, select the new item
122
+ this . state . selectedItem = item ;
123
+ this . state . active = item . value ;
124
+ }
112
125
this . update ( )
113
126
this . fire ( 'change' , {
114
- item,
127
+ item : this . state . selectedItem ,
115
128
} )
116
129
}
117
130
@@ -122,23 +135,27 @@ export class Sidebar extends Component<Props> {
122
135
class = { classNames (
123
136
'py-1 h-9 indent-10 rounded hover:bg-accent flex items-center text-sm text-zinc-500 dark:text-zinc-200 cursor-pointer' ,
124
137
{
125
- 'bg-accent ' : this . state . active === child . value ,
138
+ 'selected-item ' : this . state . selectedItem === child ,
126
139
} ,
127
140
) }
128
141
>
129
- < a href = "javascript:void()" class = "flex items-center space-x-2 whitespace-nowrap" >
130
- < span > { child . text } </ span >
131
- </ a >
142
+ < span > { child . text } </ span >
132
143
</ li >
133
144
)
134
145
}
135
146
136
147
renderToolTipChild ( child : SidebarItem ) {
137
148
return (
138
- < li class = "py-1 h-9 px-3 rounded hover:bg-accent flex items-center text-sm text-zinc-500 dark:text-zinc-200" >
139
- < a href = { child . href } class = "flex items-center space-x-2 whitespace-nowrap" >
140
- < span > { child . text } </ span >
141
- </ a >
149
+ < li
150
+ onClick = { ( ) => this . select ( child ) }
151
+ class = { classNames (
152
+ 'py-1 h-9 px-3 rounded hover:bg-accent flex items-center text-sm text-zinc-500 dark:text-zinc-200 cursor-pointer' ,
153
+ {
154
+ 'selected-item' : this . state . selectedItem === child ,
155
+ } ,
156
+ ) }
157
+ >
158
+ < span > { child . text } </ span >
142
159
</ li >
143
160
)
144
161
}
@@ -148,46 +165,29 @@ export class Sidebar extends Component<Props> {
148
165
< div class = "h-screen flex" >
149
166
< div
150
167
class = { classNames ( 'bg-background text-foreground transition-all p-2 flex flex-col justify-between' , {
151
- 'w-60' : this . state . isOpen ,
152
- 'w-16' : ! this . state . isOpen ,
168
+ 'w-30' : this . state . isOpen
153
169
} ) }
154
170
>
155
171
< div >
156
- < div class = { classNames ( 'flex items-center h-[50px] space-x-2 justify-center' ) } >
172
+ { /* <div class={classNames('flex items-center h-[50px] space-x-2 justify-center')}>
157
173
<i class="h-8 w-8">
158
174
<img src="https://omi.cdn-go.cn/admin/latest/home/omi.svg"></img>
159
175
</i>
160
- < h1
161
- class = { classNames ( 'text-2xl font-semibold whitespace-nowrap' , {
162
- block : this . state . isOpen ,
163
- hidden : ! this . state . isOpen ,
164
- } ) }
165
- >
166
- OMI Admin
167
- </ h1 >
168
- </ div >
169
- < div
170
- class = { classNames ( 'mb-2' , {
171
- block : this . state . isOpen ,
172
- hidden : ! this . state . isOpen ,
173
- } ) }
174
- >
175
- < input type = "text" placeholder = "Search" class = "px-3 w-full p-1 border rounded" />
176
- </ div >
176
+ </div> */ }
177
177
< nav class = "h-[calc(100vh-300px)] overflow-auto" >
178
178
< ul >
179
179
{ this . props . items . map ( ( item : SidebarItem ) => {
180
180
const hasChildren = ! ! ( item . children && item . children . length )
181
181
return (
182
182
< li >
183
- < a
184
- href = { hasChildren ? 'javascript:' : item . href }
185
- onClick = { ( ) => this . onItemClick ( item ) }
183
+ < div
184
+ onClick = { ( ) => hasChildren ? this . onItemClick ( item ) : this . select ( item ) }
186
185
onMouseEnter = { ( ) => this . onMouseEnter ( item ) }
187
186
onMouseLeave = { ( ) => this . onMouseLeave ( item ) }
188
- class = { classNames ( 'trigger flex items-center hover:bg-accent h-9 rounded px-2' , {
187
+ class = { classNames ( 'trigger flex items-center hover:bg-accent h-9 rounded px-2 cursor-pointer ' , {
189
188
'justify-between' : this . state . isOpen ,
190
189
'justify-center' : ! this . state . isOpen ,
190
+ 'selected-item' : this . state . selectedItem === item ,
191
191
} ) }
192
192
>
193
193
< div class = "flex items-center space-x-2 text-zinc-600 dark:text-zinc-200" >
@@ -216,7 +216,7 @@ export class Sidebar extends Component<Props> {
216
216
) }
217
217
> </ i >
218
218
) }
219
- </ a >
219
+ </ div >
220
220
{ hasChildren && this . state . isOpen && (
221
221
< ul
222
222
class = "transition-all overflow-hidden"
@@ -235,7 +235,7 @@ export class Sidebar extends Component<Props> {
235
235
</ ul >
236
236
</ nav >
237
237
</ div >
238
- { this . state . isOpen && (
238
+ { /* { this.state.isOpen && (
239
239
<div class="bg-primary text-white rounded p-4 w-56">
240
240
<h2 class="font-semibold mb-2">重点公告位</h2>
241
241
<p class="text-sm mb-4">
@@ -245,7 +245,7 @@ export class Sidebar extends Component<Props> {
245
245
知道了
246
246
</button>
247
247
</div>
248
- ) }
248
+ )} */ }
249
249
</ div >
250
250
</ div >
251
251
)
0 commit comments