# Add the "Milestone Tracker" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/milestone-tracker) to this Pantheon Content Publisher (P1) Next.js project. Project milestones with due dates, written status labels and an overall percent-complete bar.

## Steps

1. Create `components/puck/milestone-tracker-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 { milestoneTrackerBlock } from "./components/puck/milestone-tracker-block";`
3. Register it under `components` as `MilestoneTrackerBlock: milestoneTrackerBlock`.
4. Add `"MilestoneTrackerBlock"` 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/milestone-tracker-block.tsx`

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

/**
 * Milestone Tracker — a project's milestones with due dates and status (done, in progress,
 * upcoming, late), plus an overall percent-complete bar. Status is always spelled out; color
 * is an opt-in extra. Every value is a text field, bindable to a P1 data source.
 * Place inside a Dashboard Grid.
 * Register: `MilestoneTrackerBlock: milestoneTrackerBlock` in puck.config.tsx.
 */
// spec: status-colors

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

type Status = "done" | "in-progress" | "upcoming" | "late";

type Milestone = { name: string; due: string; status: Status; note: string };

export type MilestoneTrackerProps = {
  title: string;
  headingLevel: Heading;
  subtitle: string;
  milestones: Milestone[];
  progress: string;
  statusColors: "yes" | "no";
  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;
}

/** Bound data may say "In Progress", "in_progress", "complete"… */
function toStatus(raw: unknown): Status {
  const s = String(raw ?? "")
    .toLowerCase()
    .replace(/[^a-z]/g, "");
  if (["done", "complete", "completed", "finished"].includes(s)) return "done";
  if (["inprogress", "active", "started", "underway"].includes(s)) return "in-progress";
  if (["late", "overdue", "delayed", "blocked", "atrisk"].includes(s)) return "late";
  return "upcoming";
}

const LABEL: Record<Status, string> = { done: "Done", "in-progress": "In progress", upcoming: "Upcoming", late: "Late" };

const TONE: Record<"color" | "plain", Record<Status, { icon: string; badge: string }>> = {
  color: {
    done: { icon: "text-emerald-600", badge: "bg-emerald-50 text-emerald-800 ring-emerald-600/20" },
    "in-progress": { icon: "text-indigo-600", badge: "bg-indigo-50 text-indigo-800 ring-indigo-600/20" },
    upcoming: { icon: "text-neutral-400", badge: "bg-neutral-50 text-neutral-700 ring-neutral-500/20" },
    late: { icon: "text-red-600", badge: "bg-red-50 text-red-800 ring-red-600/20" },
  },
  plain: {
    done: { icon: "text-indigo-600", badge: "bg-neutral-50 text-neutral-700 ring-neutral-500/20" },
    "in-progress": { icon: "text-indigo-600", badge: "bg-indigo-50 text-indigo-800 ring-indigo-600/20" },
    upcoming: { icon: "text-neutral-400", badge: "bg-neutral-50 text-neutral-700 ring-neutral-500/20" },
    late: { icon: "text-neutral-950", badge: "bg-neutral-900 text-white ring-neutral-900" },
  },
};

function StatusIcon({ status }: { status: Status }) {
  if (status === "done")
    return (
      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
        <path
          fillRule="evenodd"
          d="M10 18a8 8 0 1 0 0-16 8 8 0 0 0 0 16Zm3.857-9.809a.75.75 0 0 0-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 1 0-1.06 1.061l2.5 2.5a.75.75 0 0 0 1.137-.089l4-5.5Z"
          clipRule="evenodd"
        />
      </svg>
    );
  if (status === "late")
    return (
      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5">
        <path
          fillRule="evenodd"
          d="M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0Zm-8-5a.75.75 0 0 1 .75.75v4.5a.75.75 0 0 1-1.5 0v-4.5A.75.75 0 0 1 10 5Zm0 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z"
          clipRule="evenodd"
        />
      </svg>
    );
  return (
    <svg aria-hidden="true" viewBox="0 0 20 20" className="size-5">
      <circle cx="10" cy="10" r="6.75" className="fill-white" stroke="currentColor" strokeWidth="1.5" />
      {status === "in-progress" ? <path d="M10 5.5a4.5 4.5 0 0 1 0 9Z" fill="currentColor" /> : null}
    </svg>
  );
}

export const milestoneTrackerBlock: ComponentConfig<MilestoneTrackerProps> = {
  label: "Milestone Tracker",
  fields: {
    title: { type: "text", label: "Project name" },
    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", metadata: { help: "e.g. Phase 2 · Updated Oct 6, 2026. Leave blank to hide." } },
    milestones: {
      type: "array",
      label: "Milestones",
      min: 1,
      max: 16,
      getItemSummary: (item) => (item?.name ? `${item.name} · ${LABEL[toStatus(item.status)]}` : "Milestone"),
      defaultItemProps: { name: "New milestone", due: "", status: "upcoming", note: "" },
      arrayFields: {
        name: { type: "text", label: "Milestone" },
        due: { type: "text", label: "Due date", metadata: { help: "Shown as written, e.g. Nov 15 or 2026-11-15." } },
        status: {
          type: "select",
          label: "Status",
          options: [
            { label: "Done", value: "done" },
            { label: "In progress", value: "in-progress" },
            { label: "Upcoming", value: "upcoming" },
            { label: "Late", value: "late" },
          ],
          metadata: { help: "Bound values like complete, active or overdue are understood too." },
        },
        note: { type: "text", label: "Note (optional)", metadata: { help: "One short line, e.g. Waiting on utility inspection." } },
      },
    },
    progress: {
      type: "text",
      label: "Overall % complete",
      metadata: { help: "Leave blank to count finished milestones. Or type or bind a percent, e.g. {{ project.percent_complete }}." },
    },
    statusColors: {
      type: "radio",
      label: "Status colors",
      options: [
        { label: "Green / amber / red", value: "yes" },
        { label: "Brand only", value: "no" },
      ],
      metadata: { help: "Status is always written out, so either choice is accessible." },
    },
    footnote: { type: "text", label: "Footnote", metadata: { help: "Where the data comes from. Leave blank to hide." } },
  },
  defaultProps: {
    title: "Riverside Park renovation",
    headingLevel: "h3",
    subtitle: "Phase 2 · Updated Oct 6, 2026",
    milestones: [
      { name: "Community input sessions", due: "Mar 14", status: "done", note: "" },
      { name: "Design approved by park board", due: "May 2", status: "done", note: "" },
      { name: "Construction permits issued", due: "Jun 20", status: "done", note: "" },
      { name: "Old playground removed", due: "Aug 8", status: "done", note: "" },
      { name: "Splash pad utility hookup", due: "Sep 30", status: "late", note: "Waiting on water department inspection" },
      { name: "Accessible loop path poured", due: "Oct 24", status: "in-progress", note: "" },
      { name: "Planting and landscaping", due: "Nov 15", status: "upcoming", note: "" },
      { name: "Public reopening", due: "Dec 6", status: "upcoming", note: "" },
    ],
    progress: "",
    statusColors: "yes",
    footnote: "Sample data · Source: Parks & Recreation capital projects office",
  },
  render: ({ id, title, headingLevel, subtitle, milestones, progress, statusColors, footnote }) => {
    const H = headingLevel || "h3";
    const uid = String(id ?? "milestones").replace(/[^a-zA-Z0-9_-]/g, "");
    const items = (Array.isArray(milestones) ? milestones : [])
      .map((m, i) => ({ key: `m${i}`, name: m?.name?.trim() || "", due: m?.due?.trim() || "", status: toStatus(m?.status), note: m?.note?.trim() || "" }))
      .filter((m) => m.name);
    const tones = TONE[statusColors === "no" ? "plain" : "color"];

    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 (!items.length) {
      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">
              <path d="M5 21V4m0 0h11l-2 4 2 4H5" strokeLinecap="round" strokeLinejoin="round" />
            </svg>
            <p className="text-sm font-medium text-neutral-900">No data yet</p>
            <p className="text-xs text-neutral-500">Milestones appear once they're entered or the data source returns them.</p>
          </div>
          {foot}
        </div>
      );
    }

    const counts = (["done", "in-progress", "late", "upcoming"] as Status[]).map((s) => ({ s, n: items.filter((m) => m.status === s).length })).filter((c) => c.n);
    const done = items.filter((m) => m.status === "done").length;
    const override = toNumber(progress);
    const pct = Math.round(Math.max(0, Math.min(100, override ?? (done / items.length) * 100)));

    return (
      <div className={card}>
        {header}

        <div className="mt-4">
          <div className="flex items-baseline justify-between gap-3">
            <p id={`${uid}-progress`} className="text-sm text-neutral-600">
              <span className="font-medium text-neutral-900 tabular-nums">
                {done} of {items.length}
              </span>{" "}
              milestones done
            </p>
            <p className="text-2xl font-semibold tracking-tight text-neutral-950 tabular-nums">
              {pct}
              <span className="text-base font-medium text-neutral-500">%</span>
            </p>
          </div>
          <div
            role="progressbar"
            aria-labelledby={`${uid}-progress`}
            aria-valuemin={0}
            aria-valuemax={100}
            aria-valuenow={pct}
            aria-valuetext={`${pct}% complete`}
            className="mt-2 h-2 overflow-hidden rounded-full bg-neutral-100"
          >
            <div className="h-full rounded-full bg-indigo-600" style={{ width: `${pct}%` }} />
          </div>
          <p className="mt-2 text-xs text-neutral-500 tabular-nums">{counts.map((c) => `${c.n} ${LABEL[c.s].toLowerCase()}`).join(" · ")}</p>
        </div>

        <ol className="mt-5">
          {items.map((m, i) => (
            <li key={m.key} className="relative flex gap-3 pb-4 last:pb-0">
              {i < items.length - 1 ? (
                <span aria-hidden="true" className={`absolute top-6 bottom-0.5 left-2.5 w-px -translate-x-1/2 ${m.status === "done" ? "bg-indigo-200" : "bg-neutral-200"}`} />
              ) : null}
              <span className={`relative mt-px shrink-0 ${tones[m.status].icon}`}>
                <StatusIcon status={m.status} />
              </span>
              <div className="flex min-w-0 flex-1 flex-col gap-1 @md:flex-row @md:items-start @md:justify-between @md:gap-4">
                <div className="min-w-0">
                  <p className={`text-sm text-pretty ${m.status === "done" ? "text-neutral-600" : "font-medium text-neutral-900"}`}>{m.name}</p>
                  {m.note ? <p className="mt-0.5 text-xs text-pretty text-neutral-500">{m.note}</p> : null}
                </div>
                <div className="flex shrink-0 items-center gap-2 text-xs @md:flex-row-reverse">
                  <span className={`inline-flex items-center rounded-md px-1.5 py-0.5 font-medium ring-1 ring-inset ${tones[m.status].badge}`}>{LABEL[m.status]}</span>
                  {m.due ? (
                    <span className="text-neutral-500 tabular-nums">
                      {m.status === "late" ? "Was due " : "Due "}
                      {m.due}
                    </span>
                  ) : null}
                </div>
              </div>
            </li>
          ))}
        </ol>

        {foot}
      </div>
    );
  },
};
```
