react-sketch
v1.2.0
Published
React component for drawing on an HTML canvas with pencil, line, arrow, rectangle and circle tools, built on fabric.js, with undo/redo, JSON import/export and TypeScript types
Maintainers
Readme
react-sketch
A sketch field component for React applications, built on fabric.js. Pencil, line, arrow, rectangle, circle, highlighter, pan and select tools, images and text, undo and redo, JSON and image export. Includes TypeScript declarations.
Installation
yarn add react-sketchor
npm install react-sketchreact (^17.0.0 || ^18.0.0 || ^19.0.0) is a peer dependency: install it in your application.
fabric is installed with react-sketch.
Usage
import { useRef } from "react";
import { SketchField, Tools } from "react-sketch";
export const Drawing = () => {
const sketch = useRef<SketchField>(null);
return (
<>
<SketchField
ref={sketch}
width={1024}
height={768}
tool={Tools.Pencil}
lineColor="black"
lineWidth={3}
/>
<button onClick={() => sketch.current?.undo()}>Undo</button>
</>
);
};Exports: SketchField (the component), Tools (Select, Pencil, Line, Arrow, Rectangle,
RectangleLabel, Polygon, Circle, Pan, DefaultTool, Highlighter, Eraser, BucketFill, LaserPointer), Types (namespace with the types and
the Tool enumeration) and a default export, which is the component with SketchField and Tools
attached (as in 0.5.x).
Documentation
The properties, the methods, the tools and the usage with a saved or controlled drawing are documented in the README of the repository. Release notes are in the changelog. Report problems at https://github.com/tbolis/react-sketch/issues.
License
MIT
