2.0.5 • Published 2 years ago

paintpad v2.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

PaintPad

Canvas component which allows freeform painting.

NPM Version build License

demo

Installation

Yarn

yarn add paintpad

NPM

npm install --save paintpad

UNPKG

<script src="https://unpkg.com/paintpad/dist/index.js" defer></script>

Usage

HTML

<paint-pad
  width="300px"
  height="300px"
  lineWidth="15"
  lineWidthMin="5"
  lineWidthMax="25"
  color="#ffdab9"
  hasSlider="true"
  hasColorPicker="true"
  isClearable="true"
  isDownloadable="true"
  isStateChangeable="true"
></paint-pad>

JavaScript

import { PaintPad } from "paintpad";

const paintPad = new PaintPad({
  width: "300px",
  height: "300px",
  lineWidth: 15,
  lineWidthMin: 5,
  lineWidthMax: 25,
  color: "#ffdab9",
  hasSlider: true,
  hasColorPicker: true,
  isClearable: true,
  isDownloadable: true,
  isStateChangeable: true,
});

document.getElementById("paint-pad-container").append(paintPad);

Angular

// app.module.ts

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

@NgModule({
  ...
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
  ...
})
// app.component.html

<paint-pad #paintPad width="300px" color="#ffdab9"></paint-pad>
// app.component.ts

import "paintpad";

export class AppComponent {
  @ViewChild('paintPad') public paintPad!: ElementRef;

  public clear(): void {
    this.paintPad.nativeElement.clear();
  }
}

React

import "paintpad";

function App() {
  const paintPad = useRef(null);

  const clear = () => paintPad.current.clear();

  return <paint-pad ref={paintPad} width="300px" color="#ffdab9"></paint-pad>;
}

Options

attributetypedescriptiondefault
widthstringwidth of the canvas'500px'
heightstringheight of the canvas'500px'
lineWidthnumberinitial thickness of the pencil10
lineWidthMinnumberminimal thickness of the pencil1
lineWidthMaxnumbermaximum thickness of the pencil30
colorstringinitial color of the pencil (must be a hexcode of 6 characters)'#000000'
imageNamestringname of the downloaded image'paintpad'
hasSliderbooleanif the user can change the thickness of the penciltrue
hasColorPickerbooleanif the user can change the color of the penciltrue
isClearablebooleanif the user can clear the canvastrue
isDownloadablebooleanif the user can download an image of the canvastrue
isStateChangeablebooleanif the user can undo and redo the state to the canvastrue

Methods

methodparametersdescription
setWidthwidth: stringsets the width of the canvas
setHeightheight: stringsets the height of the canvas
setLineWidthlineWidth: numbersets the thickness of the pencil
setLineWidthMinlineWidth: numbersets the minimal thickness of the pencil
setLineWidthMaxlineWidth: numbersets the maximum thickness of the pencil
setColorcolor: stringsets the color of the pencil
setImageNamename: stringsets the name of the downloaded image
setSliderisVisible: booleanif the user can change the thickness of the pencil
setColorPickerisVisible: booleanif the user can change the color of the pencil
setClearableisVisible: booleanif the user can clear the canvas
setDownloadableisVisible: booleanif the user can download an image of the canvas
setStateChangeableisVisible: booleanif the user can undo and redo the state to the canvas
clearclears the canvas
downloaddownloads an image of the canvas
undochanges the state of the canvas to the previous state
redochanges the state of the canvas to the next state
getDataURLreturns the data url of the canvas
getBlobcallback: BlobCallbacktype?: string \| undefinedquality?: numbergets the blob of the canvas in a callback function