What is @types/react-signature-canvas?
@types/react-signature-canvas provides TypeScript definitions for the react-signature-canvas package, which is a React wrapper for the signature_pad library. This package allows you to easily integrate a signature canvas into your React applications, enabling users to draw signatures or other freehand drawings.
What are @types/react-signature-canvas's main functionalities?
Basic Signature Canvas
This code demonstrates how to set up a basic signature canvas using the react-signature-canvas package. The canvas allows users to draw signatures with a black pen.
import React from 'react';
import SignatureCanvas from 'react-signature-canvas';
const SignaturePad = () => {
let sigPad = React.useRef(null);
return (
<div>
<SignatureCanvas ref={(ref) => { sigPad = ref; }} penColor='black' canvasProps={{width: 500, height: 200, className: 'sigCanvas'}} />
</div>
);
};
export default SignaturePad;
Clear Signature Canvas
This code adds a button to clear the signature canvas. When the button is clicked, the clear function is called, which clears the canvas.
import React from 'react';
import SignatureCanvas from 'react-signature-canvas';
const SignaturePad = () => {
let sigPad = React.useRef(null);
const clear = () => {
sigPad.clear();
};
return (
<div>
<SignatureCanvas ref={(ref) => { sigPad = ref; }} penColor='black' canvasProps={{width: 500, height: 200, className: 'sigCanvas'}} />
<button onClick={clear}>Clear</button>
</div>
);
};
export default SignaturePad;
Save Signature as Image
This code adds a button to save the signature as an image. When the button is clicked, the save function is called, which logs the data URL of the signature image to the console.
import React from 'react';
import SignatureCanvas from 'react-signature-canvas';
const SignaturePad = () => {
let sigPad = React.useRef(null);
const save = () => {
const dataURL = sigPad.toDataURL();
console.log(dataURL);
};
return (
<div>
<SignatureCanvas ref={(ref) => { sigPad = ref; }} penColor='black' canvasProps={{width: 500, height: 200, className: 'sigCanvas'}} />
<button onClick={save}>Save</button>
</div>
);
};
export default SignaturePad;
Other packages similar to @types/react-signature-canvas
react-signature-pad-wrapper
react-signature-pad-wrapper is another React wrapper for the signature_pad library. It provides similar functionality to react-signature-canvas, allowing users to draw signatures on a canvas. However, it may have different APIs and additional features.
react-signature-pad
react-signature-pad is a React component for signature_pad. It offers similar capabilities for capturing signatures in a React application. The main difference is in the implementation and API, which might be more suitable for certain use cases.
Installation
npm install --save @types/react-signature-canvas
Summary
This package contains type definitions for react-signature-canvas (https://github.com/agilgur5/react-signature-canvas).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react-signature-canvas.
import * as React from "react";
import SignaturePad = require("signature_pad");
declare namespace ReactSignatureCanvas {
interface ReactSignatureCanvasProps extends SignaturePad.SignaturePadOptions {
canvasProps?: React.CanvasHTMLAttributes<HTMLCanvasElement> | undefined;
clearOnResize?: boolean | undefined;
}
}
declare class ReactSignatureCanvas extends React.Component<ReactSignatureCanvas.ReactSignatureCanvasProps> {
on: SignaturePad["on"];
off: SignaturePad["off"];
clear: SignaturePad["clear"];
isEmpty: SignaturePad["isEmpty"];
fromDataURL: SignaturePad["fromDataURL"];
toDataURL: SignaturePad["toDataURL"];
fromData: SignaturePad["fromData"];
toData: SignaturePad["toData"];
getCanvas(): HTMLCanvasElement;
getTrimmedCanvas(): HTMLCanvasElement;
getSignaturePad(): SignaturePad;
}
export = ReactSignatureCanvas;
Additional Details
Credits
These definitions were written by Kamil Socha.