# Add the "Reading Challenge" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/reading-challenge) to this Pantheon Content Publisher (P1) Next.js project. A summer reading challenge with dates, tracks by age, how-it-works steps, prizes and an accessible community progress bar.

## Steps

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

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

/**
 * Reading Challenge — a summer reading program page section: dates, tracks by age, how-it-works
 * steps, prizes, a community progress bar with the figures in text, and a sign-up link.
 * Register: `ReadingChallengeBlock: readingChallengeBlock` in puck.config.tsx.
 */

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

type Track = { name: string; ages: string; goal: string };

export type ReadingChallengeProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  dates: string;
  signupLabel: string;
  signupHref: string;
  progressLabel: string;
  progressCurrent: string;
  progressGoal: string;
  progressUnit: string;
  progressNote: string;
  tracksHeading: string;
  tracks: Track[];
  stepsHeading: string;
  steps: { title: string; body: string }[];
  prizesHeading: string;
  prizes: { prize: string }[];
};

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

const toNumber = (v: string | undefined) => {
  const n = parseFloat((v || "").replace(/[^0-9.-]/g, ""));
  return Number.isFinite(n) ? n : null;
};

export const readingChallengeBlock: ComponentConfig<ReadingChallengeProps> = {
  label: "Reading Challenge",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Such as the program's theme. 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" },
    dates: { type: "text", label: "Dates", metadata: { help: "Such as June 1 – August 15, 2026. Leave blank to hide it." } },
    signupLabel: { type: "text", label: "Sign-up button text", metadata: { help: "Leave blank to hide the button." } },
    signupHref: { type: "text", label: "Sign-up link" },
    progressLabel: { type: "text", label: "Progress label", metadata: { help: "Names the bar, such as Community reading goal. Leave blank to hide the progress panel." } },
    progressCurrent: { type: "text", label: "Progress so far", metadata: { help: "A number, such as 1200000. Commas are fine. Can be bound to a data source." } },
    progressGoal: { type: "text", label: "Goal", metadata: { help: "A number, such as 2000000." } },
    progressUnit: { type: "text", label: "Unit", metadata: { help: "Such as minutes, books or pages." } },
    progressNote: { type: "text", label: "Progress note", metadata: { help: "Where the figure comes from and when it was updated. Leave blank to hide it." } },
    tracksHeading: { type: "text", label: "Tracks heading" },
    tracks: {
      type: "array",
      label: "Tracks by age",
      min: 0,
      max: 6,
      getItemSummary: (item) => item?.name || "Track",
      defaultItemProps: { name: "New track", ages: "All ages", goal: "" },
      arrayFields: {
        name: { type: "text", label: "Track name" },
        ages: { type: "text", label: "Ages" },
        goal: { type: "textarea", label: "Goal or details" },
      },
    },
    stepsHeading: { type: "text", label: "Steps heading" },
    steps: {
      type: "array",
      label: "How it works",
      min: 0,
      max: 5,
      getItemSummary: (item) => item?.title || "Step",
      defaultItemProps: { title: "New step", body: "" },
      arrayFields: {
        title: { type: "text", label: "Step" },
        body: { type: "textarea", label: "Details", metadata: { help: "Leave blank to hide it." } },
      },
    },
    prizesHeading: { type: "text", label: "Prizes heading" },
    prizes: {
      type: "array",
      label: "Prizes",
      min: 0,
      max: 8,
      getItemSummary: (item) => item?.prize?.slice(0, 48) || "Prize",
      defaultItemProps: { prize: "New prize" },
      arrayFields: { prize: { type: "text", label: "Prize" } },
    },
  },
  defaultProps: {
    eyebrow: "Summer Reading Challenge 2026",
    heading: "Read your way through summer",
    headingLevel: "h2",
    intro: "Every minute counts, whether it's a picture book at bedtime, a graphic novel on the porch or an audiobook on the drive to the lake. Log your reading, earn prizes and help Cedar Valley reach its biggest goal yet.",
    dates: "June 1 – August 15, 2026",
    signupLabel: "Sign up free",
    signupHref: "/summer-reading/sign-up",
    progressLabel: "Community reading goal",
    progressCurrent: "1,200,000",
    progressGoal: "2,000,000",
    progressUnit: "minutes",
    progressNote: "Sample figures. Minutes logged by all participants, updated every Monday.",
    tracksHeading: "A track for every reader",
    tracks: [
      { name: "Read-to-Me", ages: "Birth–5", goal: "Read together 20 minutes a day. Logging 15 books earns a free book to keep." },
      { name: "Kids", ages: "Ages 6–11", goal: "Read 600 minutes over the summer, about 10 minutes a day." },
      { name: "Teens", ages: "Ages 12–18", goal: "Read 800 minutes and finish three activity badges." },
      { name: "Adults", ages: "18 and up", goal: "Read five books in any format, including audiobooks and graphic novels." },
    ],
    stepsHeading: "How it works",
    steps: [
      { title: "Sign up", body: "Register online or at any branch. One account covers your whole family." },
      { title: "Read anything", body: "Books, comics, magazines, audiobooks: it all counts. So does reading aloud." },
      { title: "Log your time", body: "Track minutes on the app or on a paper log from the children's desk." },
      { title: "Collect prizes", body: "Stop by any branch to pick up prizes as you reach each milestone." },
    ],
    prizesHeading: "Prizes",
    prizes: [
      { prize: "A free book to keep at the halfway point" },
      { prize: "Coupons from Cedar Valley businesses" },
      { prize: "Free family admission to the county pool" },
      { prize: "Entry in the grand-prize drawing for an e-reader" },
    ],
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, dates, signupLabel, signupHref, progressLabel, progressCurrent, progressGoal, progressUnit, progressNote, tracksHeading, tracks, stepsHeading, steps, prizesHeading, prizes }) => {
    const H = headingLevel || "h2";
    const Sub = childLevel[H] ?? "h3";
    const uid = `p1-reading-challenge-${id || "block"}`;
    const trackList = (tracks ?? []).filter((t) => t?.name);
    const stepList = (steps ?? []).filter((s) => s?.title);
    const prizeList = (prizes ?? []).filter((p) => p?.prize);
    const current = toNumber(progressCurrent);
    const goal = toNumber(progressGoal);
    const hasProgress = Boolean(progressLabel && current !== null && goal !== null && goal > 0);
    const pct = hasProgress ? Math.max(0, Math.min(100, ((current as number) / (goal as number)) * 100)) : 0;
    const fmt = (n: number | null) => (n === null ? "—" : n.toLocaleString("en-US"));
    const progressText = `${fmt(current)} of ${fmt(goal)} ${progressUnit || ""}`.trim();

    return (
      <section className="bg-white">
        <div className="relative isolate overflow-hidden bg-indigo-950 px-4 pt-16 pb-24 sm:px-6 sm:pt-20 lg:px-8 lg:pt-24 lg:pb-28">
          <svg aria-hidden="true" viewBox="0 0 400 200" fill="none" preserveAspectRatio="xMidYMid slice" className="absolute inset-0 -z-10 size-full text-indigo-800">
            <circle cx="340" cy="40" r="90" fill="currentColor" opacity="0.5" />
            <circle cx="340" cy="40" r="56" fill="currentColor" />
            <path d="M0 170c60-20 110 10 170-6s110-34 160-20 50 18 70 14v42H0Z" fill="currentColor" opacity="0.6" />
          </svg>
          <div className="mx-auto grid max-w-7xl grid-cols-1 gap-10 lg:grid-cols-12 lg:items-end">
            <div className="lg:col-span-7">
              {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-200 uppercase">{eyebrow}</p> : null}
              {heading ? (
                <H className={`${eyebrow ? "mt-3" : ""} font-serif text-4xl font-semibold tracking-tight text-balance text-white sm:text-5xl`}>{heading}</H>
              ) : null}
              {intro ? <p className="mt-5 max-w-2xl text-lg leading-8 text-pretty text-indigo-100">{intro}</p> : null}
              {dates || signupLabel ? (
                <div className="mt-8 flex flex-col gap-4 sm:flex-row sm:items-center sm:gap-6">
                  {signupLabel ? (
                    <a
                      href={signupHref || "#"}
                      className={`inline-flex min-h-12 items-center justify-center gap-2 rounded-xl bg-white px-6 py-3 text-base font-semibold text-indigo-950 shadow-sm transition hover:bg-indigo-50 focus-visible:outline-white ${focusRing}`}
                    >
                      {signupLabel}
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-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}
                  {dates ? (
                    <p className="inline-flex items-center gap-2 text-base font-semibold text-white">
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-5 text-indigo-300">
                        <path fillRule="evenodd" d="M5.75 2a.75.75 0 0 1 .75.75V4h7V2.75a.75.75 0 0 1 1.5 0V4h.25A2.75 2.75 0 0 1 18 6.75v8.5A2.75 2.75 0 0 1 15.25 18H4.75A2.75 2.75 0 0 1 2 15.25v-8.5A2.75 2.75 0 0 1 4.75 4H5V2.75A.75.75 0 0 1 5.75 2Zm-1 5.5c-.69 0-1.25.56-1.25 1.25v6.5c0 .69.56 1.25 1.25 1.25h10.5c.69 0 1.25-.56 1.25-1.25v-6.5c0-.69-.56-1.25-1.25-1.25H4.75Z" clipRule="evenodd" />
                      </svg>
                      {dates}
                    </p>
                  ) : null}
                </div>
              ) : null}
            </div>

            {hasProgress ? (
              <div className="rounded-2xl bg-white/10 p-5 ring-1 ring-white/15 sm:p-6 lg:col-span-5">
                <p id={`${uid}-progress-label`} className="text-sm font-semibold text-indigo-100">
                  {progressLabel}
                </p>
                <p className="mt-2 text-white">
                  <span className="font-serif text-3xl font-semibold tracking-tight tabular-nums sm:text-4xl">{fmt(current)}</span>
                  <span className="ml-2 text-base text-indigo-100">
                    of {fmt(goal)} {progressUnit}
                  </span>
                </p>
                <div
                  role="progressbar"
                  aria-labelledby={`${uid}-progress-label`}
                  aria-valuemin={0}
                  aria-valuemax={goal as number}
                  aria-valuenow={Math.min(current as number, goal as number)}
                  aria-valuetext={`${progressText}, ${Math.round(pct)}%`}
                  className="mt-4 h-3 overflow-hidden rounded-full bg-indigo-900 ring-1 ring-white/20"
                >
                  <div className="h-full rounded-full bg-white" style={{ width: `${pct}%` }} />
                </div>
                <p className="mt-2 text-sm font-medium text-indigo-100 tabular-nums">{Math.round(pct)}% of the goal</p>
                {progressNote ? <p className="mt-3 text-xs leading-5 text-indigo-200">{progressNote}</p> : null}
              </div>
            ) : null}
          </div>
        </div>

        <div className="px-4 pb-16 sm:px-6 sm:pb-20 lg:px-8 lg:pb-24">
          <div className="mx-auto max-w-7xl">
            {trackList.length ? (
              <div className="-mt-12 rounded-3xl bg-white p-5 shadow-lg ring-1 ring-neutral-200 sm:p-8">
                <Sub className="font-serif text-2xl font-semibold tracking-tight text-neutral-950">{tracksHeading || "Tracks"}</Sub>
                <ul role="list" className="mt-6 grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
                  {trackList.map((t, i) => (
                    <li key={`${t.name}-${i}`} className="rounded-2xl bg-neutral-50 p-5 ring-1 ring-neutral-200">
                      {t.ages ? <p className="inline-flex rounded-full bg-indigo-600 px-2.5 py-0.5 text-xs font-semibold text-white">{t.ages}</p> : null}
                      <p className="mt-3 text-lg font-semibold text-neutral-950">{t.name}</p>
                      {t.goal ? <p className="mt-1 text-sm leading-6 text-pretty text-neutral-700">{t.goal}</p> : null}
                    </li>
                  ))}
                </ul>
              </div>
            ) : null}

            {stepList.length || prizeList.length ? (
              <div className="mt-16 grid grid-cols-1 gap-12 lg:grid-cols-12">
                {stepList.length ? (
                  <div className={prizeList.length ? "lg:col-span-7" : "lg:col-span-12"}>
                    <Sub className="font-serif text-2xl font-semibold tracking-tight text-neutral-950">{stepsHeading || "How it works"}</Sub>
                    <ol className="mt-6 space-y-6">
                      {stepList.map((s, i) => (
                        <li key={`${s.title}-${i}`} className="flex gap-4">
                          <span aria-hidden="true" className="grid size-10 shrink-0 place-items-center rounded-full bg-indigo-50 font-serif text-lg font-semibold text-indigo-700 ring-1 ring-indigo-600/15">
                            {i + 1}
                          </span>
                          <div className="min-w-0 pt-1.5">
                            <p className="text-base font-semibold text-neutral-950">{s.title}</p>
                            {s.body ? <p className="mt-1 text-sm leading-6 text-pretty text-neutral-600">{s.body}</p> : null}
                          </div>
                        </li>
                      ))}
                    </ol>
                  </div>
                ) : null}
                {prizeList.length ? (
                  <div className={stepList.length ? "lg:col-span-5" : "lg:col-span-12"}>
                    <div className="rounded-2xl bg-indigo-50 p-6 ring-1 ring-indigo-600/10 sm:p-8">
                      <Sub className="flex items-center gap-2.5 font-serif text-2xl font-semibold tracking-tight text-neutral-950">
                        <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-6 text-indigo-600">
                          <path fillRule="evenodd" d="M10 1c-1.828 0-3.623.149-5.371.435a.75.75 0 0 0-.629.74v.387c-.827.157-1.642.345-2.445.564a.75.75 0 0 0-.552.698 5 5 0 0 0 4.503 5.152 6 6 0 0 0 2.946 1.822A6.451 6.451 0 0 1 7.768 13H7.5A1.5 1.5 0 0 0 6 14.5V17h-.75C4.56 17 4 17.56 4 18.25c0 .414.336.75.75.75h10.5a.75.75 0 0 0 .75-.75c0-.69-.56-1.25-1.25-1.25H14v-2.5a1.5 1.5 0 0 0-1.5-1.5h-.268a6.453 6.453 0 0 1-.684-2.202 6 6 0 0 0 2.946-1.822 5 5 0 0 0 4.503-5.152.75.75 0 0 0-.552-.698A31.804 31.804 0 0 0 16 2.562v-.387a.75.75 0 0 0-.629-.74A33.227 33.227 0 0 0 10 1ZM2.525 4.422C3.012 4.3 3.504 4.19 4 4.09V5c0 .74.134 1.448.38 2.103a3.503 3.503 0 0 1-1.855-2.68Zm14.95 0a3.503 3.503 0 0 1-1.854 2.68C15.866 6.449 16 5.74 16 5v-.91c.496.099.988.21 1.475.332Z" clipRule="evenodd" />
                        </svg>
                        {prizesHeading || "Prizes"}
                      </Sub>
                      <ul role="list" className="mt-5 space-y-3">
                        {prizeList.map((p, i) => (
                          <li key={`${p.prize}-${i}`} className="flex gap-3 text-sm leading-6 text-neutral-800">
                            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="mt-0.5 size-5 shrink-0 text-indigo-600">
                              <path fillRule="evenodd" d="M10.868 2.884c-.321-.772-1.415-.772-1.736 0l-1.83 4.401-4.753.381c-.833.067-1.171 1.107-.536 1.651l3.62 3.102-1.106 4.637c-.194.813.691 1.456 1.405 1.02L10 15.591l4.069 2.485c.713.436 1.598-.207 1.404-1.02l-1.106-4.637 3.62-3.102c.635-.544.297-1.584-.536-1.65l-4.752-.382-1.831-4.401Z" clipRule="evenodd" />
                            </svg>
                            <span className="min-w-0">{p.prize}</span>
                          </li>
                        ))}
                      </ul>
                    </div>
                  </div>
                ) : null}
              </div>
            ) : null}
          </div>
        </div>
      </section>
    );
  },
};
```
