# Add the "Giving Totals" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/giving-totals) to this Pantheon Content Publisher (P1) Next.js project. Headline giving figures plus a by-focus-area bar list with computed shares and a visible source line.

## Steps

1. Create `components/puck/giving-totals-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 { givingTotalsBlock } from "./components/puck/giving-totals-block";`
3. Register it under `components` as `GivingTotalsBlock: givingTotalsBlock`.
4. Add `"GivingTotalsBlock"` to the best-fitting entry in `categories` (this block's library category is "Foundations"). 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/giving-totals-block.tsx`

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

/**
 * Giving Totals — headline grantmaking figures (granted since founding, grants this year,
 * organizations funded, endowment) with a by-focus-area bar list and a source line.
 * Register: `GivingTotalsBlock: givingTotalsBlock` in puck.config.tsx.
 */

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

export type GivingTotalsProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  stats: { value: string; label: string; detail: string }[];
  breakdownHeading: string;
  areas: { label: string; amount: string }[];
  source: string;
  ctaLabel: string;
  ctaHref: string;
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };
const usdCompact = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", notation: "compact", maximumFractionDigits: 1 });
const parseAmount = (s?: string) => {
  const cleaned = (s || "").replace(/[^\d.-]/g, "");
  if (!cleaned) return null;
  const n = Number(cleaned);
  return Number.isFinite(n) ? n : null;
};

