# Add the "Financial Transparency" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/financial-transparency) to this Pantheon Content Publisher (P1) Next.js project. An accessible stacked bar of how funds are spent, plus links to the Form 990, audit and annual report.

## Steps

1. Create `components/puck/financial-transparency-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 { financialTransparencyBlock } from "./components/puck/financial-transparency-block";`
3. Register it under `components` as `FinancialTransparencyBlock: financialTransparencyBlock`.
4. Add `"FinancialTransparencyBlock"` 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/financial-transparency-block.tsx`

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

/**
 * Financial Transparency — where the money goes, as an accessible stacked bar with a
 * text legend, plus links to your Form 990, audit and annual report.
 * Register: `FinancialTransparencyBlock: financialTransparencyBlock` in puck.config.tsx.
 */

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

export type FinancialTransparencyProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  chartLabel: string;
  allocations: { label: string; percent: number; description: string }[];
  source: string;
  seal: string;
  documentsLabel: string;
  documents: { label: string; href: string }[];
};

const childHeading: Record<Heading, "h2" | "h3" | "h4" | "h5"> = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" };

// Each swatch pairs a shade with a texture so segments stay distinguishable without color.
const stripes = "repeating-linear-gradient(135deg, rgb(255 255 255 / 0.35) 0 2px, transparent 2px 7px)";
const dots = "radial-gradient(rgb(255 255 255 / 0.45) 1px, transparent 1.5px)";
const swatches: { className: string; image?: string; size?: string }[] = [
  { className: "bg-indigo-700" },
  { className: "bg-indigo-500", image: stripes },
  { className: "bg-neutral-700", image: dots, size: "6px 6px" },
  { className: "bg-neutral-500" },
  { className: "bg-indigo-950", image: stripes },
  { className: "bg-neutral-900", image: dots, size: "6px 6px" },
];
const swatchStyle = (i: number) => {
  const s = swatches[i % swatches.length];
  return s.image ? { backgroundImage: s.image, backgroundSize: s.size } : undefined;
};

const formatPercent = (n: number) => `${Math.round(n * 10) / 10}%`;

export const financialTransparencyBlock: ComponentConfig<FinancialTransparencyProps> = {
  label: "Financial Transparency",
  fields: {
    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." },
    },
    intro: { type: "textarea", label: "Intro" },
    chartLabel: { type: "text", label: "Chart title", metadata: { help: "Like How each dollar was spent in 2025. Also read aloud to screen reader users." } },
    allocations: {
      type: "array",
      label: "Spending categories",
      min: 1,
      max: 6,
      getItemSummary: (item) => (item?.label ? `${item.label} · ${Number(item.percent) || 0}%` : "Category"),
      defaultItemProps: { label: "New category", percent: 10, description: "" },
      arrayFields: {
        label: { type: "text", label: "Category" },
        percent: { type: "number", label: "Percent", min: 0, max: 100, metadata: { help: "Number only. All categories should add up to 100." } },
        description: { type: "textarea", label: "Description", metadata: { help: "Optional. What this spending covers." } },
      },
      metadata: { help: "List the largest category first. If the total isn't 100, the bar is scaled to fit and a note appears while editing." },
    },
    source: { type: "text", label: "Source line", metadata: { help: "Where the figures come from, like FY2025 audited financial statements." } },
    seal: { type: "text", label: "Rating or seal", metadata: { help: "An independent rating or accreditation. Leave blank to hide it." } },
    documentsLabel: { type: "text", label: "Documents heading" },
    documents: {
      type: "array",
      label: "Documents",
      min: 0,
      max: 8,
      getItemSummary: (item) => item?.label || "Document",
      defaultItemProps: { label: "Annual report", href: "/files/annual-report.pdf" },
      arrayFields: {
        label: { type: "text", label: "Label", metadata: { help: "Include the year, like IRS Form 990 (2025)." } },
        href: { type: "text", label: "Link", metadata: { help: "A PDF in your media library or a full URL." } },
      },
    },
  },
  defaultProps: {
    heading: "Where your dollar goes",
    headingLevel: "h2",
    intro: "We publish our numbers because you deserve to see them. Most of every gift goes straight into tutoring, books and family literacy nights.",
    chartLabel: "How we spent each dollar in fiscal year 2025",
    allocations: [
      { label: "Programs", percent: 81, description: "Tutors, reading specialists, books and classroom supplies for 1,400 students." },
      { label: "Community partnerships", percent: 6, description: "Grants and training for school libraries and partner after-school sites." },
      { label: "Fundraising", percent: 8, description: "Donor communications, events and the systems that process your gifts." },
      { label: "Administration", percent: 5, description: "Finance, HR, insurance and our annual independent audit." },
    ],
    source: "Sample figures. Source: Cedar Hollow Literacy Project FY2025 audited financial statements.",
    seal: "Rated 4 out of 4 stars by an independent charity evaluator",
    documentsLabel: "Financial documents",
    documents: [
      { label: "IRS Form 990 (2025)", href: "/files/form-990-2025.pdf" },
      { label: "Audited financial statements (FY2025)", href: "/files/audit-fy2025.pdf" },
      { label: "Annual report 2025", href: "/files/annual-report-2025.pdf" },
    ],
  },
  render: ({ heading, headingLevel, intro, chartLabel, allocations, source, seal, documentsLabel, documents, puck }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[H] ?? "h3";
    const rows = (allocations ?? [])
      .filter((a) => a?.label)
      .map((a) => ({ ...a, value: Math.max(0, Number(a.percent) || 0) }));
    const total = rows.reduce((sum, r) => sum + r.value, 0);
    const offBy = total > 0 && Math.abs(total - 100) > 0.5;
    const summary = `${chartLabel ? `${chartLabel}: ` : ""}${rows.map((r) => `${r.label} ${formatPercent(r.value)}`).join(", ")}.`;
    const docs = (documents ?? []).filter((d) => d?.label);

    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 grid max-w-7xl grid-cols-1 gap-12 lg:grid-cols-12 lg:gap-16">
          <div className="lg:col-span-4">
            {heading ? <H className="text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl">{heading}</H> : null}
            {intro ? <p className="mt-4 text-lg leading-8 text-pretty text-neutral-600">{intro}</p> : null}
            {seal ? (
              <p className="mt-8 flex items-start gap-3 rounded-xl bg-indigo-50 p-4 text-sm leading-6 font-medium text-indigo-950 ring-1 ring-indigo-600/15 ring-inset">
                <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" className="size-6 shrink-0 text-indigo-700">
                  <path d="M9 12.75 11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 0 1-1.043 3.296 3.745 3.745 0 0 1-3.296 1.043A3.745 3.745 0 0 1 12 21c-1.268 0-2.39-.63-3.068-1.593a3.746 3.746 0 0 1-3.296-1.043 3.746 3.746 0 0 1-1.043-3.296A3.745 3.745 0 0 1 3 12c0-1.268.63-2.39 1.593-3.068a3.745 3.745 0 0 1 1.043-3.296 3.746 3.746 0 0 1 3.296-1.043A3.746 3.746 0 0 1 12 3c1.268 0 2.39.63 3.068 1.593a3.746 3.746 0 0 1 3.296 1.043 3.746 3.746 0 0 1 1.043 3.296A3.745 3.745 0 0 1 21 12Z" />
                </svg>
                <span>{seal}</span>
              </p>
            ) : null}
          </div>

          <div className="lg:col-span-8">
            {rows.length ? (
              <figure>
                {chartLabel ? <figcaption className="text-sm font-semibold text-neutral-950">{chartLabel}</figcaption> : null}
                {puck?.isEditing && offBy ? (
                  <p className="mt-3 rounded-lg bg-indigo-50 px-4 py-3 text-sm text-indigo-950 ring-1 ring-indigo-600/20 ring-inset">
                    Editor note: these categories add up to {formatPercent(total)}, not 100%. The bar is scaled to fit, but readers will see the numbers as entered. Only editors see this note.
                  </p>
                ) : null}
                <div role="img" aria-label={summary} className={`flex h-12 w-full gap-1 overflow-hidden rounded-lg sm:h-16 ${chartLabel ? "mt-4" : ""}`}>
                  {total > 0
                    ? rows.map((r, i) =>
                        r.value > 0 ? (
                          <div
                            key={`${r.label}-${i}`}
                            className={`h-full min-w-1 ${swatches[i % swatches.length].className}`}
                            style={{ width: `${(r.value / total) * 100}%`, ...swatchStyle(i) }}
                          />
                        ) : null,
                      )
                    : <div className="h-full w-full bg-neutral-200" />}
                </div>

                <ol role="list" className="mt-8 divide-y divide-neutral-200 border-y border-neutral-200">
                  {rows.map((r, i) => (
                    <li key={`${r.label}-${i}`} className="flex items-start gap-4 py-5">
                      <span aria-hidden="true" className={`mt-1 size-4 rounded ${swatches[i % swatches.length].className}`} style={swatchStyle(i)} />
                      <div className="min-w-0 flex-1">
                        <Sub className="text-base font-semibold text-neutral-950">{r.label}</Sub>
                        {r.description ? <p className="mt-1 text-sm leading-6 text-pretty text-neutral-600">{r.description}</p> : null}
                      </div>
                      <p className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums sm:text-3xl">{formatPercent(r.value)}</p>
                    </li>
                  ))}
                </ol>
                {source ? <p className="mt-4 text-sm text-neutral-600">{source}</p> : null}
              </figure>
            ) : null}

            {docs.length ? (
              <div className="mt-12">
                {documentsLabel ? <Sub className="text-sm font-semibold tracking-wide text-neutral-950 uppercase">{documentsLabel}</Sub> : null}
                <ul role="list" className={`grid gap-3 sm:grid-cols-2 ${documentsLabel ? "mt-4" : ""}`}>
                  {docs.map((d, i) => (
                    <li key={`${d.label}-${i}`}>
                      <a
                        href={d.href || "#"}
                        className="group flex min-h-14 items-center gap-3 rounded-xl px-4 py-3 text-sm font-semibold text-neutral-950 ring-1 ring-neutral-200 transition ring-inset hover:bg-indigo-50 hover:text-indigo-700 hover:ring-indigo-300 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                      >
                        <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" strokeLinejoin="round" className="size-6 shrink-0 text-indigo-700">
                          <path d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m.75 12 3 3m0 0 3-3m-3 3v-6m-1.5-9H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
                        </svg>
                        <span className="flex-1">{d.label}</span>
                      </a>
                    </li>
                  ))}
                </ul>
              </div>
            ) : null}
          </div>
        </div>
      </section>
    );
  },
};
```
