# Add the "Public Health Data" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/public-health-data) to this Pantheon Content Publisher (P1) Next.js project. Three or four health indicators with county-vs-state bars, comparison and trend notes, and a source line.

## Steps

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

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

/**
 * Public Health Data — a snapshot of 3–4 community health indicators, each with the county
 * value, a county-vs-state bar pair, a comparison line and a trend note, plus a source line
 * and a link to the full data portal. Values are text so P1 data-source tokens can bind.
 * Register: `PublicHealthDataBlock: publicHealthDataBlock` in puck.config.tsx.
 */

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

export type PublicHealthDataProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  areaLabel: string;
  compareLabel: string;
  indicators: {
    label: string;
    county: string;
    state: string;
    unit: string;
    max: string;
    comparison: string;
    trend: string;
  }[];
  source: string;
  portalLabel: string;
  portalHref: string;
};

const childLevel = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" } as const;
const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";

const num = (v: string) => {
  const cleaned = (v || "").replace(/[^\d.-]/g, "");
  if (!cleaned) return null;
  const n = Number(cleaned);
  return Number.isFinite(n) ? n : null;
};
const fmt = (n: number | null, unit: string) => (n === null ? "—" : `${n.toLocaleString("en-US")}${unit || ""}`);
const pct = (n: number | null, max: number) => (n === null || max <= 0 ? 0 : Math.max(0, Math.min(100, (n / max) * 100)));

