Skip to content

Commit

Permalink
feat: add drag api demo
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed May 15, 2023
1 parent 84afabb commit 7c46df1
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/react-moveable/stories/99-Tests/ReactDragAPIApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useEffect, useRef, useState } from "react";
import Moveable from "@/react-moveable";


export default function App() {
const moveableRef = useRef<Moveable>(null);
const [target, setTarget] = useState<HTMLElement | null>(null);

return (
<div className="container">
<div style={{
width: "500px",
height: "500px",
border: "1px solid black",
}} onDragEnter={e => {
const nativeEvent = e.nativeEvent;

if (!target) {
moveableRef.current!.waitToChangeTarget().then(() => {
moveableRef.current!.dragStart(nativeEvent);
});
setTarget(document.querySelector<HTMLElement>("#drag1"));
}
}}></div>
<img
id="drag1"
src="https://www.w3schools.com/html/img_w3slogo.gif"
draggable="true"
onDragOver={e => {
e.preventDefault();
}}
/>
<Moveable
ref={moveableRef}
target={target}
draggable={true}
preventDefault={false}
onDrag={e => {
e.target.style.cssText += e.cssText;
}}
/>
</div>
);
}

0 comments on commit 7c46df1

Please sign in to comment.