import React, { useState } from "react"; import { useStore } from "@/_models/RootStore"; type Props = { targetRef: React.RefObject; }; export const Draggable: React.FC = ({ targetRef }) => { const { historyStore } = useStore(); const [initialPos, setInitialPos] = useState(null); const [initialSize, setInitialSize] = useState(null); const [width, setWidth] = useState(0); const initial = (e: React.DragEvent) => { setInitialPos(e.clientX); setInitialSize(targetRef.current?.offsetWidth ?? 0); }; const resize = (e: React.DragEvent) => { if (initialPos !== null && initialSize !== null) { setWidth(initialSize - (e.clientX - initialPos)); targetRef.current!.style.width = `${width}px`; } if (width <= 270) { historyStore.closeModelDetail(); } }; return (
); };