React Canvas Draw
A simple yet powerful canvas-drawing component for React (Demo)
Install via NPM:
npm install react-canvas-draw --save
yarn add react-canvas-draw
For more examples, like saving and loading a drawing ==> look into the
These are the defaultProps of CanvasDraw. You can pass along any of these props to customize the CanvasDraw component. Examples of how to use the props are also shown in the
static defaultProps =onChange: nullloadTimeOffset: 5lazyRadius: 30brushRadius: 12brushColor: "#444"catenaryColor: "#0a0302"gridColor: "rgba(150,150,150,0.17)"hideGrid: falsecanvasWidth: 400canvasHeight: 400disabled: falseimgSrc: ""saveData: nullimmediateLoading: falsehideInterface: false;
Useful functions that you can call, e.g. when having a reference to this component:
getSaveData()returns the drawing's save-data as a stringified object
loadSaveData(saveData: String, immediate: Boolean)loads a previously saved drawing using the saveData string, as well as an optional boolean flag to load it immediately, instead of live-drawing it.
clear()clears the canvas completely
undo()removes the latest change to the drawing. This includes everything drawn since the last MouseDown event.
This repo was kickstarted by nwb's awesome react-component starter.
You just need to clone it, yarn it & start it!
If you want to save large strings, like the stringified JSON of a drawing, I recommend you to use pieroxy/lz-string for compression. It's LZ compression will bring down your long strings to only ~10% of it's original size.
I borrowed a lot of the logic and actually used lazy-brush during the push to v1 of react-canvas-draw. Without it, react-canvas-draw would most likely still be pre v1 and wouldn't feel as good.
Thanks goes to these wonderful people (emoji key):
💻 📖 💡 🤔
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT, see LICENSE for details.