Zum Inhalt springen
Docxcelerate

← Registry

Letterhead

Opening

The block at the top of the page. The address is one paragraph with the lines joined rather than one node per line, so a sender with two address lines and one with five both come out as a block instead of a ragged run of nodes.

npx dxcl add letterhead
exportiert Letterhead · löst zu 3 Nodes auf
01

Vorschaudaten

das JSON, mit dem diese Vorschau gebaut wurde
{
  "sender": {
    "name": "Riverside Leisure Centre",
    "addressLines": [
      "14 Mill Lane",
      "Bristol",
      "BS1 4TG"
    ]
  },
  "sentOn": "2026-09-01"
}
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 — 3 Nodes
letterhead-sender paragraph · static Riverside Leisure Centre
letterhead-address paragraph · static 14 Mill Lane, Bristol, BS1 4TG
letterhead-date paragraph · static 1 September 2026
04

Die Dateien

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

/**
 * The block at the top of the page saying who sent this and when.
 *
 * Written as loose paragraphs rather than a section, because a letterhead has
 * no heading — it is the thing a heading would sit under. The address is one
 * paragraph with the lines joined, so a sender with two address lines and one
 * with five both come out as a block rather than as a ragged run of nodes.
 *
 * Installed by `dxcl add letterhead`. It is your copy: rename it, re-order it,
 * or drop the date once it is in the project.
 */

/** What this component reads. Add these fields to your document data type. */
export interface LetterheadData {
  sender: {
    /** The organisation, as it should be printed. */
    name: string;
    /** Street, town, postcode — one entry per line. */
    addressLines: string[];
  };
  /** When the document was sent. Anything `Date` can parse. */
  sentOn: string | number | Date;
}

export const Letterhead: Nodes = () => {
  const format = useFormat();
  const [sender] = useState((data: LetterheadData) => ({
    name: data.sender.name,
    address: data.sender.addressLines.join(", "),
    sentOn: format.date(data.sentOn),
  }));

  return (
    <>
      <Paragraph id="letterhead-sender">{sender.name}</Paragraph>
      <Paragraph id="letterhead-address">{sender.address}</Paragraph>
      <Paragraph id="letterhead-date">{sender.sentOn}</Paragraph>
    </>
  );
};