Ir al contenido
Docxcelerate

← Registro

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
exporta SignatureBlock · se resuelve en 4 nodos
01

Datos de vista previa

el JSON con el que se construyó esta vista previa
{
  "signatory": {
    "name": "Tomas Lindqvist",
    "role": "Centre Manager",
    "signatureImage": "assets/signature-lindqvist.png"
  }
}
02

Vista previa renderizada

el componente renderizado por su cuenta
Open ↗
Renderizado por Docxcelerate en tiempo de compilación Abrir ↗
03

Nodos resueltos

lo que recibe un renderizador — 4 nodos
closing paragraph · static Yours sincerely,
signature-image image · static
signatory-name paragraph · static Tomas Lindqvist
signatory-role paragraph · static Centre Manager
04

Los archivos

lo que escribe la instalación; el archivo seleccionado es el componente
nodes/signature-block.node.tsx Código
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>
    </>
  );
};