0.1.0 • Published 6 years ago

@creatdevsolutions/cs-react-signature-pad v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

React Signature Pad

A signature pad implementation for react in Typescript.

Basic Usage

interface Props {

}

interface State {

}

class App extends React.Component {
    constructor(props) {
        super(props);

        this.signaturePadRef = React.createFef<SignaturePad>();
    }

    render() {
        return (
            <SignaturePad
                ref={this.signaturePadRef}
                className={styles.SignaturePad}
            />
        )
    }

    componentDidMount() {
        const signaturePad: SignaturePad = this.signaturePadRef.current;

       // do some stuff
    }
}

Props

NameOptionalDefaultValueDescription
penColortrue#000000Sets the color of the pen to draw
backgroundColortrue#FFFFFFSets the backgroundColor of the canvas
defaultImagetrueundefinedFills the Signaturepad on mounting with this image, does not set it on reset
heightfalse150Height in pixel of the pad
widthfalse300Width in pixel of the pad
onEndtrue-Callback, fired when drawing a line ends
onBegintrue-Callback, fired when drawing a line begins
reffalse-React ref for the pad, only possible way to get data out of the pad

Methods

const signaturePad: SignaturePad = this.signaturePadRef.current;

// Methods

// ===============================================
// isEmpty() - returns boolean
// ===============================================

signaturePad.isEmpty();

// ===============================================
// clear() - clears canvas
// ===============================================

signaturePad.clear();

// ===============================================
// toDataURL() - retrieves image as a data url
// ===============================================

signaturePad.toDataURL();

// ===============================================
// fromDataURL() - writes a base64 image to canvas
// ===============================================

signaturePad.fromDataURL(base64String);

Example

$ npm start

Then navigate to http://localhost:3000/ in your browser and you should be able to see the signature pad in action.