@@ -8,7 +8,7 @@ Tabs in a particular project.
88*/
99
1010import type { MenuProps } from "antd" ;
11- import { Button , Dropdown , Modal , Switch , Tooltip } from "antd" ;
11+ import { Button , Dropdown , Modal , Tooltip } from "antd" ;
1212import { debounce , throttle } from "lodash" ;
1313import { ReactNode , useEffect , useLayoutEffect , useRef , useState } from "react" ;
1414
@@ -101,31 +101,31 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
101101 const vbar = getValidVBAROption ( other_settings . get ( VBAR_KEY ) ) ;
102102 const isAnonymous = useTypedRedux ( "account" , "is_anonymous" ) ;
103103 const parent = useRef < HTMLDivElement > ( null ) ;
104- const tabs = useRef < HTMLDivElement > ( null ) ;
104+ const gap = useRef < HTMLDivElement > ( null ) ;
105105 const breakPoint = useRef < number > ( 0 ) ;
106106 const refCondensed = useRef < boolean > ( false ) ;
107107 const [ condensed , setCondensed ] = useState ( false ) ;
108108
109109 const calcCondensed = throttle (
110110 ( ) => {
111- if ( tabs . current == null ) return ;
111+ if ( gap . current == null ) return ;
112112 if ( parent . current == null ) return ;
113113
114- const th = tabs . current . clientHeight ;
114+ const gh = gap . current . clientHeight ;
115115 const ph = parent . current . clientHeight ;
116116
117117 if ( refCondensed . current ) {
118118 // 5px slack to avoid flickering
119- if ( ph > breakPoint . current + 5 ) {
119+ if ( gh > 0 && ph > breakPoint . current + 5 ) {
120120 setCondensed ( false ) ;
121121 refCondensed . current = false ;
122122 }
123123 } else {
124- if ( ph < th ) {
124+ if ( gh < 1 ) {
125125 setCondensed ( true ) ;
126126 refCondensed . current = true ;
127127 // 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 ;
129129 }
130130 }
131131 } ,
@@ -211,6 +211,24 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
211211 if ( tab != null ) items . push ( tab ) ;
212212 }
213213
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+
214232 return (
215233 < div
216234 ref = { parent }
@@ -222,27 +240,15 @@ export function VerticalFixedTabs(props: Readonly<FVTProps>) {
222240 // also, the scrollbar is intentionally only active in condensed mode, to avoid it to show up briefly.
223241 overflowY : condensed ? "auto" : "hidden" ,
224242 overflowX : "hidden" ,
243+ flex : "1 1 0" ,
225244 } }
226245 >
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 ( ) }
246252 </ div >
247253 ) ;
248254}
@@ -306,7 +312,11 @@ function LayoutSelector({ vbar }) {
306312 return (
307313 < div style = { { textAlign : "center" } } >
308314 < 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+ />
310320 </ Dropdown >
311321 </ div >
312322 ) ;
0 commit comments