Zum Inhalt springen
Docxcelerate

← Registry

Signature block

Closing

The image is optional and the name is not, which is the right way round: a letter signed by nobody is a letter nobody owns, whereas a missing image is a rendering detail. Without one the block closes with the typed name.

npx dxcl add signature-block
exportiert SignatureBlock · löst zu 4 Nodes auf
01

Vorschaudaten

das JSON, mit dem diese Vorschau gebaut wurde
{
  "signatory": {
    "name": "Tomas Lindqvist",
    "role": "Centre Manager",
    "signatureImage": "assets/signature-lindqvist.png"
  }
}
02

Gerenderte Vorschau

die Komponente für sich gerendert
Open ↗
Von Docxcelerate beim Build gerendert Öffnen ↗
03

Aufgelöste Nodes

was ein Renderer erhält — 4 Nodes
closing paragraph · static Yours sincerely,
signature-image image · static
signatory-name paragraph · static Tomas Lindqvist
signatory-role paragraph · static Centre Manager
04

Die Dateien

was die Installation schreibt; die gewählte Datei ist die Komponente
nodes/signature-block.node.tsx Quellcode
import { Image, type Nodes, Paragraph, useState } from "docxcelerate/template";

/**
 * How a letter ends: a closing line, a signature, and who signed it.
 *
 * The signature image is optional and the name is not, which is the right way
 * round — a letter signed by nobody is a letter nobody owns, whereas a missing
 * image is a rendering detail. Where there is no image the block simply closes
 * with the typed name.
 *
 * Installed by `dxcl add signature-block`.
 */

/** What this component reads. Add these fields to your document data type. */
export interface SignatoryData {
  signatory: {
    /** The person signing, as they should be printed. */
    name: string;
    /** Their role, printed beneath the name. */
    role: string;
    /** Path to a signature image, relative to the document project. */
    signatureImage?: string;
    /** How the letter closes. Defaults to "Yours sincerely". */
    closing?: string;
  };
}

export const SignatureBlock: Nodes = () => {
  const [signatory] = useState((data: SignatoryData) => data.signatory);

  return (
    <>
      <Paragraph id="closing">{signatory.closing ?? "Yours sincerely"},</Paragraph>
      {signatory.signatureImage && (
        <Image
          id="signature-image"
          src={signatory.signatureImage}
          alt={`Signature of ${signatory.name}`}
          width={160}
          height={54}
        />
      )}
      <Paragraph id="signatory-name">{signatory.name}</Paragraph>
      <Paragraph id="signatory-role">{signatory.role}</Paragraph>
    </>
  );
};