Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving and Restoring DataURL results in smaller image #104

Closed
mweel1 opened this issue Dec 4, 2023 · 1 comment
Closed

Saving and Restoring DataURL results in smaller image #104

mweel1 opened this issue Dec 4, 2023 · 1 comment
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: duplicate solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue

Comments

@mweel1
Copy link

mweel1 commented Dec 4, 2023

Whenever I save the value, and restore the value the image is smaller then the viewport.

What is the best way to save a value and restore it on the signature pad?

import { FieldSignature, FieldTextBox } from "../types";
import { Input } from "../../components/input";
import { Label } from "../../components/label";
import SignatureCanvas from "react-signature-canvas";
import React from "react";

export function Signature(props: {
  signature: FieldSignature;
  onUpdate?: (field: FieldSignature) => void;
  onInit?: (field: FieldSignature) => void;
}) {
  const canvas = React.useRef<SignatureCanvas>(null);

  React.useEffect(() => {
    if (canvas.current) {
      if (props.signature.value)
        canvas.current.fromDataURL(props.signature.value);
    }
  }, []);
  return (
    <>
      {props.signature.label && (
        <>
          <div className="pb-3">
            <Label>
              {props.signature.label} {props.signature.required ? "*" : ""}
            </Label>
          </div>
        </>
      )}

      <SignatureCanvas
        ref={canvas}
        penColor="green"
        onEnd={(e) => {
          alert("Updating");
          const f = {
            ...props.signature,
            value: canvas.current!.getCanvas().toDataURL(),
          };

          if (props.onUpdate) props.onUpdate(f);
        }}
        canvasProps={{
          width: 500,
          height: 200,
          className:
            "sigCanvas border-[5px] rounded-md border-dashed border-b-red-300",
        }}
      />
      {props.signature.subLabel && (
        <>
          <div className="text-sm text-muted-foreground pt-2">
            {props.signature.subLabel}
          </div>
        </>
      )}
    </>
  );
}
@agilgur5 agilgur5 added solution: duplicate kind: support Asking for support with something or a specific use case labels Dec 4, 2023
@agilgur5
Copy link
Owner

Seems to be a duplicate of #6. You can specify a width and height as options to fromDataURL.

@agilgur5 agilgur5 added scope: upstream Issue in upstream dependency solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue labels Dec 18, 2023
Repository owner locked as resolved and limited conversation to collaborators Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: duplicate solution: out-of-scope This is out of scope for this project solution: workaround available A workaround is available for this issue
Projects
None yet
Development

No branches or pull requests

2 participants