Skip to content

Commit 2aa37ba

Browse files
committed
docs: update docs
1 parent df4eea7 commit 2aa37ba

File tree

1 file changed

+143
-1
lines changed

1 file changed

+143
-1
lines changed

README.md

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,143 @@
1-
# Vue 3 Signature Pad
1+
<p align="center">
2+
<h1 align="center">
3+
Vue 3 Signature Pad
4+
</h1>
5+
</p>
6+
7+
8+
A Vue 3 based smooth signature drawing component.
9+
10+
## Installation
11+
12+
```bash
13+
npm install @selemondev/vue3-signature-pad
14+
```
15+
16+
## Usage
17+
18+
```ts
19+
<script setup lang="ts">
20+
import { VueSignaturePad } from "@selemondev/vue3-signature-pad"
21+
import { onMounted, ref } from "vue";
22+
23+
const state = ref({
24+
options: {
25+
penColor: 'rgb(0, 0, 0)',
26+
backgroundColor: 'rgb(255, 255, 255)'
27+
},
28+
disabled: false,
29+
})
30+
31+
const colors = [
32+
{
33+
color: 'rgb(51, 133, 255)'
34+
},
35+
36+
{
37+
color: 'rgb(85, 255, 51)'
38+
},
39+
40+
{
41+
color: 'rgb(255, 85, 51)'
42+
}
43+
];
44+
45+
const activeColor = ref();
46+
47+
const signature = ref();
48+
49+
const handleSave = (t: string) => {
50+
return console.log(signature.value.undo())
51+
};
52+
const handleClear = (t: string) => {
53+
return signature.value.clearCanvas()
54+
};
55+
const handleUndo = (t: string) => {
56+
return signature.value.undo()
57+
};
58+
59+
const handleDisabled = () => {
60+
return state.disabled = !state.disabled;
61+
};
62+
63+
const handleFromDataURL = (url: string) => {
64+
return signature.value.fromDataURL(url);
65+
};
66+
67+
const handleAddWaterMark = () => {
68+
return signature1.value.addWaterMark({
69+
text: "Selemondev", // watermark text, > default ''
70+
font: "20px Arial", // mark font, > default '20px sans-serif'
71+
style: 'all', // fillText and strokeText, 'all'/'stroke'/'fill', > default 'fill
72+
fillStyle: "red", // fillcolor, > default '#333'
73+
strokeStyle: "blue", // strokecolor, > default '#333'
74+
x: 100, // fill positionX, > default 20
75+
y: 200, // fill positionY, > default 20
76+
sx: 100, // stroke positionX, > default 40
77+
sy: 200 // stroke positionY, > default 40
78+
});
79+
}
80+
</script>
81+
82+
<template>
83+
<div class="grid place-items-center w-full min-h-screen">
84+
<div class="flex flex-col items-center space-y-4">
85+
<div class="bg-gray-100 p-6">
86+
<VueSignaturePad ref="signature" height="400px" width="1280px" :maxWidth="2" :minWidth="2"
87+
:disabled="state.disabled"
88+
:options="{
89+
penColor: state.options.penColor, backgroundColor: state.options.backgroundColor
90+
}" />
91+
</div>
92+
93+
<button type="button" @click="handleSave('image/jpeg')">Save</button>
94+
<button type="button" @click="handleClear">Clear</button>
95+
<button type="button" @click="handleUndo">Undo</button>
96+
<button type="button" @click="handleDisabled">Disabled</button>
97+
<button type="button" @click="handleFromDataURL('https://github.com/selemondev.png')">
98+
FronData URL
99+
</button>
100+
<button type="button" @click="handleAddWaterMark">Add watermark</button>
101+
</div>
102+
</div>
103+
</template>
104+
```
105+
106+
## Props
107+
108+
109+
| name | type | default | description |
110+
|:-------------:|:-------------:|:-------------------------:| :-----------------: |
111+
| option | `Object` | {penColor:"rgb(0, 0, 0)", backgroundColor:"rgb(255,255,255)"} | penColor and backgroundColor |
112+
| width | `String` | "100%" | Pad width |
113+
| height | `String` | "100%" | Pad height |
114+
| throttle | `Number` | 16 | Draw the next point at most once per every x milliseconds |
115+
| maxWidth | `Number` | 2 | Maximum thickness of the pen line |
116+
| minWidth | `Number` | 2 | Minimum thickness of the pen line |
117+
| clearOnResize | `Boolean` | false |Clear canvas on window resize|
118+
| waterMark | `Object` | {} |Add addWaterMark |
119+
| disabled | `Boolean` | false |Disable canvas |
120+
| defaultUrl | `String` | "" |Show image by default |
121+
122+
## Events
123+
124+
| name | params | description |
125+
| :-------------: |:-------------: |:-------------:|
126+
| saveSignature | format (() / image/jpeg / image/svg) | Save image as PNG/JPEG or SVG |
127+
| clearCanvas | | Clear canvas |
128+
| isCanvasEmpty | | Returns true if the canvas is empty, otherwise it returns false |
129+
| undo | | Remove the last drawing |
130+
| addWaterMark | {} | Add waterMark
131+
| fromDataURL | (url) | Draw signature image from data URL.
132+
| handleBeginStroke | | Emits `Signature started` when the user starts drawing on the canvas.
133+
| handleEndStroke | | Emits `Signature ended` when the user stops drawing on the canvas.
134+
| handleBeforeUpdateStroke | | Emits `Signature before update` before the drawing gets updated on the canvas.
135+
| handleAfterUpdateStroke | | Emits `Signature after update` after the drawing gets updated on the canvas.
136+
137+
138+
## Credits go to these amazing projects
139+
140+
- [Signature Pad](https://github.com/szimek/signature_pad)
141+
142+
- [Vue 3 Signature](https://github.com/WangShayne/vue3-signature) - Vue 3 Signature Pad is an enhanced version of Vue 3 Signature with type safety and more options.
143+

0 commit comments

Comments
 (0)