# Add the "Grants Awarded" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/grants-awarded) to this Pantheon Content Publisher (P1) Next.js project. Accessible table of awarded grants with grantee, program, amount, year and purpose, a computed total and CSV link.

## Steps

1. Create `components/puck/grants-awarded-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 { grantsAwardedBlock } from "./components/puck/grants-awarded-block";`
3. Register it under `components` as `GrantsAwardedBlock: grantsAwardedBlock`.
4. Add `"GrantsAwardedBlock"` 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/grants-awarded-block.tsx`

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

/**
 * Grants Awarded — a real table of grants (grantee, program, amount, year, purpose)
 * with a computed totals row, horizontal scroll on phones and a CSV download link.
 * Register: `GrantsAwardedBlock: grantsAwardedBlock` in puck.config.tsx.
 */

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

type Grant = { grantee: string; program: string; amount: string; year: string; purpose: string };

export type GrantsAwardedProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  caption: string;
  grants: Grant[];
  showTotal: boolean;
  csvLabel: string;
  csvHref: string;
  source: string;
};

const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";
const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD", maximumFractionDigits: 0 });

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 grantsAwardedBlock: ComponentConfig<GrantsAwardedProps> = {
  label: "Grants Awarded",
  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" },
    caption: { type: "text", label: "Table caption", metadata: { help: "Describes the table, like Grants approved by the board in 2026. Read aloud to screen reader users." } },
    grants: {
      type: "array",
      label: "Grants",
      min: 1,
      max: 60,
      getItemSummary: (item) => [item?.grantee, item?.amount].filter(Boolean).join(" · ") || "Grant",
      defaultItemProps: { grantee: "New grantee", program: "", amount: "$10,000", year: "2026", purpose: "" },
      arrayFields: {
        grantee: { type: "text", label: "Grantee" },
        program: { type: "text", label: "Program", metadata: { help: "The grant program or focus area." } },
        amount: { type: "text", label: "Amount", metadata: { help: "Dollars, like $25,000. Used for the total; leave blank if undisclosed." } },
        year: { type: "text", label: "Year" },
        purpose: { type: "textarea", label: "Purpose", metadata: { help: "One sentence on what the grant supports." } },
      },
      metadata: { help: "Shown in the order entered. For long lists, link the full CSV below." },
    },
    showTotal: {
      type: "radio",
      label: "Totals row",
      options: [
        { label: "Show", value: true },
        { label: "Hide", value: false },
      ],
      metadata: { help: "Adds up every amount in the table." },
    },
    csvLabel: { type: "text", label: "Download link text", metadata: { help: "Leave blank to hide the link." } },
    csvHref: { type: "text", label: "Download link", metadata: { help: "A CSV in your media library." } },
    source: { type: "text", label: "Source line", metadata: { help: "Where the figures come from, like Board-approved grants, FY2026." } },
  },
  defaultProps: {
    eyebrow: "Grants awarded",
    heading: "Recent grants",
    headingLevel: "h2",
    intro: "Every grant the board approves is published here within 30 days. These are the most recent; the full list goes back to 1998.",
    caption: "Grants approved by the Harlow Community Foundation board, 2026",
    grants: [
      { grantee: "Eastside Tenant Legal Services", program: "Thriving Neighborhoods", amount: "$60,000", year: "2026", purpose: "Two staff attorneys for eviction defense in Harlow County housing court." },
      { grantee: "Little Acorns Child Development Center", program: "Early Learning", amount: "$35,000", year: "2026", purpose: "Wage supplements and credential coursework for 14 infant-toddler teachers." },
      { grantee: "Harlow County Public Library Foundation", program: "Early Learning", amount: "$22,500", year: "2026", purpose: "Bilingual family story-time at six branch libraries." },
      { grantee: "Riverbend Arts Collective", program: "Arts Access", amount: "$8,000", year: "2026", purpose: "Free summer mural program pairing teen apprentices with local artists." },
      { grantee: "Northside Community Health Clinic", program: "Health Access", amount: "$50,000", year: "2026", purpose: "Mobile dental unit visits to rural schools in the county's north end." },
      { grantee: "Second Street Neighborhood Association", program: "Thriving Neighborhoods", amount: "$12,000", year: "2026", purpose: "Resident-led planning for the Second Street corridor, with a fiscal sponsor." },
    ],
    showTotal: true,
    csvLabel: "Download the full grants list (CSV)",
    csvHref: "/files/harlow-grants-awarded.csv",
    source: "Sample figures. Source: Harlow Community Foundation board-approved grants, 2026.",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, caption, grants, showTotal, csvLabel, csvHref, source }) => {
    const H = headingLevel || "h2";
    const uid = `ga-${id || "table"}`;
    const rows = (grants ?? []).filter((g) => g?.grantee);
    const amounts = rows.map((g) => parseAmount(g.amount));
    const counted = amounts.filter((a): a is number => a !== null);
    const total = counted.reduce((s, n) => s + n, 0);
    const hasHeader = Boolean(eyebrow || heading || intro || csvLabel);

    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">
          {hasHeader ? (
            <div className="flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between lg:gap-16">
              <div className="max-w-2xl">
                {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>
              {csvLabel ? (
                <a href={csvHref || "#"} download className={`inline-flex min-h-11 shrink-0 items-center justify-center gap-2 self-start rounded-lg px-4 py-2.5 text-sm font-semibold text-neutral-950 ring-1 ring-neutral-300 transition ring-inset hover:bg-neutral-50 hover:ring-indigo-400 lg:self-auto ${focusRing}`}>
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 text-indigo-700">
                    <path d="M10.75 2.75a.75.75 0 0 0-1.5 0v8.614L6.295 8.235a.75.75 0 1 0-1.09 1.03l4.25 4.5a.75.75 0 0 0 1.09 0l4.25-4.5a.75.75 0 0 0-1.09-1.03l-2.955 3.129V2.75Z" />
                    <path d="M3.5 12.75a.75.75 0 0 0-1.5 0v2.5A2.75 2.75 0 0 0 4.75 18h10.5A2.75 2.75 0 0 0 18 15.25v-2.5a.75.75 0 0 0-1.5 0v2.5c0 .69-.56 1.25-1.25 1.25H4.75c-.69 0-1.25-.56-1.25-1.25v-2.5Z" />
                  </svg>
                  {csvLabel}
                </a>
              ) : null}
            </div>
          ) : null}

          {rows.length ? (
            <div
              role="region"
              aria-labelledby={`${uid}-caption`}
              tabIndex={0}
              className={`relative -mx-4 overflow-x-auto sm:mx-0 sm:rounded-2xl sm:ring-1 sm:ring-neutral-950/10 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-indigo-600 ${hasHeader ? "mt-10 sm:mt-12" : ""}`}
            >
              <table className="w-full min-w-3xl border-collapse text-left text-sm">
                <caption id={`${uid}-caption`} className="px-4 pb-3 text-left text-sm font-semibold text-neutral-950 sm:px-6 sm:pt-5">
                  {caption || heading || "Grants awarded"}
                  <span className="ml-2 font-normal text-neutral-600 sm:hidden">Scroll sideways for more columns.</span>
                </caption>
                <thead className="bg-neutral-50">
                  <tr className="border-y border-neutral-200">
                    <th scope="col" className="py-3 pr-3 pl-4 text-xs font-semibold tracking-wide text-neutral-700 uppercase sm:pl-6">Grantee</th>
                    <th scope="col" className="px-3 py-3 text-xs font-semibold tracking-wide text-neutral-700 uppercase">Program</th>
                    <th scope="col" className="px-3 py-3 text-right text-xs font-semibold tracking-wide text-neutral-700 uppercase">Amount</th>
                    <th scope="col" className="px-3 py-3 text-xs font-semibold tracking-wide text-neutral-700 uppercase">Year</th>
                    <th scope="col" className="py-3 pr-4 pl-3 text-xs font-semibold tracking-wide text-neutral-700 uppercase sm:pr-6">Purpose</th>
                  </tr>
                </thead>
                <tbody className="divide-y divide-neutral-200">
                  {rows.map((g, i) => (
                    <tr key={`${g.grantee}-${i}`} className="align-top hover:bg-indigo-50/50">
                      <th scope="row" className="max-w-56 py-4 pr-3 pl-4 font-semibold text-pretty text-neutral-950 sm:pl-6">{g.grantee}</th>
                      <td className="px-3 py-4 whitespace-nowrap text-neutral-700">{g.program || <span aria-label="Not listed">—</span>}</td>
                      <td className="px-3 py-4 text-right font-semibold whitespace-nowrap text-neutral-950 tabular-nums">
                        {amounts[i] !== null ? usd.format(amounts[i] as number) : g.amount || <span aria-label="Not disclosed">—</span>}
                      </td>
                      <td className="px-3 py-4 whitespace-nowrap text-neutral-700 tabular-nums">{g.year}</td>
                      <td className="min-w-64 py-4 pr-4 pl-3 leading-6 text-pretty text-neutral-600 sm:pr-6">{g.purpose}</td>
                    </tr>
                  ))}
                </tbody>
                {showTotal !== false && counted.length ? (
                  <tfoot>
                    <tr className="border-t-2 border-neutral-950 bg-neutral-50">
                      <th scope="row" colSpan={2} className="py-4 pr-3 pl-4 font-semibold text-neutral-950 sm:pl-6">
                        Total
                        <span className="ml-2 font-normal text-neutral-600">
                          {counted.length} {counted.length === 1 ? "grant" : "grants"}
                          {counted.length < rows.length ? ` with disclosed amounts, of ${rows.length}` : ""}
                        </span>
                      </th>
                      <td className="px-3 py-4 text-right text-base font-semibold whitespace-nowrap text-neutral-950 tabular-nums">{usd.format(total)}</td>
                      <td colSpan={2} />
                    </tr>
                  </tfoot>
                ) : null}
              </table>
            </div>
          ) : null}

          {source ? <p className="mt-4 text-sm leading-6 text-pretty text-neutral-600">{source}</p> : null}
        </div>
      </section>
    );
  },
};
```
