@@ -8,7 +8,7 @@ Tabs in a particular project.
8
8
*/
9
9
10
10
import type { MenuProps } from "antd" ;
11
- import { Button , Dropdown , Modal , Switch , Tooltip } from "antd" ;
11
+ import { Button , Dropdown , Modal , Tooltip } from "antd" ;
12
12
import { debounce , throttle } from "lodash" ;
13
13
import { ReactNode , useEffect , useLayoutEffect , useRef , useState } from "react" ;
14
14
@@ -101,31 +101,31 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
101
101
const vbar = getValidVBAROption ( other_settings . get ( VBAR_KEY ) ) ;
102
102
const isAnonymous = useTypedRedux ( "account" , "is_anonymous" ) ;
103
103
const parent = useRef < HTMLDivElement > ( null ) ;
104
- const tabs = useRef < HTMLDivElement > ( null ) ;
104
+ const gap = useRef < HTMLDivElement > ( null ) ;
105
105
const breakPoint = useRef < number > ( 0 ) ;
106
106
const refCondensed = useRef < boolean > ( false ) ;
107
107
const [ condensed , setCondensed ] = useState ( false ) ;
108
108
109
109
const calcCondensed = throttle (
110
110
( ) => {
111
- if ( tabs . current == null ) return ;
111
+ if ( gap . current == null ) return ;
112
112
if ( parent . current == null ) return ;
113
113
114
- const th = tabs . current . clientHeight ;
114
+ const gh = gap . current . clientHeight ;
115
115
const ph = parent . current . clientHeight ;
116
116
117
117
if ( refCondensed . current ) {
118
118
// 5px slack to avoid flickering
119
- if ( ph > breakPoint . current + 5 ) {
119
+ if ( gh > 0 && ph > breakPoint . current + 5 ) {
120
120
setCondensed ( false ) ;
121
121
refCondensed . current = false ;
122
122
}
123
123
} else {
124
- if ( ph < th ) {
124
+ if ( gh < 1 ) {
125
125
setCondensed ( true ) ;
126
126
refCondensed . current = true ;
127
127
// max? because when we start with a thin window, the ph is already smaller than th
128
- breakPoint . current = Math . max ( th , ph ) ;
128
+ breakPoint . current = ph ;
129
129
}
130
130
}
131
131
} ,
@@ -211,6 +211,24 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
211
211
if ( tab != null ) items . push ( tab ) ;
212
212
}
213
213
214
+ function renderToggleSidebar ( ) {
215
+ return (
216
+ < Tooltip title = "Hide the action bar" placement = "rightTop" >
217
+ < Button
218
+ size = "small"
219
+ type = "text"
220
+ block
221
+ onClick = { ( ) => {
222
+ track ( "action-bar" , { action : "hide" } ) ;
223
+ actions ?. toggleActionButtons ( ) ;
224
+ } }
225
+ >
226
+ < Icon name = "vertical-right-outlined" />
227
+ </ Button >
228
+ </ Tooltip >
229
+ ) ;
230
+ }
231
+
214
232
return (
215
233
< div
216
234
ref = { parent }
@@ -222,27 +240,15 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
222
240
// also, the scrollbar is intentionally only active in condensed mode, to avoid it to show up briefly.
223
241
overflowY : condensed ? "auto" : "hidden" ,
224
242
overflowX : "hidden" ,
243
+ flex : "1 1 0" ,
225
244
} }
226
245
>
227
- < div
228
- ref = { tabs }
229
- style = { { display : "flex" , flexDirection : "column" , flex : "1 1 0" } }
230
- >
231
- { items }
232
- < div style = { { flex : 1 } } > </ div > { /* moves hide switch to the bottom */ }
233
- < LayoutSelector vbar = { vbar } />
234
- < Tooltip title = "Hide the action bar" placement = "right" >
235
- < Switch
236
- style = { { margin : "10px" } }
237
- size = "small"
238
- checked
239
- onChange = { ( ) => {
240
- actions ?. toggleActionButtons ( ) ;
241
- track ( "action-bar" , { action : "hide" } ) ;
242
- } }
243
- />
244
- </ Tooltip >
245
- </ div >
246
+ { items }
247
+ { /* moves the layout selector to the bottom */ }
248
+ < div ref = { gap } style = { { flex : 1 } } > </ div > { " " }
249
+ { /* moves hide switch to the bottom */ }
250
+ < LayoutSelector vbar = { vbar } />
251
+ { renderToggleSidebar ( ) }
246
252
</ div >
247
253
) ;
248
254
}
@@ -306,7 +312,11 @@ function LayoutSelector({ vbar }) {
306
312
return (
307
313
< div style = { { textAlign : "center" } } >
308
314
< Dropdown menu = { { items } } trigger = { [ "click" ] } placement = "topLeft" >
309
- < Button icon = { < Icon name = "layout" /> } style = { { margin : "5px" } } />
315
+ < Button
316
+ icon = { < Icon name = "layout" /> }
317
+ style = { { margin : "5px" } }
318
+ type = "text"
319
+ />
310
320
</ Dropdown >
311
321
</ div >
312
322
) ;
0 commit comments