@@ -7,12 +7,13 @@ import {
7
7
LanguageInterface ,
8
8
languages ,
9
9
Sidebar ,
10
- Spacer ,
11
- ThemeDialog
10
+ ThemeDialog ,
11
+ useSidebar
12
12
} from '@/components'
13
13
import { ContentStyleType , useRouterContext , useTheme } from '@/context'
14
14
import { TypesUser } from '@/types'
15
15
import { TranslationStore } from '@/views'
16
+ import { cn } from '@utils/cn'
16
17
17
18
import { SidebarItem } from './sidebar-item'
18
19
import { SidebarSearchLegacy } from './sidebar-search-legacy'
@@ -35,6 +36,7 @@ interface SidebarProps {
35
36
handleRemoveRecentMenuItem : ( item : NavbarItemType ) => void
36
37
useTranslationStore : ( ) => TranslationStore
37
38
showNewSearch ?: boolean
39
+ hasToggle ?: boolean
38
40
}
39
41
40
42
export const AppSidebar = ( {
@@ -48,11 +50,13 @@ export const AppSidebar = ({
48
50
handleSettingsMenu,
49
51
handleCustomNav,
50
52
handleLogOut,
53
+ hasToggle = true ,
51
54
showNewSearch
52
55
} : SidebarProps ) => {
53
56
const { t, i18n, changeLanguage } = useTranslationStore ( )
54
57
const { theme, setTheme, setInset, isInset } = useTheme ( )
55
58
const { Link, navigate } = useRouterContext ( )
59
+ const { collapsed, toggleSidebar } = useSidebar ( )
56
60
57
61
const [ openThemeDialog , setOpenThemeDialog ] = useState ( false )
58
62
const [ openLanguageDialog , setOpenLanguageDialog ] = useState ( false )
@@ -72,6 +76,19 @@ export const AppSidebar = ({
72
76
73
77
const onInsetChange = ( style : ContentStyleType ) => setInset ( style === ContentStyleType . Inset )
74
78
79
+ const HarnessLogo = ( { className } : { className ?: string } ) => (
80
+ < Link to = "/" className = { cn ( 'flex items-center gap-0.5 overflow-hidden' , className ) } >
81
+ < Icon name = "harness" size = { 18 } className = "text-sidebar-foreground-accent" />
82
+ < div
83
+ className = { cn ( 'overflow-hidden max-w-20 mb-px opacity-100 transition-[max-width,opacity] ease-linear' , {
84
+ 'max-w-0 opacity-0' : collapsed
85
+ } ) }
86
+ >
87
+ < Icon name = "harness-logo-text" width = { 65 } height = { 15 } className = "text-sidebar-foreground-1" />
88
+ </ div >
89
+ </ Link >
90
+ )
91
+
75
92
return (
76
93
< >
77
94
< Sidebar . Root className = "z-20" >
@@ -81,24 +98,11 @@ export const AppSidebar = ({
81
98
< SidebarSearch
82
99
className = "pb-3 pt-1.5"
83
100
t = { t }
84
- logo = {
85
- < Link to = "/" className = "flex h-[58px] items-center justify-start gap-0.5 pl-1" >
86
- < Icon name = "harness" size = { 18 } className = "text-sidebar-foreground-accent" />
87
- < Icon name = "harness-logo-text" width = { 65 } height = { 15 } className = "text-sidebar-foreground-1 mb-px" />
88
- </ Link >
89
- }
101
+ logo = { < HarnessLogo className = "h-[58px] justify-start pl-1" /> }
90
102
/>
91
103
</ SearchProvider >
92
104
) : (
93
- < SidebarSearchLegacy
94
- t = { t }
95
- logo = {
96
- < Link className = "flex items-center gap-0.5" to = "/" >
97
- < Icon name = "harness" size = { 18 } className = "text-sidebar-foreground-accent" />
98
- < Icon name = "harness-logo-text" width = { 65 } height = { 15 } className = "text-sidebar-foreground-1 mb-px" />
99
- </ Link >
100
- }
101
- />
105
+ < SidebarSearchLegacy t = { t } logo = { < HarnessLogo /> } />
102
106
) }
103
107
</ Sidebar . Header >
104
108
< Sidebar . Content >
@@ -131,7 +135,6 @@ export const AppSidebar = ({
131
135
{ ! ! recentMenuItems . length && (
132
136
< Sidebar . Group title = { t ( 'component:navbar.recent' , 'Recent' ) } className = "border-t pt-2.5" >
133
137
< Sidebar . GroupLabel > { t ( 'component:navbar.recent' , 'Recent' ) } </ Sidebar . GroupLabel >
134
- < Spacer size = { 2 } />
135
138
< Sidebar . GroupContent >
136
139
< Sidebar . Menu >
137
140
{ recentMenuItems . map ( item => (
@@ -155,26 +158,53 @@ export const AppSidebar = ({
155
158
< Sidebar . Menu >
156
159
{ ! ! currentUser ?. admin && (
157
160
< Sidebar . MenuItem >
158
- < Sidebar . MenuButton asChild onClick = { ( ) => navigate ( '/admin/default-settings' ) } >
159
- < Sidebar . MenuItemText
160
- text = { t ( 'component:navbar.user-management' , 'User Management' ) }
161
- icon = { < Icon name = "account" size = { 14 } /> }
162
- />
163
- </ Sidebar . MenuButton >
161
+ < button className = "w-full" onClick = { ( ) => navigate ( '/admin/default-settings' ) } >
162
+ < Sidebar . MenuButton asChild >
163
+ < Sidebar . MenuItemText
164
+ text = { t ( 'component:navbar.user-management' , 'User Management' ) }
165
+ icon = { < Icon name = "account" size = { 14 } /> }
166
+ />
167
+ </ Sidebar . MenuButton >
168
+ </ button >
164
169
</ Sidebar . MenuItem >
165
170
) }
166
171
< Sidebar . MenuItem >
167
- < Sidebar . MenuButton asChild onClick = { handleSettingsMenu } >
168
- < Sidebar . MenuItemText
169
- text = { t ( 'component:navbar.settings' , 'Settings' ) }
170
- icon = { < Icon name = "settings-1" size = { 14 } /> }
171
- />
172
- </ Sidebar . MenuButton >
172
+ < button className = "w-full" onClick = { handleSettingsMenu } >
173
+ < Sidebar . MenuButton asChild >
174
+ < Sidebar . MenuItemText
175
+ text = { t ( 'component:navbar.settings' , 'Settings' ) }
176
+ icon = { < Icon name = "settings-1" size = { 14 } /> }
177
+ />
178
+ </ Sidebar . MenuButton >
179
+ </ button >
173
180
</ Sidebar . MenuItem >
174
181
</ Sidebar . Menu >
175
182
</ Sidebar . GroupContent >
176
183
</ Sidebar . Group >
177
184
</ Sidebar . Content >
185
+
186
+ { hasToggle && (
187
+ < Sidebar . Group >
188
+ < Sidebar . Menu >
189
+ < Sidebar . MenuItem >
190
+ < button className = "w-full" onClick = { toggleSidebar } >
191
+ < Sidebar . MenuButton asChild >
192
+ < Sidebar . MenuItemText
193
+ aria-label = {
194
+ collapsed
195
+ ? t ( 'component:navbar.sidebarToggle.expand' , 'Expand' )
196
+ : t ( 'component:navbar.sidebarToggle.collapse' , 'Collapse' )
197
+ }
198
+ text = { t ( 'component:navbar.sidebarToggle.collapse' , 'Collapse' ) }
199
+ icon = { < Icon name = { collapsed ? 'sidebar-right' : 'sidebar-left' } size = { 14 } /> }
200
+ />
201
+ </ Sidebar . MenuButton >
202
+ </ button >
203
+ </ Sidebar . MenuItem >
204
+ </ Sidebar . Menu >
205
+ </ Sidebar . Group >
206
+ ) }
207
+
178
208
< Sidebar . Footer className = "border-sidebar-border-1 border-t" >
179
209
< User
180
210
user = { currentUser }
0 commit comments