FloatingWindow
Draggable floating area
Source
LLM docs
Docs
Package
Usage
FloatingWindow creates a draggable element with a fixed position:
Constrain to viewport
Use the constrainToViewport prop to restrict element movement to the viewport boundaries.
If you do not set the constrainToViewport prop, the element can be dragged outside the viewport:
Constrain offset
Use the constrainOffset prop to set the offset from the viewport edges when constraining the element:
Drag handle selector
The dragHandleSelector prop allows specifying a selector of an element (or a group of elements) that should be used to drag the floating window.
If not specified, the entire root element is used as a drag target.
The excludeDragHandleSelector prop excludes elements within dragHandleSelector from the drag event.
In the following example, the close button is excluded from the drag event:
Enabled prop
Use the enabled option to enable or disable dragging:
Set position
Call the setPosition function to set the position of the element programmatically.
This function accepts an object with top, left, right and bottom properties,
from which you should only specify two (for example, top and left, bottom and right).
Lock axis
Use the axis option to restrict movement to the specified axis:
use-floating-window hook
If you prefer the hook API, you can use the useFloatingWindow hook.
It supports most of the FloatingWindow features: