A hook for making the chat window draggable within the viewport.Documentation Index
Fetch the complete documentation index at: https://anvil.servicetitan.com/llms.txt
Use this file to discover all available pages before exploring further.
Usage
Options
| Option | Type | Default | Description |
|---|---|---|---|
| initialX | number | window.innerWidth - 390 | Initial horizontal position |
| initialY | number | 64 | Initial vertical position |
| minVisibleHorizontal | number | 390 | Minimum pixels visible horizontally when near edge |
| minVisibleVertical | number | 56 | Minimum pixels visible vertically when near edge |
| width | number | 390 | Width of the draggable element |
Returns
| Property | Type | Description |
|---|---|---|
| position | { x: number; y: number } | Current position coordinates |
| isDragging | boolean | Whether the element is currently being dragged |
| handleMouseDown | (e: MouseEvent) => void | Handler to attach to the drag trigger element |
| resetPosition | () => void | Resets position to calculated initial position |
Behavior
- Viewport Constraints: Position is constrained to keep the minimum visible pixels within the viewport
- Resize Handling: Automatically adjusts position when window is resized
- Text Selection: Prevents text selection while dragging
- Mouse Events: Attaches global mouse events during drag for smooth tracking