# Add the "Radial Progress" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/radial-progress) to this Pantheon Content Publisher (P1) Next.js project. One to four ring gauges side by side, each showing progress toward its target.

## Steps

1. Create `components/puck/radial-progress-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 { radialProgressBlock } from "./components/puck/radial-progress-block";`
3. Register it under `components` as `RadialProgressBlock: radialProgressBlock`.
4. Add `"RadialProgressBlock"` to the best-fitting entry in `categories` (this block's library category is "Dashboards"). Create a category only if none fits.
5. Dashboard widgets are designed to sit inside the Dashboard Grid block (https://p1-blocks.prolificdigital.io/r/dashboard-grid.md). If the project doesn't have it yet, offer to add it too.
6. Run the project's type check (usually `pnpm typecheck`) and resolve anything project-specific.
7. 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-`.
- Data values are text fields on purpose: P1 data-source tokens (`{{ source.field }}`) only bind in text fields. Don't convert them to number fields.
- Don't change prop names in `defaultProps`. Content editors' saved pages depend on them.

## File: `components/puck/radial-progress-block.tsx`

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

/**
 * Radial Progress — one to four ring gauges side by side, each showing a value against its
 * target with the percentage in the center. Every value is a text field, bindable to a P1
 * data source. Place inside a Dashboard Grid.
 * Register: `RadialProgressBlock: radialProgressBlock` in puck.config.tsx.
 */

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

type Ring = { label: string; value: string; target: string; prefix: string; suffix: string };

export type RadialProgressProps = {
  title: string;
  headingLevel: Heading;
  subtitle: string;
  rings: Ring[];
  footnote: string;
};

/** "1,234.5", "$12k" or "-3.2%" → number; anything unparseable → null. */
function toNumber(raw: string | undefined): number | null {
  if (raw == null) return null;
  const cleaned = String(raw).replace(/[^0-9.\-]/g, "");
  if (cleaned === "" || cleaned === "-" || cleaned === ".") return null;
  const n = Number(cleaned);
  return Number.isFinite(n) ? n : null;
}

const compact = new Intl.NumberFormat("en-US", { notation: "compact", maximumFractionDigits: 1 });
const full = new Intl.NumberFormat("en-US", { maximumFractionDigits: 2 });

function format(n: number | null, prefix = "", suffix = "", short = false) {
  if (n === null) return "—";
  const unit = suffix && /^[a-z]/i.test(suffix) && suffix.length > 1 ? ` ${suffix}` : suffix;
  return `${n < 0 ? "−" : ""}${prefix}${(short ? compact : full).format(Math.abs(n))}${unit}`;
}

const R = 42;
const C = 2 * Math.PI * R;

const GRID: Record<number, string> = {
  1: "grid-cols-1",
  2: "grid-cols-1 @3xs:grid-cols-2",
  3: "grid-cols-1 @xs:grid-cols-3",
  4: "grid-cols-1 @3xs:grid-cols-2 @2xl:grid-cols-4",
};

export const radialProgressBlock: ComponentConfig<RadialProgressProps> = {
  label: "Radial Progress",
  fields: {
    title: { type: "text", label: "Title" },
    headingLevel: {
      type: "select",
      label: "Heading level",
      options: [
        { label: "H2", value: "h2" },
        { label: "H3 (recommended inside a dashboard)", value: "h3" },
        { label: "H4", value: "h4" },
        { label: "Not a heading", value: "p" },
      ],
      metadata: { help: "Sets the page outline for screen readers and search. The look doesn't change." },
    },
    subtitle: { type: "text", label: "Subtitle or period", metadata: { help: "e.g. As of Oct 6, 2026. Leave blank to hide." } },
    rings: {
      type: "array",
      label: "Rings",
      min: 1,
      max: 4,
      getItemSummary: (item) => item?.label || "Ring",
      defaultItemProps: { label: "New goal", value: "", target: "", prefix: "", suffix: "" },
      arrayFields: {
        label: { type: "text", label: "Label" },
        value: { type: "text", label: "Current value", metadata: { help: "A number. Or bind it, e.g. {{ campaign.raised }}." } },
        target: { type: "text", label: "Target", metadata: { help: "The goal. The ring fills to value ÷ target." } },
        prefix: { type: "text", label: "Prefix", metadata: { help: "e.g. $." } },
        suffix: { type: "text", label: "Suffix", metadata: { help: "e.g. k or donors." } },
      },
    },
    footnote: { type: "text", label: "Footnote", metadata: { help: "Where the data comes from. Leave blank to hide." } },
  },
  defaultProps: {
    title: "Year-end campaign",
    headingLevel: "h3",
    subtitle: "As of Oct 6, 2026 · Campaign closes Dec 31",
    rings: [
      { label: "Dollars raised", value: "412,600", target: "500,000", prefix: "$", suffix: "" },
      { label: "New donors", value: "1,284", target: "1,500", prefix: "", suffix: "" },
      { label: "Monthly sustainers", value: "318", target: "300", prefix: "", suffix: "" },
      { label: "Matching gifts", value: "41", target: "80", prefix: "", suffix: "" },
    ],
    footnote: "Sample data · Source: donor CRM campaign report",
  },
  render: ({ title, headingLevel, subtitle, rings, footnote }) => {
    const H = headingLevel || "h3";
    const items = (Array.isArray(rings) ? rings : []).slice(0, 4).map((r, i) => {
      const value = toNumber(r?.value);
      const target = toNumber(r?.target);
      const ratio = value !== null && target !== null && target > 0 ? value / target : null;
      return {
        key: `r${i}`,
        label: r?.label?.trim() || `Goal ${i + 1}`,
        prefix: r?.prefix?.trim() || "",
        suffix: r?.suffix?.trim() || "",
        value,
        target,
        ratio,
      };
    });
    const hasData = items.some((r) => r.value !== null);

    const header = (
      <div>
        {title ? <H className="text-sm font-semibold text-neutral-950">{title}</H> : null}
        {subtitle ? <p className="mt-0.5 text-sm text-neutral-500">{subtitle}</p> : null}
      </div>
    );
    const foot = footnote ? <p className="mt-auto pt-4 text-xs text-neutral-500">{footnote}</p> : null;
    const card =
      "@container flex h-full flex-col rounded-xl bg-white p-5 shadow-xs ring-1 ring-neutral-950/5 sm:p-6 not-in-data-[dashboard-grid]:mx-4 not-in-data-[dashboard-grid]:my-8 sm:not-in-data-[dashboard-grid]:mx-auto sm:not-in-data-[dashboard-grid]:max-w-2xl";

    if (!hasData) {
      return (
        <div className={card}>
          {header}
          <div className="mt-4 flex flex-1 flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-neutral-200 px-4 py-10 text-center">
            <svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" className="size-6 text-neutral-400">
              <circle cx="12" cy="12" r="8" />
              <path d="M12 4a8 8 0 0 1 8 8" strokeLinecap="round" strokeWidth="2.5" />
            </svg>
            <p className="text-sm font-medium text-neutral-900">No data yet</p>
            <p className="text-xs text-neutral-500">Rings appear once values are entered or the data source returns them.</p>
          </div>
          {foot}
        </div>
      );
    }

    return (
      <div className={card}>
        {header}
        <ul className={`mt-6 grid flex-1 content-center gap-x-4 gap-y-8 ${GRID[items.length] ?? GRID[4]}`}>
          {items.map((r) => {
            const pct = r.ratio === null ? null : Math.round(r.ratio * 100);
            const fill = r.ratio === null ? 0 : Math.max(0, Math.min(1, r.ratio));
            const met = r.ratio !== null && r.ratio >= 1;
            const amount = `${format(r.value, r.prefix, r.suffix)}${r.target !== null ? ` of ${format(r.target, r.prefix, r.suffix)}` : ""}`;
            return (
              <li key={r.key} className="flex min-w-0 flex-col items-center text-center">
                <div
                  role="img"
                  aria-label={`${r.label}: ${pct === null ? "no target set" : `${pct}% of target`}, ${amount}${met ? ", goal met" : ""}.`}
                  className={`relative aspect-square w-full ${items.length === 1 ? "max-w-44" : "max-w-32 @2xl:max-w-36"}`}
                >
                  <svg viewBox="0 0 100 100" aria-hidden="true" className="size-full">
                    <circle cx="50" cy="50" r={R} fill="none" className="stroke-neutral-100" strokeWidth="8" />
                    {fill > 0 ? (
                      <circle
                        cx="50"
                        cy="50"
                        r={R}
                        fill="none"
                        className={met ? "stroke-indigo-700" : "stroke-indigo-600"}
                        strokeWidth="8"
                        strokeLinecap={fill < 1 ? "round" : "butt"}
                        strokeDasharray={`${(C * fill).toFixed(2)} ${C.toFixed(2)}`}
                        transform="rotate(-90 50 50)"
                      />
                    ) : null}
                  </svg>
                  <div aria-hidden="true" className="absolute inset-0 flex flex-col items-center justify-center">
                    <span className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums @2xl:text-3xl">
                      {pct === null ? "—" : pct}
                      {pct !== null ? <span className="text-sm font-medium text-neutral-500">%</span> : null}
                    </span>
                    {met ? (
                      <span className="mt-0.5 inline-flex items-center gap-0.5 text-xs font-medium text-indigo-700">
                        <svg viewBox="0 0 16 16" fill="currentColor" className="size-3">
                          <path fillRule="evenodd" d="M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z" clipRule="evenodd" />
                        </svg>
                        Goal met
                      </span>
                    ) : (
                      <span className="mt-0.5 text-xs text-neutral-500">of target</span>
                    )}
                  </div>
                </div>
                <p className="mt-3 text-sm font-medium text-pretty text-neutral-900">{r.label}</p>
                <p className="mt-0.5 text-xs text-neutral-500 tabular-nums">{amount}</p>
              </li>
            );
          })}
        </ul>
        {foot}
      </div>
    );
  },
};
```
