Files
tolaria/src/components/ResizeHandle.tsx
lucaronin 0053eb3009 feat: UI polish — typography, layout, and sidebar fixes
- font-mono-label: font-weight 500, remove letter-spacing
- NoteList: move timestamp below snippet in note items
- Sidebar: add border-r with sidebar-border color
- ResizeHandle: overlap sidebar border with -ml-1 (no visible gap)
- Sidebar items: text-muted-foreground for inactive group items
- NoteList: uniform 14px vertical padding across all note items
- NoteList header: fixed height 45px to match tab bar
2026-02-18 10:52:01 +01:00

75 lines
2.0 KiB
TypeScript

import { useCallback, useEffect, useRef } from 'react'
interface ResizeHandleProps {
onResize: (delta: number) => void
}
export function ResizeHandle({ onResize }: ResizeHandleProps) {
const isDragging = useRef(false)
const lastX = useRef(0)
const pendingDelta = useRef(0)
const rafId = useRef(0)
const handleMouseDown = useCallback(
(e: React.MouseEvent) => {
e.preventDefault()
isDragging.current = true
lastX.current = e.clientX
pendingDelta.current = 0
document.body.style.cursor = 'col-resize'
document.body.style.userSelect = 'none'
},
[],
)
useEffect(() => {
const handleMouseMove = (e: MouseEvent) => {
if (!isDragging.current) return
pendingDelta.current += e.clientX - lastX.current
lastX.current = e.clientX
if (!rafId.current) {
rafId.current = requestAnimationFrame(() => {
if (pendingDelta.current !== 0) {
onResize(pendingDelta.current)
pendingDelta.current = 0
}
rafId.current = 0
})
}
}
const handleMouseUp = () => {
if (isDragging.current) {
isDragging.current = false
document.body.style.cursor = ''
document.body.style.userSelect = ''
// Flush any pending delta
if (rafId.current) {
cancelAnimationFrame(rafId.current)
rafId.current = 0
}
if (pendingDelta.current !== 0) {
onResize(pendingDelta.current)
pendingDelta.current = 0
}
}
}
document.addEventListener('mousemove', handleMouseMove)
document.addEventListener('mouseup', handleMouseUp)
return () => {
document.removeEventListener('mousemove', handleMouseMove)
document.removeEventListener('mouseup', handleMouseUp)
if (rafId.current) cancelAnimationFrame(rafId.current)
}
}, [onResize])
return (
<div
className="-ml-1 w-1 shrink-0 cursor-col-resize bg-transparent transition-colors hover:bg-[var(--border)]"
onMouseDown={handleMouseDown}
/>
)
}