A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
/* Copyright 2026 Marimo. All rights reserved. */
import { GripHorizontalIcon } from "lucide-react";
import type { Popover as PopoverPrimitive } from "radix-ui";
import { useRef, useState } from "react";
import { Popover, PopoverContent, PopoverTrigger } from "./popover";
interface DraggablePopoverProps extends PopoverPrimitive.PopoverProps {
children: React.ReactNode;
className?: string;
}
export const DraggablePopover = ({
children,
className,
...props
}: DraggablePopoverProps) => {
const [position, setPosition] = useState({ x: 0, y: 0 });
const dragStartPos = useRef({ x: 0, y: 0 });
const [isDragging, setIsDragging] = useState(false);
const handleMouseDown = (e: React.MouseEvent) => {
dragStartPos.current = {
x: e.clientX - position.x,
y: e.clientY - position.y,
};
setIsDragging(true);
document.addEventListener("mousemove", handleMouseMove);
document.addEventListener("mouseup", handleMouseUp);
};
const handleMouseMove = (e: MouseEvent) => {
setPosition({
x: e.clientX - dragStartPos.current.x,
y: e.clientY - dragStartPos.current.y,
});
};
const handleMouseUp = () => {
setIsDragging(false);
document.removeEventListener("mousemove", handleMouseMove);
document.removeEventListener("mouseup", handleMouseUp);
};
return (
<Popover {...props}>
<PopoverTrigger />
<PopoverContent
className={className}
style={{
position: "fixed",
left: position.x,
top: position.y,
}}
>
<button
type="button"
aria-label="Move popup with arrow keys"
onMouseDown={handleMouseDown}
onKeyDown={(e) => {
const directions: Record<
string,
{ x: number; y: number } | undefined
> = {
ArrowLeft: { x: -10, y: 0 },
ArrowRight: { x: 10, y: 0 },
ArrowUp: { x: 0, y: -10 },
ArrowDown: { x: 0, y: 10 },
};
const offset = directions[e.key];
if (offset) {
e.preventDefault();
e.stopPropagation();
setPosition((previous) => ({
x: previous.x + offset.x,
y: previous.y + offset.y,
}));
}
}}
className={`flex items-center justify-center absolute top-0 left-1/2 -translate-x-1/2 ${
isDragging ? "cursor-grabbing" : "cursor-grab"
}`}
>
<GripHorizontalIcon className="h-5 w-5 mt-1 text-muted-foreground/40" />
</button>
{children}
</PopoverContent>
</Popover>
);
};