Skip to content

doei/react-sketch

 
 

Repository files navigation

react-sketch

GitHub release NPM release NPM downloads Build status

A Sketch tool for React based applications, backed-up by FabricJS

warning-image Please note that this module is still in development! Feel free to send me enhancements and ideas :)

Installation

npm install react-sketch --save

Source installation

In order to build from source, read the relevant instructions first.

On an ubuntu machine perform the following steps to install, node version should be >=4 , tested with versions 4,5,6 (see travis-ci). This is only for installation (npm install) we can then change back to a newer stable node version

$ sudo apt-get install libcairo2-dev libjpeg-dev libgif-dev
$ sudo npm install -g canvas
$ npm install

Usage

Import the relevant SketchField component and use it, you can find more on the examples folder of the project

import {SketchField, Tools} from 'react-sketch';

class SketchFieldDemo extends React.Component {
     render() {
        return (
            <SketchField width='1024px' 
                         height='768px' 
                         tool={Tools.Pencil} 
                         color='black'
                         lineWidth={3}/>
        )
     }
}

Configuration Options

Option Type Default Description
tool Enumeration (string) pencil The tool to use, can be select,pencil,circle, rectangle,circle
lineColor String black The color of the line
lineWidth Number 1 The width of the line
fillColor String transparent The fill color of the shape when applicable (e.g. circle)
undoSteps Number 15 number of undo/redo steps to maintain
imageFormat String png image format when calling toDataURL, can be png or jpeg
width Number No Value(null) Set/control the canvas width, if left empty the sketch will scale to parent element
height Number 512 Set/control the canvas height, if left empty the sketch will take a reasonable default height
defaultData JSON or data URL Default initial data, can be json or URL data accroding to configuration option below, in the case of data URL the initial drawing will be improted as an image
defaultDataType Enumeration (string) json The Type of initial data, can be either json or url

Examples

The project includes a webpack server for running the examples, just run:

git clone https://github.com/tbolis/react-sketch.git
npm install
npm start

and navigate to http://localhost:9999

You can as well check the live showcase here: http://tbolis.github.io/showcase/react-sketch/

Issues

See https://github.com/tbolis/react-sketch/issues

Changelog

See https://github.com/tbolis/react-sketch/blob/master/CHANGELOG.md

License

MIT, do remember to add a reference if you find it useful :)

About

Sketch Tool for React based applications, backed up by FabricJS

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%