export const givingTotalsBlock: ComponentConfig<GivingTotalsProps> = {
  label: "Giving Totals",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. Leave blank to hide it." } },
    heading: { type: "text", 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." },
    },
    intro: { type: "textarea", label: "Intro" },
    stats: {
      type: "array",
      label: "Headline figures",
      min: 1,
      max: 4,
      getItemSummary: (item) => [item?.value, item?.label].filter(Boolean).join(" · ") || "Figure",
      defaultItemProps: { value: "$1M", label: "New figure", detail: "" },
      arrayFields: {
        value: { type: "text", label: "Figure", metadata: { help: "As it should appear, like $214M or 1,286." } },
        label: { type: "text", label: "Label" },
        detail: { type: "text", label: "Detail", metadata: { help: "Optional context, like Since 1962." } },
      },
    },
    breakdownHeading: { type: "text", label: "Breakdown heading", metadata: { help: "Like Grants by focus area, 2026. Leave the list empty to hide the breakdown." } },
    areas: {
      type: "array",
      label: "Focus areas",
      min: 0,
      max: 8,
      getItemSummary: (item) => [item?.label, item?.amount].filter(Boolean).join(" · ") || "Focus area",
      defaultItemProps: { label: "New focus area", amount: "$100,000" },
      arrayFields: {
        label: { type: "text", label: "Focus area" },
        amount: { type: "text", label: "Amount granted", metadata: { help: "Dollars, like $2,400,000. Bars and percentages are calculated from these." } },
      },
      metadata: { help: "List the largest first. Each bar's length is its share of the total." },
    },
    source: { type: "text", label: "Source line", metadata: { help: "Where the figures come from, like FY2026 audited financial statements." } },
    ctaLabel: { type: "text", label: "Link text", metadata: { help: "Leave blank to hide the link." } },
    ctaHref: { type: "text", label: "Link" },
  },
  defaultProps: {
    eyebrow: "Our giving",
    heading: "Six decades of investing in Harlow County",
    headingLevel: "h2",
    intro: "Thousands of donors, from first-time givers to families who started funds generations ago, have made this possible. Here's what their generosity adds up to.",
    stats: [
      { value: "$214M", label: "granted since 1962", detail: "To nonprofits, schools and public agencies" },
      { value: "1,286", label: "grants this year", detail: "Including donor-advised and scholarship grants" },
      { value: "612", label: "organizations funded", detail: "In fiscal year 2026" },
      { value: "$486M", label: "endowment", detail: "As of June 30, 2026" },
    ],
    breakdownHeading: "Discretionary grants by focus area, FY2026",
    areas: [
      { label: "Housing & neighborhoods", amount: "$4,850,000" },
      { label: "Early learning", amount: "$3,620,000" },
      { label: "Health access", amount: "$2,940,000" },
      { label: "Arts & culture", amount: "$1,310,000" },
      { label: "Nonprofit strength", amount: "$780,000" },
    ],
    source: "Sample figures. Source: Harlow Community Foundation FY2026 audited financial statements and IRS Form 990.",
    ctaLabel: "Read the annual report",
    ctaHref: "/about/annual-report",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, stats, breakdownHeading, areas, source, ctaLabel, ctaHref }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] ?? "h3";
    const uid = `gt-${id || "totals"}`;
    const figures = (stats ?? []).filter((s) => s?.value);
    const rows = (areas ?? [])
      .filter((a) => a?.label)
      .map((a) => ({ label: a.label, raw: a.amount, value: parseAmount(a.amount) }));
    const total = rows.reduce((sum, r) => sum + Math.max(0, r.value ?? 0), 0);
    const max = Math.max(0, ...rows.map((r) => r.value ?? 0));
    const statCols = figures.length >= 4 ? "lg:grid-cols-4" : figures.length === 3 ? "lg:grid-cols-3" : "";

    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-7xl">
          <div className="max-w-3xl">
            {eyebrow ? <p className="text-sm font-semibold tracking-widest text-indigo-700 uppercase">{eyebrow}</p> : null}
            {heading ? <H className={`text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl ${eyebrow ? "mt-3" : ""}`}>{heading}</H> : null}
            {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
          </div>

          {figures.length ? (
            <dl className={`mt-12 grid grid-cols-1 border-t border-neutral-950 sm:grid-cols-2 lg:mt-14 ${statCols}`}>
              {figures.map((s, i) => (
                <div key={`${s.label}-${i}`} className="flex flex-col border-b border-neutral-200 py-6 sm:pr-8 lg:border-b-0 lg:py-8">
                  <dt className="order-2 mt-2 text-base font-semibold text-neutral-950">{s.label}</dt>
                  <dd className="order-1 text-5xl leading-none font-semibold tracking-tight text-indigo-700 tabular-nums sm:text-6xl">{s.value}</dd>
                  {s.detail ? <dd className="order-3 mt-1 text-sm leading-6 text-pretty text-neutral-600">{s.detail}</dd> : null}
                </div>
              ))}
            </dl>
          ) : null}

          {rows.length ? (
            <div className="mt-14 grid grid-cols-1 gap-8 rounded-2xl bg-neutral-50 p-6 ring-1 ring-neutral-200 sm:p-8 lg:mt-16 lg:grid-cols-12 lg:gap-12 lg:p-10">
              <div className="lg:col-span-4">
                {breakdownHeading ? <Sub id={`${uid}-bd`} className="text-lg leading-7 font-semibold text-balance text-neutral-950">{breakdownHeading}</Sub> : null}
                {total > 0 ? (
                  <p className={`text-sm text-neutral-600 ${breakdownHeading ? "mt-2" : ""}`}>
                    <span className="font-semibold text-neutral-950 tabular-nums">{usdCompact.format(total)}</span> total across {rows.length} {rows.length === 1 ? "area" : "areas"}
                  </p>
                ) : null}
              </div>
              <ul role="list" aria-labelledby={breakdownHeading ? `${uid}-bd` : undefined} aria-label={breakdownHeading ? undefined : "Grants by focus area"} className="space-y-5 lg:col-span-8">
                {rows.map((r, i) => {
                  const v = Math.max(0, r.value ?? 0);
                  const pct = total > 0 ? Math.round((v / total) * 100) : 0;
                  const width = max > 0 ? Math.max(1, (v / max) * 100) : 0;
                  return (
                    <li key={`${r.label}-${i}`}>
                      <div className="flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 text-sm">
                        <span className="font-medium text-neutral-950">{r.label}</span>
                        <span className="text-neutral-600 tabular-nums">
                          <span className="font-semibold text-neutral-950">{r.value !== null ? usdCompact.format(v) : r.raw || "—"}</span>
                          {r.value !== null && total > 0 ? <span> · {pct}%</span> : null}
                        </span>
                      </div>
                      <div aria-hidden="true" className="mt-2 h-2.5 w-full overflow-hidden rounded-full bg-neutral-200">
                        <div className={`h-full rounded-full ${i === 0 ? "bg-indigo-700" : "bg-indigo-500"}`} style={{ width: `${width}%` }} />
                      </div>
                    </li>
                  );
                })}
              </ul>
            </div>
          ) : null}

          {source || ctaLabel ? (
            <div className="mt-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
              {source ? <p className="text-sm leading-6 text-pretty text-neutral-600">{source}</p> : <span />}
              {ctaLabel ? (
                <a href={ctaHref || "#"} className="inline-flex min-h-11 shrink-0 items-center gap-1.5 self-start rounded px-1 text-sm font-semibold text-indigo-700 hover:text-indigo-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 sm:self-auto">
                  {ctaLabel}
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4">
                    <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}
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```
