@@ -9,11 +9,9 @@ import { useRootDirPath } from '@/hooks/use-root-dir-path'
9
9
import { useAllBVData } from '@/queries/useAllBVData'
10
10
import { cls } from '@/utils/cls'
11
11
import { Avatar } from 'antd'
12
- import { Suspense , useState } from 'react'
12
+ import { Suspense , useCallback , useRef , useState } from 'react'
13
13
import { NavLink , Outlet , useParams } from 'react-router-dom'
14
14
15
- import { Panel , PanelGroup , PanelResizeHandle } from 'react-resizable-panels'
16
-
17
15
export default function Space ( ) {
18
16
const rootDirPath = useRootDirPath ( )
19
17
const { data : allData } = useAllBVData ( rootDirPath )
@@ -22,41 +20,68 @@ export default function Space() {
22
20
const isAll = ! mid
23
21
24
22
// UI
25
- const [ isDragging , setIsDragging ] = useState ( false )
23
+ const [ leftWidth , setLeftWidth ] = useState ( 128 )
24
+ const handleRef = useRef < HTMLElement > ( null )
25
+
26
+ const handleMouseDown = useCallback (
27
+ ( e : React . MouseEvent ) => {
28
+ e . preventDefault ( )
29
+ const startX = e . clientX
30
+ const startWidth = leftWidth
31
+
32
+ const onMouseMove = ( e : MouseEvent ) => {
33
+ const dx = e . clientX - startX
34
+ const newWidth = startWidth + dx
35
+ const minWidth = 100
36
+ const maxWidth = 400
37
+ if ( newWidth >= minWidth && newWidth <= maxWidth ) {
38
+ setLeftWidth ( newWidth )
39
+ }
40
+ }
41
+
42
+ const onMouseUp = ( ) => {
43
+ document . removeEventListener ( 'mousemove' , onMouseMove )
44
+ document . removeEventListener ( 'mouseup' , onMouseUp )
45
+ }
46
+
47
+ document . addEventListener ( 'mousemove' , onMouseMove )
48
+ document . addEventListener ( 'mouseup' , onMouseUp )
49
+ } ,
50
+ [ leftWidth ]
51
+ )
26
52
27
53
return (
28
54
< >
29
- < PanelGroup direction = 'horizontal' className = 'flex h-full flex-1' >
30
- < Panel id = 'sidebar' defaultSize = { 15 } minSize = { 10 } maxSize = { 30 } order = { 1 } >
31
- < aside className = 'h-full overflow-auto' >
32
- < NavLink
33
- className = { cls (
34
- 'm-2 flex items-center space-x-2 rounded-md p-2 transition-all' ,
35
- isAll ? 'bg-slate-100 text-primary' : '!text-gray-500 hover:!bg-slate-50'
36
- ) }
37
- to = ''
38
- >
39
- < Avatar className = 'h-8 w-8 flex-shrink-0' > all</ Avatar >
40
- < span className = 'truncate text-sm' > 全部UP主</ span >
41
- </ NavLink >
42
-
43
- { allData ?. ups . map ( ( v ) => < OwnerListItem key = { v . mid } mid = { v . mid } path = { v . path } /> ) }
44
- </ aside >
45
- </ Panel >
46
-
47
- < PanelResizeHandle
48
- onDragging = { setIsDragging }
49
- className = { cls ( 'w-[1px] bg-gray-200 transition-all' , isDragging ? 'cursor-move bg-primary' : '' ) }
50
- />
51
-
52
- < Panel minSize = { 25 } order = { 2 } >
53
- < main className = 'h-full overflow-auto' >
54
- < Suspense fallback = { null } >
55
- < Outlet />
56
- </ Suspense >
57
- </ main >
58
- </ Panel >
59
- </ PanelGroup >
55
+ < section className = 'flex h-full flex-1' >
56
+ < aside className = 'flex-shrink-0 overflow-auto' style = { { width : leftWidth } } >
57
+ < NavLink
58
+ className = { cls (
59
+ 'm-2 flex items-center space-x-2 rounded-md p-2 transition-all' ,
60
+ isAll ? 'bg-slate-100 text-primary' : '!text-gray-500 hover:!bg-slate-50'
61
+ ) }
62
+ to = ''
63
+ >
64
+ < Avatar className = 'h-8 w-8 flex-shrink-0' > all</ Avatar >
65
+ < span className = 'truncate text-sm' > 全部UP主</ span >
66
+ </ NavLink >
67
+
68
+ { allData ?. ups . map ( ( v ) => < OwnerListItem key = { v . mid } mid = { v . mid } path = { v . path } /> ) }
69
+ </ aside >
70
+
71
+ < div className = 'relative w-[1px] bg-gray-200 transition-all hover:bg-primary' >
72
+ < i
73
+ ref = { handleRef }
74
+ onMouseDown = { handleMouseDown }
75
+ className = 'absolute bottom-0 left-0 top-0 w-3 -translate-x-1/2 transform cursor-ew-resize'
76
+ > </ i >
77
+ </ div >
78
+
79
+ < main className = 'flex-1 overflow-auto' >
80
+ < Suspense fallback = { null } >
81
+ < Outlet />
82
+ </ Suspense >
83
+ </ main >
84
+ </ section >
60
85
</ >
61
86
)
62
87
}
0 commit comments