feat: add eraser tool
This commit is contained in:
parent
6f5fdfb799
commit
a5bc500553
2 changed files with 15 additions and 8 deletions
21
src/App.tsx
21
src/App.tsx
|
|
@ -1,6 +1,6 @@
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { Layer, Stage } from "react-konva";
|
import { Layer, Stage } from "react-konva";
|
||||||
import { Hand, Pencil } from "lucide-react";
|
import { Eraser, Hand, Pencil } from "lucide-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Menubar,
|
Menubar,
|
||||||
|
|
@ -92,15 +92,15 @@ function App() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClick = (e) => {
|
const onClick = (e) => {
|
||||||
|
const blockX = Math.floor(mousePosition.x / 16);
|
||||||
|
const blockY = Math.floor(mousePosition.y / 16);
|
||||||
|
const updatedBlocks = blocks.filter((b) => !(b.x === blockX && b.y === blockY));
|
||||||
|
|
||||||
switch (tool) {
|
switch (tool) {
|
||||||
case "hand":
|
case "hand":
|
||||||
setCssCursor("grabbing");
|
setCssCursor("grabbing");
|
||||||
break;
|
break;
|
||||||
case "pencil": {
|
case "pencil": {
|
||||||
const blockX = Math.floor(mousePosition.x / 16);
|
|
||||||
const blockY = Math.floor(mousePosition.y / 16);
|
|
||||||
const updatedBlocks = blocks.filter((b) => !(b.x === blockX && b.y === blockY));
|
|
||||||
|
|
||||||
setBlocks([
|
setBlocks([
|
||||||
...updatedBlocks,
|
...updatedBlocks,
|
||||||
{
|
{
|
||||||
|
|
@ -109,6 +109,11 @@ function App() {
|
||||||
y: blockY,
|
y: blockY,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "eraser": {
|
||||||
|
setBlocks(updatedBlocks);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -158,10 +163,9 @@ function App() {
|
||||||
|
|
||||||
<ToggleGroup
|
<ToggleGroup
|
||||||
type="single"
|
type="single"
|
||||||
size={"sm"}
|
|
||||||
value={tool}
|
value={tool}
|
||||||
onValueChange={onToolChange}
|
onValueChange={onToolChange}
|
||||||
className="flex flex-col gap-0.5 justify-start py-0.5 border-r border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950"
|
className="flex flex-col justify-start py-1 border-r border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950"
|
||||||
>
|
>
|
||||||
<ToggleGroupItem value="hand">
|
<ToggleGroupItem value="hand">
|
||||||
<Hand />
|
<Hand />
|
||||||
|
|
@ -169,6 +173,9 @@ function App() {
|
||||||
<ToggleGroupItem value="pencil">
|
<ToggleGroupItem value="pencil">
|
||||||
<Pencil />
|
<Pencil />
|
||||||
</ToggleGroupItem>
|
</ToggleGroupItem>
|
||||||
|
<ToggleGroupItem value="eraser">
|
||||||
|
<Eraser />
|
||||||
|
</ToggleGroupItem>
|
||||||
</ToggleGroup>
|
</ToggleGroup>
|
||||||
|
|
||||||
<div ref={stageContainerRef} className="relative w-full h-full">
|
<div ref={stageContainerRef} className="relative w-full h-full">
|
||||||
|
|
|
||||||
2
src/types.d.ts
vendored
2
src/types.d.ts
vendored
|
|
@ -7,4 +7,4 @@ interface Block extends Position {
|
||||||
name: string;
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type Tool = "hand" | "pencil";
|
type Tool = "hand" | "pencil" | "eraser";
|
||||||
Loading…
Reference in a new issue