# Add the "Matching Gift" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/matching-gift) to this Pantheon Content Publisher (P1) Next.js project. Your-gift-doubles banner with matcher, ratio, cap, deadline, progress toward the cap and an employer-match link.

## Steps

1. Create `components/puck/matching-gift-block.tsx` with the exact file contents below. If `components/puck/` doesn't exist, find the folder where this project keeps its Puck components (look at the imports in `puck.config.tsx`) and put it there.
2. In `puck.config.tsx`, import it: `import { matchingGiftBlock } from "./components/puck/matching-gift-block";`
3. Register it under `components` as `MatchingGiftBlock: matchingGiftBlock`.
4. Add `"MatchingGiftBlock"` to the best-fitting entry in `categories` (this block's library category is "Nonprofit"). Create a category only if none fits.
5. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
6. If `package.json` has a `sync:registry` script, tell the user it must run (or that CI will run it) before the new component appears in the P1 editor.

## Rules

- Do not add dependencies. The block is self-contained by design: one type-only import from `@puckeditor/core`, Tailwind v4 classes, no client JavaScript.
- Keep the files as-is unless the user asks for changes. The accent color is `indigo-*`; if the project has brand colors, offer to swap them with a find-and-replace on `indigo-`.
- Images are plain `imageUrl` + `imageAlt` text fields. If this project defines a P1 media-library field (search for `"p1-media"`), offer to switch to it.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/matching-gift-block.tsx`

```tsx
import type { ComponentConfig } from "@puckeditor/core";

/**
 * Matching Gift — a "your gift doubles" banner for a challenge match: who's matching, the
 * ratio, the cap and deadline, progress toward the cap, a give button, and a link to check
 * whether the donor's employer matches gifts too.
 * Register: `MatchingGiftBlock: matchingGiftBlock` in puck.config.tsx.
 */

type Heading = "h1" | "h2" | "h3" | "h4";

export type MatchingGiftProps = {
  ratio: string;
  ratioCaption: string;
  heading: string;
  headingLevel: Heading;
  body: string;
  matcher: string;
  matcherLabel: string;
  cap: string;
  capLabel: string;
  deadline: string;
  deadlineLabel: string;
  matched: string;
  matchedLabel: string;
  ctaLabel: string;
  ctaHref: string;
  employerText: string;
  employerLabel: string;
  employerHref: string;
};

const toNumber = (v?: string) => {
  const n = parseFloat(String(v ?? "").replace(/[^0-9.-]/g, ""));
  return Number.isFinite(n) ? n : null;
};

export const matchingGiftBlock: ComponentConfig<MatchingGiftProps> = {
  label: "Matching Gift",
  fields: {
    ratio: { type: "text", label: "Match ratio", metadata: { help: "Shown very large, like 2× for dollar-for-dollar or 3× for a 2:1 match." } },
    ratioCaption: { type: "text", label: "Ratio caption", metadata: { help: "Spells the ratio out, like Every $1 becomes $2. Also read to screen reader users." } },
    heading: { type: "textarea", label: "Heading" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H1", value: "h1" },
        { label: "H2", value: "h2" },
        { label: "H3", value: "h3" },
        { label: "H4", value: "h4" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    body: { type: "textarea", label: "Body" },
    matcherLabel: { type: "text", label: "Matcher label", metadata: { help: "Like Matched by." } },
    matcher: { type: "text", label: "Matcher", metadata: { help: "The donor, foundation or company putting up the match." } },
    capLabel: { type: "text", label: "Cap label", metadata: { help: "Like Matched up to." } },
    cap: { type: "text", label: "Cap", metadata: { help: "The most the matcher will give, like $50,000. Leave blank if there's no cap." } },
    deadlineLabel: { type: "text", label: "Deadline label", metadata: { help: "Like Match ends." } },
    deadline: { type: "text", label: "Deadline", metadata: { help: "Write it out, like Midnight, Dec. 31. Leave blank to hide it." } },
    matchedLabel: { type: "text", label: "Progress label", metadata: { help: "Like matched so far." } },
    matched: {
      type: "text",
      label: "Matched so far",
      metadata: { help: "Like $31,400. With a cap, this shows a progress bar. Bind it to a data source to keep it current, or leave blank to hide it." },
    },
    ctaLabel: { type: "text", label: "Button text" },
    ctaHref: { type: "text", label: "Button link" },
    employerText: { type: "text", label: "Employer match text", metadata: { help: "A line about workplace matching gifts. Leave blank to hide it." } },
    employerLabel: { type: "text", label: "Employer link text" },
    employerHref: { type: "text", label: "Employer link", metadata: { help: "Your employer-match lookup page or tool." } },
  },
  defaultProps: {
    ratio: "2×",
    ratioCaption: "Every $1 you give becomes $2",
    heading: "Your gift goes twice as far this month",
    headingLevel: "h2",
    body: "A longtime supporter has pledged to match every gift to Fernbrook Land Trust, dollar for dollar, until the match runs out. Your gift and theirs go straight to restoring Cold Spring Run.",
    matcherLabel: "Matched by",
    matcher: "The Aldine Family Foundation",
    capLabel: "Matched up to",
    cap: "$50,000",
    deadlineLabel: "Match ends",
    deadline: "Midnight, Dec. 31",
    matchedLabel: "matched so far",
    matched: "$31,400",
    ctaLabel: "Double my gift",
    ctaHref: "/donate?campaign=match",
    employerText: "Many employers match gifts too, which can triple your impact.",
    employerLabel: "Check if your employer matches",
    employerHref: "/give/employer-match",
  },
  render: ({ id, ratio, ratioCaption, heading, headingLevel, body, matcher, matcherLabel, cap, capLabel, deadline, deadlineLabel, matched, matchedLabel, ctaLabel, ctaHref, employerText, employerLabel, employerHref }) => {
    const H = headingLevel || "h2";
    const capN = toNumber(cap);
    const matchedN = toNumber(matched);
    const pct = capN && capN > 0 && matchedN !== null ? Math.min(100, Math.max(0, (matchedN / capN) * 100)) : null;
    const terms = [
      { key: "matcher", label: matcherLabel, value: matcher },
      { key: "cap", label: capLabel, value: cap },
      { key: "deadline", label: deadlineLabel, value: deadline },
    ].filter((t) => t.value);
    const progressId = `${id || "match"}-progress`;

    return (
      <section className="bg-white px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-6xl overflow-hidden rounded-3xl bg-indigo-950 shadow-xl shadow-indigo-950/20">
          <div className="grid grid-cols-1 lg:grid-cols-12">
            {ratio ? (
              <div className="relative isolate flex flex-col justify-center overflow-hidden bg-indigo-700 px-6 py-10 sm:px-10 lg:col-span-5 lg:py-14">
                <svg aria-hidden="true" viewBox="0 0 200 200" className="absolute -right-16 -bottom-16 -z-10 size-72 text-indigo-600">
                  <circle cx="100" cy="100" r="98" fill="none" stroke="currentColor" strokeWidth="2" />
                  <circle cx="100" cy="100" r="70" fill="none" stroke="currentColor" strokeWidth="2" />
                  <circle cx="100" cy="100" r="42" fill="none" stroke="currentColor" strokeWidth="2" />
                </svg>
                <p aria-hidden="true" className="text-8xl leading-none font-semibold tracking-tighter text-white tabular-nums sm:text-9xl">
                  {ratio}
                </p>
                {ratioCaption ? <p className="mt-4 text-lg font-medium text-indigo-100">{ratioCaption}</p> : null}
              </div>
            ) : null}

            <div className={`px-6 py-10 sm:px-10 lg:py-14 ${ratio ? "lg:col-span-7" : "lg:col-span-12"}`}>
              {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-white sm:text-4xl">{heading}</H> : null}
              {body ? <p className="mt-4 text-base leading-7 text-pretty text-indigo-100 sm:text-lg sm:leading-8">{body}</p> : null}

              {terms.length ? (
                <dl className="mt-8 grid grid-cols-1 gap-x-6 gap-y-4 border-y border-white/15 py-6 sm:grid-cols-3">
                  {terms.map((t) => (
                    <div key={t.key} className={`min-w-0 ${t.key === "matcher" && terms.length === 3 ? "sm:col-span-3" : ""}`}>
                      {t.label ? <dt className="text-sm text-indigo-200">{t.label}</dt> : null}
                      <dd className="mt-0.5 font-semibold break-words text-white">{t.value}</dd>
                    </div>
                  ))}
                </dl>
              ) : null}

              {matched ? (
                <div className="mt-6">
                  <p id={progressId} className="text-sm text-indigo-100">
                    <span className="font-semibold text-white tabular-nums">{matched}</span> {matchedLabel}
                    {cap && pct !== null ? <span className="tabular-nums"> of {cap}</span> : null}
                  </p>
                  {pct !== null ? (
                    <div
                      role="progressbar"
                      aria-labelledby={progressId}
                      aria-valuemin={0}
                      aria-valuemax={100}
                      aria-valuenow={Math.round(pct)}
                      aria-valuetext={`${Math.round(pct)}% of the match claimed`}
                      className="mt-3 h-2.5 overflow-hidden rounded-full bg-white/15"
                    >
                      <div className="h-full rounded-full bg-white" style={{ width: `${pct}%` }} />
                    </div>
                  ) : null}
                </div>
              ) : null}

              {ctaLabel || employerLabel ? (
                <div className="mt-8 flex flex-col gap-4 sm:flex-row sm:flex-wrap sm:items-center sm:gap-6">
                  {ctaLabel ? (
                    <a
                      href={ctaHref || "#"}
                      className="group inline-flex min-h-12 items-center justify-center gap-2 rounded-lg bg-white px-6 py-3 text-base font-semibold text-indigo-950 transition hover:bg-indigo-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                    >
                      {ctaLabel}
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 transition group-hover:translate-x-0.5">
                        <path fillRule="evenodd" d="M3 10a.75.75 0 0 1 .75-.75h10.64l-3.22-3.22a.75.75 0 1 1 1.06-1.06l4.5 4.5a.75.75 0 0 1 0 1.06l-4.5 4.5a.75.75 0 1 1-1.06-1.06l3.22-3.22H3.75A.75.75 0 0 1 3 10Z" clipRule="evenodd" />
                      </svg>
                    </a>
                  ) : null}
                  {employerLabel ? (
                    <p className="text-sm leading-6 text-indigo-100">
                      {employerText ? <span className="block">{employerText}</span> : null}
                      <a
                        href={employerHref || "#"}
                        className="inline-flex min-h-11 items-center font-semibold text-white underline decoration-indigo-300 underline-offset-4 hover:decoration-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
                      >
                        {employerLabel}
                      </a>
                    </p>
                  ) : null}
                </div>
              ) : null}
            </div>
          </div>
        </div>
      </section>
    );
  },
};
```
