diff --git a/pkgs/webview-ui/app/src/components/modal/index.tsx b/pkgs/webview-ui/app/src/components/modal/index.tsx new file mode 100644 index 000000000..7add1f5a9 --- /dev/null +++ b/pkgs/webview-ui/app/src/components/modal/index.tsx @@ -0,0 +1,119 @@ +import Dialog from "corvu/dialog"; +import { createEffect, createSignal, JSX } from "solid-js"; +import { Button } from "../button"; +import Icon from "../icon"; +import cx from "classnames"; + +interface ModalProps { + open: boolean | undefined; + handleClose: () => void; + title: string; + children: JSX.Element; +} +export const Modal = (props: ModalProps) => { + const [dragging, setDragging] = createSignal(false); + const [startOffset, setStartOffset] = createSignal({ x: 0, y: 0 }); + // const [dialogStyle, setDialogStyle] = createSignal({ top: 100, left: 100 }); + let dialogRef: HTMLDivElement; + + const handleMouseDown = (e: MouseEvent) => { + setDragging(true); + const rect = dialogRef.getBoundingClientRect(); + setStartOffset({ + x: e.clientX - rect.left, + y: e.clientY - rect.top, + }); + }; + + const handleMouseMove = (e: MouseEvent) => { + if (dragging()) { + const newTop = e.clientY - startOffset().y; + const newLeft = e.clientX - startOffset().x; + + dialogRef.style.top = `${newTop}px`; + dialogRef.style.left = `${newLeft}px`; + } + }; + + const handleMouseUp = () => setDragging(false); + + createEffect(() => { + console.log("dialog open", props.open); + }); + return ( + + + + + { + dialogRef = el; + }} + onMouseMove={handleMouseMove} + onMouseUp={handleMouseUp} + onMouseDown={(e) => { + e.stopPropagation(); // Prevent backdrop drag conflict + }} + onClick={(e) => e.stopPropagation()} // Prevent backdrop click closing + > + +
+
+
+
+
+
+
+
+ {props.title} +
+
+
+
+
+
+
+
+ +
+
+
+ + {props.children} + +
+
+
+ ); +};