2.1.5 • Published 3 years ago

vue-paintable v2.1.5

Weekly downloads
1,119
License
-
Repository
github
Last release
3 years ago

vue-paintable npm npm.io

With this vue plugin and component you can add a paintable canvas through your page. All paintings are saved by default into localStorage.

How to use?

npm install vue-paintable

or

yarn add vue-paintable

Inside your main (typically main.js)

import Vue from 'vue';
import Paintable from 'vue-paintable';

Vue.use(Paintable, {
  // optional methods
  setItem(key, image) {
    localStorage.setItem(key, image);
  },
  // you also can use async
  getItem(key) {
    return localStorage.getItem(key);
  },
  removeItem(key) {
    localStorage.removeItem(key);
  }
});
//...

Inside your components

<template>
  <paintable
    alwaysOnTop
    :active="isActive"
    :width="800"
    :height="800"
    :disableNavigation="disableNavigation"
    :hide="hidePaintable"
    :horizontalNavigation="true"
    :navigation="navigation"
    :name="isFirstPaintable ? 'my-screen' : 'my-second-screen'"
    :factor="1"
    :lineWidth="dynamicLineWidth"
    :lineWidthEraser="20"
    :useEraser="useEraser"
    :color="color"
    class="paint"
    ref="paintable"
    @toggle-paintable="toggledPaintable"
  >
    Your content
    <router-view></router-view>
  </paintable>
</template>

Navigation

Set your own navigation content by adding an object to your <paintable> component.

{
  'draw-save': {
    body: 'draw',
    activeBody: '<strong>save</strong>'
  },
  color: {
    body: 'CP'
  }
}

Display navigation horizontal

To display the navigation horizontally add horizontalNavigation to prop list.

Available navigation items:

  • color
  • line-width
  • undo
  • redo
  • delete
  • cancel

has active state (activeBody):

  • draw-save
  • eraser-pencil

Custom Navigation

To use a custom navigation disable the default navigation with disableNavigation.

use \$refs to call paintable methods

<paintable ref="paintable">content</paintable>

<button @click="$refs.paintable.undoDrawingStep">undo</button>
<button @click="$refs.paintable.redoDrawingStep">redo</button>
<button @click="$refs.paintable.clearCanvas">clear</button>
<button @click="$refs.paintable.saveCurrentCanvasToStorage">
  save
</button>
<button @click="$refs.paintable.cancelDrawing">cancel</button>

Take a look at the demo (/src/App.vue)

Props

nametyperequireddefaultdescription
namestring - requiredtrue-unique identifier
showUndoRedobooleanfalsetrueshow undo and redo button
hidebooleanfalsefalsehide the complete paintable
colorsArray of colors (rgb, hex etc.)false'black', '#f00', '#4481c7', 'rgba(255, 235, 59, 0.4)', '#999', 'green'array of choosable colors
widthnumberfalsewindow.innerWidthcanvas width
heightnumberfalsewindow.innerHeightcanvas height
showLineWidthbooleanfalsetrueshow button to set line width
lineWidthnumberfalse5line width
alwaysOnTopbooleanfalsetrueset canvas always as top layer
factornumberfalse1set a scale factor if needed
lineWidthErasernumberfalse20set eraser line width
horizontalNavigationbooleanfalsetruedisplay the navigation horizontally or vertically
disableNavigationbooleanfalsefalsehide navigation
activebooleanfalsefalseset paintable active/inactive
colorstringfalse#000current color
useEraserbooleanfalsefalseset to true, to use the eraser
thresholdnumberfalse0set the threshold on which an event gets triggered (see events)

Events

nametypedescription
toggle-paintablebooleanIs emitted, when changing paintable state
thresholdReachedbooleanIs emitted, when the speciefied threshold is reached
<paintable @toggle-paintable="toggledPaintable"></paintable>

<paintable :threshold="10" @thresholdReached="thresholdReached"></paintable>

development

If you want to develop with this plugin, follow these steps:

  • clone repo
  • run yarn install or npm install
  • run yarn serve or npm run serve

build

You can find all built files inside the dist folder.

  • run yarn build or npm run build
2.1.4

3 years ago

2.1.5

3 years ago

2.1.3

4 years ago

2.1.2

4 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.1

5 years ago

0.12.0

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

1.0.0

5 years ago

0.10.2

5 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.0

6 years ago

0.4.7

6 years ago

0.4.6

6 years ago

0.4.5

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

6 years ago

0.4.1

6 years ago