1.1.1 • Published 7 years ago

react-drawable-canvas v1.1.1

Weekly downloads
145
License
MIT
Repository
github
Last release
7 years ago

react-drawable-canvas

Drawable canvas component for React.js.

Install

$ npm install react-drawable-canvas --save

Demo

Demo source

Example use:

const React = require('react');
const DrawableCanvas = require('react-drawable-canvas');

const App = React.createClass( {
 render() {
   return (
     <div>
       <DrawableCanvas />
     </div>
   );
 }
});

module.exports = App;

Default props is white background with black brush, size 4. Add custom styles in the canvasStyle object.

{
  brushColor: '#000000',
  lineWidth: 4,
  canvasStyle: {
    backgroundColor: 'FFFFFF'
  },
  clear: false
}

The clear property can be used to reset the drawing. All other updates should set clear to false. Example with buttons to clear the canvas and change the color:

const App = React.createClass( {

  getInitialState() {
    return {
      brushColor: '#800909',
      lineWidth: 4,
      canvasStyle: {
        backgroundColor: '#00FFDC'
      },
      clear: false
    };
  },

  handleOnClickClear() {
    this.setState({
      clear: true
    });
  },

  handleOnClickChangeColorYellow() {
    this.setState({
      brushColor: '#ffff00',
      clear: false
    });
  },

  handleOnClickChangeColorRed(){
    this.setState({
      brushColor: '#800909',
      clear: false
    });
  },

  render() {
    return (
      <div>
        <DrawableCanvas {...this.state} />
        <button onClick={this.handleOnClickClear}>Clear all</button>
        <button onClick={this.handleOnClickChangeColorYellow}>Set color to Yellow</button>
        <button onClick={this.handleOnClickChangeColorRed}>Set color to Red</button>
      </div>
    );
  }

});

module.exports = App;
1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago