You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A React wrapper for [signature pad](https://github.com/szimek/signature_pad).
12
13
13
14
## Installation
15
+
14
16
This package is available through npm:
17
+
15
18
```
16
19
npm install --save react-signature-pad-wrapper
17
20
```
18
21
19
22
## Usage
20
-
This package implements exactly the same interface as the original *signature_pad* package and adds a couple of extra features that make responsive behaviour a little easier to deal with. For a complete overview of the available options and callables see the documentation for [signature pad](https://github.com/szimek/signature_pad).
23
+
24
+
This package implements exactly the same interface as the original _signature_pad_ package and adds a couple of extra features that make responsive behaviour a little easier to deal with. For a complete overview of the available options and callables see the documentation for [signature pad](https://github.com/szimek/signature_pad).
The HTML canvas object sucks when it comes to responsiveness. The approach taken with this plugin is to use a fixed size canvas when a height and width (in pixels) is explicitly passed in as a component property:
68
+
58
69
```javascript
59
70
...
60
71
render() {
@@ -64,28 +75,35 @@ render() {
64
75
```
65
76
66
77
If you want the component to be responsive, simply ommit the width and height property:
78
+
67
79
```javascript
68
80
...
69
81
render() {
70
82
return<SignaturePad />;
71
83
}
72
84
...
73
85
```
86
+
74
87
The canvas width and height will now be updated whenever the window is resized (using a debounced handler). Changing the width and height properties of a HTML canvas object will erase its current content.
75
88
76
89
If you'd like to keep what is currently drawn on the canvas you can pass a `redrawOnResize` property to the component and set it to `true` (`redrawOnResize` is `false` by default):
90
+
77
91
```javascript
78
92
...
79
93
render() {
80
94
return<SignaturePad redrawOnResize />;
81
95
}
82
96
...
83
97
```
98
+
84
99
This will save the current canvas content to a base64 data string before performing the resize operation and load it in the canvas right after the resize operation finishes. **Note**: the repeated saving and loading of image data when resizing often will degrade the quality rapidly. There is no easy solution around this unfortunately. Resampling the image data is imagined to help significantly, but this is a rather costly operation in general and not something you would ideally do with JavaScript in the browser on every resize event (even if throttled/debounced).
85
100
86
101
## Example
102
+
87
103
This project includes a simple example that demonstrates a responsive sketch pad. To build the example:
104
+
88
105
```shell
89
106
cd example && npm run build
90
107
```
108
+
91
109
Then open `example/index.html` in a browser of your choice.
0 commit comments