export const publicHealthDataBlock: ComponentConfig<PublicHealthDataProps> = {
  label: "Public Health Data",
  fields: {
    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. Indicator names use the next level down." },
    },
    intro: { type: "textarea", label: "Intro" },
    areaLabel: { type: "text", label: "Your area label", metadata: { help: "Like Lakeshore County. Names the dark bar." } },
    compareLabel: { type: "text", label: "Comparison label", metadata: { help: "Like Michigan or State average. Names the light bar." } },
    indicators: {
      type: "array",
      label: "Indicators",
      min: 1,
      max: 4,
      getItemSummary: (item) => item?.label || "Indicator",
      defaultItemProps: { label: "New indicator", county: "", state: "", unit: "%", max: "100", comparison: "", trend: "" },
      arrayFields: {
        label: { type: "text", label: "Name" },
        county: { type: "text", label: "Your area value", metadata: { help: "A number, like 71.4. Can be a data-source token." } },
        state: { type: "text", label: "Comparison value", metadata: { help: "A number. Leave blank to hide the comparison bar." } },
        unit: { type: "text", label: "Unit", metadata: { help: "Added after each value, like %. Leave blank for none." } },
        max: { type: "text", label: "Bar scale maximum", metadata: { help: "The value that fills a whole bar. Use 100 for percentages." } },
        comparison: { type: "text", label: "Comparison text", metadata: { help: "Say what the gap means in plain words, like 3 points higher than the state." } },
        trend: { type: "text", label: "Trend note", metadata: { help: "Like Up from 68.2% in 2024. Leave blank to hide." } },
      },
    },
    source: { type: "textarea", label: "Source line", metadata: { help: "Name the data source and year. Required for any statistic." } },
    portalLabel: { type: "text", label: "Data portal link text", metadata: { help: "Leave blank to hide." } },
    portalHref: { type: "text", label: "Data portal link" },
  },
  defaultProps: {
    heading: "Community health at a glance",
    headingLevel: "h2",
    intro: "A quick look at how Lakeshore County compares to the state on a few key measures. We update these numbers each year.",
    areaLabel: "Lakeshore County",
    compareLabel: "State",
    indicators: [
      { label: "Adults with a flu shot", county: "48.6", state: "44.1", unit: "%", max: "100", comparison: "4.5 points higher than the state", trend: "Up from 45.2% the year before" },
      { label: "People without health insurance", county: "7.9", state: "5.8", unit: "%", max: "20", comparison: "2.1 points higher than the state", trend: "Down from 8.6% the year before" },
      { label: "Kindergartners with all required shots", county: "89.3", state: "91.0", unit: "%", max: "100", comparison: "1.7 points lower than the state", trend: "About the same as last year" },
      { label: "Adults with a usual doctor or clinic", county: "78.2", state: "81.5", unit: "%", max: "100", comparison: "3.3 points lower than the state", trend: "Up from 76.9% the year before" },
    ],
    source: "Sample figures for illustration only, not real data. Replace with your own and name each source and year, such as your state's BRFSS survey or the Census Bureau's American Community Survey.",
    portalLabel: "Explore the full data portal",
    portalHref: "/data",
  },
  render: ({ id, heading, headingLevel, intro, areaLabel, compareLabel, indicators, source, portalLabel, portalHref }) => {
    const H = headingLevel || "h2";
    const Sub = childLevel[H] ?? "h3";
    const list = (indicators ?? []).filter((x) => x?.label);
    const area = areaLabel || "Our area";
    const compare = compareLabel || "Comparison";
    const cols = list.length >= 4 ? "md:grid-cols-2 xl:grid-cols-4" : list.length === 3 ? "md:grid-cols-3" : list.length === 2 ? "md:grid-cols-2" : "";
    const base = `phd-${id || "block"}`;

    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="flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between">
            {heading || intro ? (
              <div className="max-w-2xl">
                {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}
              </div>
            ) : null}
            <ul role="list" aria-label="Chart key" className="flex flex-wrap gap-x-6 gap-y-2 text-sm text-neutral-700">
              <li className="flex items-center gap-2">
                <span aria-hidden="true" className="h-2.5 w-6 rounded-full bg-indigo-600" />
                {area}
              </li>
              <li className="flex items-center gap-2">
                <span aria-hidden="true" className="h-2.5 w-6 rounded-full bg-neutral-300" />
                {compare}
              </li>
            </ul>
          </div>

          {list.length ? (
            <ul role="list" className={`mt-10 grid grid-cols-1 gap-px overflow-hidden rounded-2xl bg-neutral-200 ring-1 ring-neutral-200 sm:mt-12 ${cols}`}>
              {list.map((x, i) => {
                const c = num(x.county);
                const s = num(x.state);
                const max = num(x.max) ?? 100;
                const nameId = `${base}-${i}`;
                return (
                  <li key={`${x.label}-${i}`} className="flex flex-col bg-white p-6 sm:p-7">
                    <article aria-labelledby={nameId} className="flex h-full flex-col">
                      <Sub id={nameId} className="text-base leading-6 font-semibold text-balance text-neutral-950">
                        {x.label}
                      </Sub>
                      <p aria-hidden="true" className="mt-4 flex items-baseline gap-2">
                        <span className="text-5xl font-semibold tracking-tight text-neutral-950 tabular-nums">{fmt(c, x.unit)}</span>
                        <span className="text-sm text-neutral-600">{area}</span>
                      </p>

                      <ul role="list" className="mt-6 space-y-3">
                        <li>
                          <p className="flex items-baseline justify-between gap-3 text-sm">
                            <span className="text-neutral-700">{area}<span className="sr-only">:</span></span>
                            <span className="font-semibold text-neutral-950 tabular-nums">{fmt(c, x.unit)}</span>
                          </p>
                          <div aria-hidden="true" className="mt-1.5 h-2.5 overflow-hidden rounded-full bg-neutral-100">
                            <div className="h-full rounded-full bg-indigo-600" style={{ width: `${pct(c, max)}%` }} />
                          </div>
                        </li>
                        {s !== null ? (
                          <li>
                            <p className="flex items-baseline justify-between gap-3 text-sm">
                              <span className="text-neutral-700">{compare}<span className="sr-only">:</span></span>
                              <span className="font-semibold text-neutral-950 tabular-nums">{fmt(s, x.unit)}</span>
                            </p>
                            <div aria-hidden="true" className="mt-1.5 h-2.5 overflow-hidden rounded-full bg-neutral-100">
                              <div className="h-full rounded-full bg-neutral-300" style={{ width: `${pct(s, max)}%` }} />
                            </div>
                          </li>
                        ) : null}
                      </ul>

                      {x.comparison || x.trend ? (
                        <div className="mt-auto space-y-1 pt-6 text-sm leading-6">
                          {x.comparison ? <p className="font-medium text-pretty text-neutral-950">{x.comparison}</p> : null}
                          {x.trend ? <p className="text-pretty text-neutral-600">{x.trend}</p> : null}
                        </div>
                      ) : null}
                    </article>
                  </li>
                );
              })}
            </ul>
          ) : null}

          {source || portalLabel ? (
            <div className="mt-8 flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between sm:gap-10">
              {source ? (
                <p className="max-w-3xl text-xs leading-5 text-pretty text-neutral-600">
                  <span className="font-semibold text-neutral-800">Source: </span>
                  {source}
                </p>
              ) : null}
              {portalLabel ? (
                <a href={portalHref || "#"} className={`group -mt-2.5 inline-flex min-h-11 shrink-0 items-center gap-2 rounded-lg text-sm font-semibold text-indigo-700 hover:text-indigo-900 ${focusRing}`}>
                  {portalLabel}
                  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 transition motion-safe: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}
            </div>
          ) : null}
        </div>
      </section>
    );
  },
};
```
