-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathMainPanel.tsx
73 lines (68 loc) · 2.08 KB
/
MainPanel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import clsx from "clsx"
import { useState } from "react"
import { useDetachedWindowControls, useSettingsContext } from "../context/useRDTContext.js"
import { useAttachWindowListener } from "../hooks/useAttachListener.js"
import { useDebounce } from "../hooks/useDebounce.js"
import { useResize } from "../hooks/useResize.js"
interface MainPanelProps {
children: React.ReactNode
isOpen: boolean
isEmbedded?: boolean
className?: string
}
const useResizeDetachedPanel = () => {
const { isDetached } = useDetachedWindowControls()
const [state, setState] = useState(0)
const debounce = useDebounce(() => {
setState(state + 1)
})
useAttachWindowListener("resize", debounce, isDetached)
}
const MainPanel = ({ children, isOpen, isEmbedded = false, className }: MainPanelProps) => {
const { settings } = useSettingsContext()
const { detachedWindow } = useDetachedWindowControls()
const { height, panelLocation } = settings
const { enableResize, disableResize, isResizing } = useResize()
useResizeDetachedPanel()
return (
<div
style={
!isEmbedded
? {
zIndex: 9998,
height: detachedWindow ? window.innerHeight : height,
}
: undefined
}
className={clsx(
"duration-600 box-border flex overflow-auto bg-main text-white opacity-0 transition-all",
isOpen ? "opacity-100 drop-shadow-2xl" : "!h-0",
isResizing && "cursor-grabbing ",
!isEmbedded
? clsx(
"flex-col fixed left-0 w-screen",
panelLocation === "bottom" ? "bottom-0" : "top-0 border-b-2 border-main"
)
: "flex-row",
className
)}
>
{!isEmbedded && panelLocation === "bottom" && (
<div
onMouseDown={enableResize}
onMouseUp={disableResize}
className={clsx("absolute z-50 h-1 w-full", isResizing ? "cursor-grabbing" : "cursor-ns-resize")}
/>
)}
{children}
{!isEmbedded && panelLocation === "top" && (
<div
onMouseDown={enableResize}
onMouseUp={disableResize}
className={clsx("absolute bottom-0 z-50 h-1 w-full", isResizing ? "cursor-grabbing" : "cursor-ns-resize")}
/>
)}
</div>
)
}
export { MainPanel }