-
-
Notifications
You must be signed in to change notification settings - Fork 627
Expand file tree
/
Copy pathShell.tsx
More file actions
92 lines (78 loc) · 2.56 KB
/
Shell.tsx
File metadata and controls
92 lines (78 loc) · 2.56 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { Show, createSignal, onCleanup, onMount } from 'solid-js'
import { Header, HeaderLogo, MainPanel } from '@tanstack/devtools-ui'
import { useStyles } from '../styles/use-styles'
import { UtilList } from './UtilList'
import { DetailsPanel } from './DetailsPanel'
import type { Accessor } from 'solid-js'
export function Shell() {
const styles = useStyles()
const [leftPanelWidth, setLeftPanelWidth] = createSignal(300)
const [isDragging, setIsDragging] = createSignal(false)
const [selectedKey, setSelectedKey] = createSignal<string | null>(null)
let dragStartX = 0
let dragStartWidth = 0
const handleMouseDown = (e: MouseEvent) => {
e.preventDefault()
e.stopPropagation()
setIsDragging(true)
document.body.style.cursor = 'col-resize'
document.body.style.userSelect = 'none'
dragStartX = e.clientX
dragStartWidth = leftPanelWidth()
}
const handleMouseMove = (e: MouseEvent) => {
if (!isDragging()) return
e.preventDefault()
const deltaX = e.clientX - dragStartX
const newWidth = Math.max(150, Math.min(800, dragStartWidth + deltaX))
setLeftPanelWidth(newWidth)
}
const handleMouseUp = () => {
setIsDragging(false)
document.body.style.cursor = ''
document.body.style.userSelect = ''
}
onMount(() => {
document.addEventListener('mousemove', handleMouseMove)
document.addEventListener('mouseup', handleMouseUp)
})
onCleanup(() => {
document.removeEventListener('mousemove', handleMouseMove)
document.removeEventListener('mouseup', handleMouseUp)
})
return (
<MainPanel>
<Header>
<HeaderLogo
flavor={{ light: '#eeaf00', dark: '#eeaf00' }}
onClick={() => {
window.open(
'https://tanstack.com/form/latest/docs/overview',
'_blank',
)
}}
>
TanStack Form
</HeaderLogo>
</Header>
<div class={styles().mainContainer}>
<div
class={styles().leftPanel}
style={`--left-panel-width: ${leftPanelWidth()}px`}
>
<UtilList selectedKey={selectedKey} setSelectedKey={setSelectedKey} />
</div>
<div
class={`${styles().dragHandle} ${isDragging() ? 'dragging' : ''}`}
onMouseDown={handleMouseDown}
/>
<div class={styles().rightPanel}>
<Show when={selectedKey() != null}>
<div class={styles().panelHeader}>Details</div>
<DetailsPanel selectedKey={selectedKey as Accessor<string>} />
</Show>
</div>
</div>
</MainPanel>
)
}