Skip to content

Commit

Permalink
WIP. xarrows. add demo 2
Browse files Browse the repository at this point in the history
  • Loading branch information
maxzz committed Feb 3, 2024
1 parent b61493c commit 5ee6f5f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"react": "^18.2.0",
"react-day-picker": "^8.10.0",
"react-dom": "^18.2.0",
"react-draggable": "^4.4.6",
"react-hook-form": "^7.49.2",
"react-hot-toast": "^2.4.1",
"react-resizable-panels": "^1.0.7",
Expand Down
20 changes: 20 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 31 additions & 3 deletions src/components/2-main/2-demo/73-demo-xarrow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useRef } from "react";
import Xarrow from "react-xarrows";
import { HTMLAttributes, useRef } from "react";
import Xarrow, { Xwrapper, useXarrow } from "react-xarrows";
import Draggable from 'react-draggable';

export function XArrowsDemo() {
export function XArrowsDemo1() {
const box1Ref = useRef(null);
return (
<div className="relative">
Expand All @@ -20,3 +21,30 @@ export function XArrowsDemo() {
</div>
);
}



const boxStyle = { border: 'grey solid 2px', borderRadius: '10px', padding: '5px' };

const DraggableBox = ({ id }: HTMLAttributes<HTMLDivElement>) => {
const updateXarrow = useXarrow();
return (
<Draggable onDrag={updateXarrow} onStop={updateXarrow}>
<div id={id} style={boxStyle}>
{id}
</div>
</Draggable>
);
};

export function XArrowsDemo() {
return (
<div>
<Xwrapper>
<DraggableBox id={'elem1'} />
<DraggableBox id={'elem2'} />
<Xarrow start={'elem1'} end="elem2" />
</Xwrapper>
</div >
);
}

0 comments on commit 5ee6f5f

Please sign in to comment.