# Add the "Story Cards" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/card-grid) to this Pantheon Content Publisher (P1) Next.js project. News, stories or blog posts as image cards with whole-card click targets and no nested links.

## Steps

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

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

/**
 * Card Grid — news, stories or resources as image cards with category and date.
 * Each card is one link (on its title) stretched over the card, so there are no nested links.
 * Register: `CardGridBlock: cardGridBlock` in puck.config.tsx.
 */

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

type Card = {
  imageUrl: string;
  imageAlt: string;
  category: string;
  date: string;
  title: string;
  excerpt: string;
  href: string;
};

export type CardGridProps = {
  heading: string;
  headingLevel: Heading;
  intro: string;
  viewAllLabel: string;
  viewAllHref: string;
  cards: Card[];
  columns: "2" | "3";
};

const childHeading = { h1: "h2", h2: "h3", h3: "h4", h4: "h5" } as const;

const gridCols = {
  "2": "md:grid-cols-2",
  "3": "md:grid-cols-2 lg:grid-cols-3",
} as const;

const Arrow = ({ className }: { className: string }) => (
  <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className={className}>
    <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>
);

export const cardGridBlock: ComponentConfig<CardGridProps> = {
  label: "Card Grid",
  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." },
    },
    intro: { type: "textarea", label: "Intro" },
    viewAllLabel: { type: "text", label: "\"View all\" link text", metadata: { help: "Leave blank to hide it." } },
    viewAllHref: { type: "text", label: "\"View all\" link" },
    cards: {
      type: "array",
      label: "Cards",
      min: 1,
      max: 12,
      getItemSummary: (item) => item?.title?.slice(0, 48) || "Card",
      defaultItemProps: {
        imageUrl: "https://picsum.photos/seed/newstory/1200/800",
        imageAlt: "",
        category: "News",
        date: "",
        title: "New story",
        excerpt: "",
        href: "",
      },
      arrayFields: {
        imageUrl: { type: "text", label: "Image URL", metadata: { help: "Leave blank for a text-only card." } },
        imageAlt: { type: "text", label: "Image alt text", metadata: { help: "Describe the photo for screen reader users. Leave blank only if it's purely decorative." } },
        category: { type: "text", label: "Category" },
        date: { type: "text", label: "Date", metadata: { help: "Type it as it should appear, such as March 4, 2026." } },
        title: { type: "text", label: "Title" },
        excerpt: { type: "textarea", label: "Excerpt", metadata: { help: "One or two sentences. Longer text is trimmed to three lines." } },
        href: { type: "text", label: "Link", metadata: { help: "Where the card goes. Leave blank to make the card unclickable." } },
      },
    },
    columns: {
      type: "radio",
      label: "Columns on desktop",
      options: [
        { label: "2", value: "2" },
        { label: "3", value: "3" },
      ],
    },
  },
  defaultProps: {
    heading: "News and stories",
    headingLevel: "h2",
    intro: "What our crews, volunteers and neighbors have been up to across the park system this season.",
    viewAllLabel: "View all stories",
    viewAllHref: "/news",
    cards: [
      {
        imageUrl: "https://picsum.photos/seed/meadow/1200/800",
        imageAlt: "Volunteers planting native grasses in an open meadow",
        category: "Conservation",
        date: "September 18, 2026",
        title: "Four acres of mowed lawn are becoming a pollinator meadow",
        excerpt: "Two hundred volunteers planted 30,000 native plugs at Riverside Park. By next summer the monarchs should notice.",
        href: "/news/riverside-meadow",
      },
      {
        imageUrl: "https://picsum.photos/seed/libraryyouth/1200/800",
        imageAlt: "Teenagers studying together at a long table in a community center",
        category: "Programs",
        date: "September 9, 2026",
        title: "The teen study hall that outgrew its room",
        excerpt: "What started as six students and a pot of coffee at the Eastside Center now fills the gym three nights a week.",
        href: "/news/teen-study-hall",
      },
      {
        imageUrl: "https://picsum.photos/seed/trailbridge/1200/800",
        imageAlt: "A new wooden footbridge crossing a creek in the woods",
        category: "Capital projects",
        date: "August 27, 2026",
        title: "Mill Creek Trail reopens with a fully accessible bridge",
        excerpt: "The new crossing closes the last gap in the loop, giving wheelchair users and strollers a continuous 3.2-mile route.",
        href: "/news/mill-creek-bridge",
      },
    ],
    columns: "3",
  },
  render: ({ heading, headingLevel, intro, viewAllLabel, viewAllHref, cards, columns }) => {
    const H = headingLevel || "h2";
    const Sub = childHeading[headingLevel] || "h3";
    const list = (cards ?? []).filter((c) => c?.title);
    const hasHeader = Boolean(heading || intro || viewAllLabel);
    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">
          {hasHeader ? (
            <div className="flex flex-col gap-6 md:flex-row md:items-end md:justify-between md:gap-12">
              <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>
              {viewAllLabel ? (
                <a
                  href={viewAllHref || "#"}
                  className="group inline-flex min-h-11 shrink-0 items-center gap-1.5 self-start font-semibold text-indigo-700 underline decoration-indigo-300 underline-offset-4 hover:decoration-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600 md:self-auto"
                >
                  {viewAllLabel}
                  <Arrow className="size-5 transition motion-safe:group-hover:translate-x-0.5" />
                </a>
              ) : null}
            </div>
          ) : null}
          {list.length ? (
            <ul role="list" className={`grid grid-cols-1 gap-x-8 gap-y-14 ${hasHeader ? "mt-12 sm:mt-16" : ""} ${gridCols[columns] || gridCols["3"]}`}>
              {list.map((card, i) => (
                <li key={`${card.title}-${i}`}>
                  <article className="group relative flex h-full flex-col">
                    {card.imageUrl ? (
                      <div className="overflow-hidden rounded-2xl bg-neutral-100 ring-1 ring-neutral-900/5">
                        <img
                          src={card.imageUrl}
                          alt={card.imageAlt || ""}
                          className={`aspect-[3/2] w-full object-cover ${card.href ? "transition duration-500 ease-out motion-safe:group-hover:scale-105" : ""}`}
                        />
                      </div>
                    ) : null}
                    {card.category || card.date ? (
                      <p className={`flex flex-wrap items-center gap-x-3 gap-y-1 text-sm leading-6 ${card.imageUrl ? "mt-6" : ""}`}>
                        {card.category ? <span className="font-semibold text-indigo-700">{card.category}</span> : null}
                        {card.category && card.date ? <span aria-hidden="true" className="size-1 rounded-full bg-neutral-400" /> : null}
                        {card.date ? <span className="text-neutral-600">{card.date}</span> : null}
                      </p>
                    ) : null}
                    <Sub className={`text-xl leading-snug font-semibold tracking-tight text-pretty text-neutral-950 ${card.imageUrl || card.category || card.date ? "mt-3" : ""}`}>
                      {card.href ? (
                        <a
                          href={card.href}
                          className="transition-colors after:absolute after:-inset-3 after:rounded-3xl group-hover:text-indigo-700 focus-visible:outline-none focus-visible:after:outline-2 focus-visible:after:outline-indigo-600"
                        >
                          {card.title}
                        </a>
                      ) : (
                        card.title
                      )}
                    </Sub>
                    {card.excerpt ? <p className="mt-3 line-clamp-3 text-base leading-7 text-neutral-600">{card.excerpt}</p> : null}
                  </article>
                </li>
              ))}
            </ul>
          ) : null}
        </div>
      </section>
    );
  },
};
```
