JSPM

@siamf/react-signature-pad

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 32
  • Score
    100M100P100Q74303F
  • License MIT

A react signature pad wrapper component with all essential API and latest version of signature pad.

Package Exports

  • @siamf/react-signature-pad
  • @siamf/react-signature-pad/dist/cjs/index.js
  • @siamf/react-signature-pad/dist/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@siamf/react-signature-pad) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


Siam Ahnaf

@siamf/react-signature-pad

A react wrapper component for signature pad integration into react with typescript and latest version of signature pad. It supports all kind of essentials API and options.

Buy Me A Coffee

Installation

$ npm i @siamf/react-signature-pad

Usage

import { SignaturePad } from "@siamf/react-signature-pad";

//SignaturePad Component
<SignaturePad
  canvasProps={{ width: 600, height: 300 }}
/>

How to use API?

import { SignaturePad, SignatureCanvasRef } from "@siamf/react-signature-pad";
import { useRef } from "react";

const MyComponent = () => {
    const ref = useRef<SignatureCanvasRef>(null);

    const getDataUrl = () => {
        if (ref.current) {
            const dataUrl = ref.current.toDataURL();
            console.log('Signature as PNG:', dataUrl);
        }
    };

    //You can use All API by calling ref object;

    return (
        <div>
          <SignaturePad
            canvasProps={{ width: 600, height: 300 }}
            ref={ref}
          />
          <button onClick={getDataUrl}>
            Download Signature
          </button>
        </div>
    )
}

export default MyComponent;

Props

Name Types Description
dotSize number Radius of a single dot. Also the width of the start of a mark.
minWidth number Minimum width of a line. Defaults to 0.5.
maxWidth number Maximum width of a line. Defaults to 2.5.
throttle number Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
minDistance number Add the next point only if the previous one is farther than x pixels. Defaults to 5.
backgroundColor string Color used to clear the background. Can be any color format accepted by context.fillStyle. Defaults to "rgba(0,0,0,0)" (transparent black). Use a non-transparent color e.g. "rgb(255,255,255)" (opaque white) if you'd like to save signatures as JPEG images.
penColor string Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
velocityFilterWeight number Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
canvasContextOptions CanvasRenderingContext2DSettings Part of the Canvas API, provides the 2D rendering context for the drawing surface of a canvas element. It is used for drawing shapes, text, images, and other objects
canvasProps HTMLCanvasElement Direct canvas html element props
clearOnResize boolean Whether or not the canvas should be cleared when the window resizes

API Method

Name Types Default
clear() () => void Clear canvas element
isEmpty() () => boolean Whether canvas empty or not
toDataURL() (type?: string, encoderOptions?: number):string Get signature Data URL
toFile() (type?: string, encoderOptions?: number):File Get Signature Image File
toSVG() (options?: ToSVGOptions) Get the svg element
fromDataURL() (dataUrl: string, options?: { ratio?: number; width?: number; height?: number; xOffset?: number; yOffset?: number }) => Promise Writes a base64 image to canvas
toData() () => PointGroup[] Returns signature image as an array of point groups
fromData() (pointGroups: PointGroup[], options?: { clear?: boolean }) => void Draws signature image from an array of point groups
getCanvas() () => HTMLCanvasElement Get HTML Canvas Element
getSignaturePad() () => SignaturePad Get the whole Signature Pas Instance
on() () => void; Rebinds all event handlers
off() () => void; Unbinds all event handlers

Stay in touch