|
| 1 | +import { Tailwind } from "@onedoc/react-print"; |
| 2 | +import { DocConfig } from "docgen/types"; |
| 3 | +import React from "react"; |
| 4 | + |
| 5 | +// This provides a loose support for DocuSign fields |
| 6 | +const availableFields = { |
| 7 | + signHere: "eSignSignHere", |
| 8 | + signHereOptional: "eSignSignHereOptional", |
| 9 | + signInitialHere: "eSignInitialHere", |
| 10 | + signInitialHereOptional: "eSignInitialHereOptional", |
| 11 | + company: "eSignCompany", |
| 12 | + dateSigned: "eSignDateSigned", |
| 13 | + title: "eSignTitle", |
| 14 | + fullName: "eSignFullName", |
| 15 | + lastName: "eSignLastName", |
| 16 | + firstName: "eSignFirstName", |
| 17 | + emailAddress: "eSignEmailAddress", |
| 18 | + number: "eSignNumber", |
| 19 | + date: "eSignDate", |
| 20 | + ssn: "eSignSSN", |
| 21 | + zip5: "eSignZIP5", |
| 22 | + zip5dash4: "eSignZIP5DASH4", |
| 23 | + note: "eSignNote", |
| 24 | + list: "eSignList", |
| 25 | + checkbox: "eSignCheckbox", |
| 26 | + radio: "eSignRadio", |
| 27 | + approve: "eSignApprove", |
| 28 | + decline: "eSignDecline", |
| 29 | + view: "eSignView", |
| 30 | + signerAttachment: "eSignSignerAttachment", |
| 31 | + signerAttachmentOptional: "eSignSignerAttachmentOptional", |
| 32 | +}; |
| 33 | + |
| 34 | +type fieldTypes = keyof typeof availableFields; |
| 35 | + |
| 36 | +export const Field = ({ |
| 37 | + type, |
| 38 | + signee, |
| 39 | + ...props |
| 40 | +}: { |
| 41 | + type: fieldTypes; |
| 42 | + signee: string; |
| 43 | +} & React.InputHTMLAttributes<HTMLInputElement>) => { |
| 44 | + return ( |
| 45 | + <input |
| 46 | + {...props} |
| 47 | + name={availableFields[type]} |
| 48 | + type={ |
| 49 | + type === "radio" ? "radio" : type === "checkbox" ? "checkbox" : "text" |
| 50 | + } |
| 51 | + data-onedoc-sign={type} |
| 52 | + className={`--onedoc-signature-field --onedoc-signature-field-${type} ${props.className || ""}`} |
| 53 | + /> |
| 54 | + ); |
| 55 | +}; |
| 56 | + |
| 57 | +export const __docConfig: DocConfig = { |
| 58 | + name: "Signature", |
| 59 | + icon: "signature", |
| 60 | + description: `Add signature fields to your document. You can specify various types of fields like signature, initials, date, and more. |
| 61 | +
|
| 62 | +<Warning> |
| 63 | +Signature and form filling are currently only available to select customers. If you would like to use these features in your project, please reach out at [email protected]. |
| 64 | +</Warning> |
| 65 | +`, |
| 66 | + components: { |
| 67 | + Field: { |
| 68 | + client: true, |
| 69 | + server: true, |
| 70 | + examples: { |
| 71 | + default: { |
| 72 | + description: `The created fields can be signed as-is in Acrobat Reader or other PDF viewers, using Onedoc's signature API, or through other e-signature services like [DocuSign](https://developers.docusign.com/docs/esign-rest-api/esign101/concepts/tabs/pdf-transform/). |
| 73 | +
|
| 74 | +Supported fields: |
| 75 | +
|
| 76 | +| Field Type | Description | |
| 77 | +|------------|-------------| |
| 78 | +| signHere | Signature field | |
| 79 | +| signHereOptional | Optional signature field | |
| 80 | +| signInitialHere | Initials field | |
| 81 | +| signInitialHereOptional | Optional initials field | |
| 82 | +| company | Company name field | |
| 83 | +| dateSigned | Date signed field | |
| 84 | +| title | Title field | |
| 85 | +| fullName | Full name field | |
| 86 | +| lastName | Last name field | |
| 87 | +| firstName | First name field | |
| 88 | +| emailAddress | Email address field | |
| 89 | +| number | Number field | |
| 90 | +| date | Date field | |
| 91 | +| ssn | Social Security Number field | |
| 92 | +| zip5 | ZIP code field | |
| 93 | +| zip5dash4 | ZIP code with 4-digit extension field | |
| 94 | +| note | Note field | |
| 95 | +| list | List field | |
| 96 | +| checkbox | Checkbox field | |
| 97 | +| radio | Radio button field | |
| 98 | +| approve | Approve button field | |
| 99 | +| decline | Decline button field | |
| 100 | +| view | View button field | |
| 101 | +| signerAttachment | Signer attachment field | |
| 102 | +| signerAttachmentOptional | Optional signer attachment field |`, |
| 103 | + template: ( |
| 104 | + <> |
| 105 | + <Tailwind> |
| 106 | + <h2 className="text-xl font-bold mb-4">Signature</h2> |
| 107 | + <div className="p-4 rounded-md border border-gray-200"> |
| 108 | + By |
| 109 | + <br /> |
| 110 | + <Field |
| 111 | + type="fullName" |
| 112 | + signee="sender" |
| 113 | + defaultValue="John Doe" |
| 114 | + className="border-b border-b-gray-300" |
| 115 | + /> |
| 116 | + <br /> |
| 117 | + <Field |
| 118 | + type="dateSigned" |
| 119 | + signee="sender" |
| 120 | + defaultValue="04/18/2024" |
| 121 | + className="border-b border-b-gray-300" |
| 122 | + /> |
| 123 | + <br /> |
| 124 | + <Field |
| 125 | + type="signHere" |
| 126 | + signee="sender" |
| 127 | + className="border border-gray-300 h-48" |
| 128 | + /> |
| 129 | + </div> |
| 130 | + </Tailwind> |
| 131 | + </> |
| 132 | + ), |
| 133 | + }, |
| 134 | + }, |
| 135 | + }, |
| 136 | + }, |
| 137 | +}; |
0 commit comments