diff --git a/.gitignore b/.gitignore index 16d2e37..04d92d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules build .vscode +*.tgz diff --git a/package.json b/package.json index ee8e7b3..62a882d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-drawarea", - "version": "1.0.7", + "version": "1.0.8", "description": "React components to draw with mouse or touch events", "author": { "name": "Borja González", diff --git a/src/DrawArea.tsx b/src/DrawArea.tsx index a96475a..cccd7b7 100644 --- a/src/DrawArea.tsx +++ b/src/DrawArea.tsx @@ -24,25 +24,22 @@ const DrawArea: FC = ({ children, }) => { const [lines, setLines] = useState([]) - const [currentLine, setCurrentLine] = useState([]) + const [newLine, setNewLine] = useState([]) + const allLines = newLine.length === 0 ? lines : [...lines, newLine] const reset = () => setLines([]) - const undo = () => setLines(lines.slice(0, -1)) - const finishLine = () => { - if (currentLine.length > 1) setLines([...lines, currentLine]) - setCurrentLine([]) + if (newLine.length > 1) setLines(allLines) + setNewLine([]) } - - const addPoint = (newPoint: Point) => - setCurrentLine([...currentLine, newPoint]) + const addPoint = (newPoint: Point) => setNewLine([...newLine, newPoint]) const content = hidden ? null : (
- + {disabled || }
) @@ -51,8 +48,8 @@ const DrawArea: FC = ({ return ( 0, + lines: allLines, + isDrawing: newLine.length > 0, reset, undo, }}>