-
+
+
+
+ {typeof userMark?.mark !== 'undefined' && (
+
+
+ )}
+
+
- >
+
)
}
diff --git a/src/components/MarkRender/Signature.module.scss b/src/components/MarkRender/Signature.module.scss
index 74be1a1..d09d6d2 100644
--- a/src/components/MarkRender/Signature.module.scss
+++ b/src/components/MarkRender/Signature.module.scss
@@ -1,4 +1,9 @@
-.svg {
+.img {
width: 100%;
height: 100%;
+ object-fit: contain;
+ overflow: hidden;
+ pointer-events: none;
+ -webkit-user-select: none;
+ user-select: none;
}
diff --git a/src/components/MarkRender/Signature.tsx b/src/components/MarkRender/Signature.tsx
index 1c8279f..1f90c9b 100644
--- a/src/components/MarkRender/Signature.tsx
+++ b/src/components/MarkRender/Signature.tsx
@@ -1,20 +1,27 @@
+import { useEffect, useState } from 'react'
+import SignaturePad from 'signature_pad'
import { MarkRenderProps } from '../../types/mark'
-import { SIGNATURE_PAD_SIZE } from '../../utils'
+import { SIGNATURE_PAD_OPTIONS, SIGNATURE_PAD_SIZE } from '../../utils'
+import { BasicPoint } from 'signature_pad/dist/types/point'
import styles from './Signature.module.scss'
export const MarkRenderSignature = ({ value }: MarkRenderProps) => {
- const segments: string[][] = value ? JSON.parse(value) : []
+ const [dataUrl, setDataUrl] = useState
()
- return (
-
- )
+ useEffect(() => {
+ if (value) {
+ const canvas = document.createElement('canvas')
+ canvas.width = SIGNATURE_PAD_SIZE.width
+ canvas.height = SIGNATURE_PAD_SIZE.height
+ const pad = new SignaturePad(canvas, SIGNATURE_PAD_OPTIONS)
+ pad.fromData(
+ JSON.parse(value).map((p: BasicPoint[]) => ({
+ points: p
+ }))
+ )
+ setDataUrl(canvas.toDataURL('image/webp'))
+ }
+ }, [value])
+
+ return dataUrl ? : null
}