Skip to content

Commit

Permalink
add arrow
Browse files Browse the repository at this point in the history
  • Loading branch information
kolibril13 committed Mar 13, 2024
1 parent acb9455 commit b09b958
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ import "tldraw/tldraw.css";

export default function App() {
const handleMount = (editor) => {
const id = createShapeId("hello");
const rectangleId1 = createShapeId("rectangle1"); // Blue rectangle
const rectangleId2 = createShapeId("rectangle2"); // Yellow rectangle
const arrowId = createShapeId("arrow"); // arrow starting from blue rectangle and ending at yellow rectangle

editor.createShapes([
{
id,
id: rectangleId1,
type: "geo",
x: 350,
y: 300,
props: {
geo: "rectangle",
w: 150,
h: 75,
dash: "draw",
color: "blue",
size: "m",
},
},
{
id: rectangleId2,
type: "geo",
x: 500,
y: 500,
Expand All @@ -20,6 +37,31 @@ export default function App() {
},
},
]);

editor.createShapes([
{
id: arrowId,
type: "arrow",
props: {
start: {
// Bind to the center of rectangle1
type: "binding",
boundShapeId: rectangleId1,
normalizedAnchor: { x: 0.5, y: 0.5 },
isExact: false,
isPrecise: true,
},
end: {
// Bind to the center of rectangle2
type: "binding",
boundShapeId: rectangleId2,
normalizedAnchor: { x: 0.5, y: 0.5 },
isExact: false,
isPrecise: true,
},
},
},
]);
};

return (
Expand Down

0 comments on commit b09b958

Please sign in to comment.