# Add the "Catalog Search" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/catalog-search) to this Pantheon Content Publisher (P1) Next.js project. A catalog search panel that submits to your catalog with an optional format filter, quick links and an Ask a librarian link.

## Steps

1. Create `components/puck/catalog-search-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 { catalogSearchBlock } from "./components/puck/catalog-search-block";`
3. Register it under `components` as `CatalogSearchBlock: catalogSearchBlock`.
4. Add `"CatalogSearchBlock"` 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/catalog-search-block.tsx`

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

/**
 * Catalog Search — a library catalog search panel: keyword box plus an optional format
 * filter that submits with GET to your catalog, quick links and an "Ask a librarian" link.
 * Register: `CatalogSearchBlock: catalogSearchBlock` in puck.config.tsx.
 */

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

type QuickLink = { label: string; href: string; icon: "new" | "star" | "account" | "list" };

export type CatalogSearchProps = {
  eyebrow: string;
  heading: string;
  headingLevel: Heading;
  intro: string;
  catalogUrl: string;
  queryParam: string;
  inputLabel: string;
  placeholder: string;
  formatParam: string;
  formatLabel: string;
  formats: { label: string; value: string }[];
  buttonLabel: string;
  quickLinksLabel: string;
  quickLinks: QuickLink[];
  askPrompt: string;
  askLabel: string;
  askHref: string;
};

const icons: Record<QuickLink["icon"], React.ReactNode> = {
  new: (
    <path fillRule="evenodd" d="M10 1a.75.75 0 0 1 .75.75v1.5a.75.75 0 0 1-1.5 0v-1.5A.75.75 0 0 1 10 1ZM5.05 3.05a.75.75 0 0 1 1.06 0l1.062 1.06A.75.75 0 1 1 6.11 5.173L5.05 4.11a.75.75 0 0 1 0-1.06Zm9.9 0a.75.75 0 0 1 0 1.06l-1.06 1.062a.75.75 0 0 1-1.062-1.061l1.061-1.06a.75.75 0 0 1 1.06 0ZM3 8a.75.75 0 0 1 .75-.75h1.5a.75.75 0 0 1 0 1.5h-1.5A.75.75 0 0 1 3 8Zm11 0a.75.75 0 0 1 .75-.75h1.5a.75.75 0 0 1 0 1.5h-1.5A.75.75 0 0 1 14 8Zm-6.828 2.828a.75.75 0 0 1 0 1.061L6.11 12.95a.75.75 0 0 1-1.06-1.06l1.06-1.06a.75.75 0 0 1 1.06 0ZM10 7a3 3 0 1 0 0 6 3 3 0 0 0 0-6Zm-2.5 8.5a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Zm.75 2.25a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5Z" clipRule="evenodd" />
  ),
  star: (
    <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" />
  ),
  account: (
    <path d="M10 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM3.465 14.493a1.23 1.23 0 0 0 .41 1.412A9.957 9.957 0 0 0 10 18c2.31 0 4.438-.784 6.131-2.1.43-.333.604-.903.408-1.41a7.002 7.002 0 0 0-13.074.003Z" />
  ),
  list: (
    <path fillRule="evenodd" d="M6 4.75A.75.75 0 0 1 6.75 4h10.5a.75.75 0 0 1 0 1.5H6.75A.75.75 0 0 1 6 4.75ZM6 10a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H6.75A.75.75 0 0 1 6 10Zm0 5.25a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H6.75a.75.75 0 0 1-.75-.75ZM1.99 4.75a1 1 0 0 1 1-1H3a1 1 0 0 1 1 1v.01a1 1 0 0 1-1 1h-.01a1 1 0 0 1-1-1v-.01ZM1.99 15.25a1 1 0 0 1 1-1H3a1 1 0 0 1 1 1v.01a1 1 0 0 1-1 1h-.01a1 1 0 0 1-1-1v-.01ZM1.99 10a1 1 0 0 1 1-1H3a1 1 0 0 1 1 1v.01a1 1 0 0 1-1 1h-.01a1 1 0 0 1-1-1V10Z" clipRule="evenodd" />
  ),
};

const focusRing = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600";

export const catalogSearchBlock: ComponentConfig<CatalogSearchProps> = {
  label: "Catalog Search",
  fields: {
    eyebrow: { type: "text", label: "Eyebrow", metadata: { help: "Small line above the heading. 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" },
    catalogUrl: { type: "text", label: "Catalog search URL", metadata: { help: "Your catalog's search results address, such as https://catalog.example.org/search. The form opens it with the search words added." } },
    queryParam: { type: "text", label: "Search parameter name", metadata: { help: "The query name your catalog reads, often q, query or lookfor. Check a results page address to find it." } },
    inputLabel: { type: "text", label: "Search field label", metadata: { help: "Shown above the search box and read by screen readers." } },
    placeholder: { type: "text", label: "Placeholder", metadata: { help: "Example text inside the empty field." } },
    formatParam: { type: "text", label: "Format parameter name", metadata: { help: "The query name your catalog uses to filter by format, such as format or type. Leave blank to hide the format menu." } },
    formatLabel: { type: "text", label: "Format menu label" },
    formats: {
      type: "array",
      label: "Formats",
      min: 0,
      max: 10,
      getItemSummary: (item) => item?.label || "Format",
      defaultItemProps: { label: "Magazines", value: "magazine" },
      arrayFields: {
        label: { type: "text", label: "Label" },
        value: { type: "text", label: "Catalog value", metadata: { help: "The exact value your catalog expects for this format." } },
      },
    },
    buttonLabel: { type: "text", label: "Button text" },
    quickLinksLabel: { type: "text", label: "Quick links label", metadata: { help: "Leave blank to hide the label." } },
    quickLinks: {
      type: "array",
      label: "Quick links",
      min: 0,
      max: 6,
      getItemSummary: (item) => item?.label || "Link",
      defaultItemProps: { label: "Reading lists", href: "/lists", icon: "list" },
      arrayFields: {
        label: { type: "text", label: "Text" },
        href: { type: "text", label: "Link" },
        icon: {
          type: "select",
          label: "Icon",
          options: [
            { label: "Sparkle (new)", value: "new" },
            { label: "Star (picks)", value: "star" },
            { label: "Person (account)", value: "account" },
            { label: "List", value: "list" },
          ],
        },
      },
    },
    askPrompt: { type: "text", label: "Help prompt", metadata: { help: "Short line before the help link, such as Can't find it? Leave blank to hide it." } },
    askLabel: { type: "text", label: "Help link text", metadata: { help: "Leave blank to hide the help link." } },
    askHref: { type: "text", label: "Help link" },
  },
  defaultProps: {
    eyebrow: "Cedar Valley Public Library",
    heading: "Find your next great read",
    headingLevel: "h2",
    intro: "Search more than 280,000 books, audiobooks, movies and albums across all four branches. Place a hold and we'll have it waiting at the branch you choose.",
    catalogUrl: "https://catalog.cedarvalleylibrary.example.org/search",
    queryParam: "q",
    inputLabel: "Title, author, subject or keyword",
    placeholder: "Try “Toni Morrison” or “bread baking”",
    formatParam: "format",
    formatLabel: "Format",
    formats: [
      { label: "Books", value: "book" },
      { label: "Audiobooks", value: "audiobook" },
      { label: "Movies", value: "movie" },
      { label: "Music", value: "music" },
    ],
    buttonLabel: "Search the catalog",
    quickLinksLabel: "Browse",
    quickLinks: [
      { label: "New arrivals", href: "/catalog/new", icon: "new" },
      { label: "Staff picks", href: "/catalog/staff-picks", icon: "star" },
      { label: "My account & holds", href: "/account", icon: "account" },
    ],
    askPrompt: "Can't find what you're looking for?",
    askLabel: "Ask a librarian",
    askHref: "/ask",
  },
  render: ({ id, eyebrow, heading, headingLevel, intro, catalogUrl, queryParam, inputLabel, placeholder, formatParam, formatLabel, formats, buttonLabel, quickLinksLabel, quickLinks, askPrompt, askLabel, askHref }) => {
    const H = headingLevel || "h2";
    const uid = `p1-catalog-search-${id || "block"}`;
    const formatList = (formats ?? []).filter((f) => f?.label && f?.value);
    const links = (quickLinks ?? []).filter((l) => l?.label);
    const showFormats = Boolean(formatParam && formatList.length);

    return (
      <section className="bg-neutral-50 px-4 py-16 sm:px-6 sm:py-20 lg:px-8 lg:py-24">
        <div className="mx-auto max-w-4xl">
          <div className="relative isolate overflow-hidden rounded-3xl bg-white p-6 shadow-sm ring-1 ring-neutral-200 sm:p-10 lg:p-12">
            <svg aria-hidden="true" viewBox="0 0 240 120" fill="none" className="absolute -top-6 -right-10 -z-10 w-56 text-indigo-100 sm:w-72">
              <rect x="10" y="30" width="22" height="90" rx="3" fill="currentColor" />
              <rect x="36" y="14" width="18" height="106" rx="3" fill="currentColor" />
              <rect x="58" y="40" width="26" height="80" rx="3" fill="currentColor" />
              <rect x="92" y="22" width="20" height="98" rx="3" fill="currentColor" transform="rotate(-12 102 71)" />
              <rect x="128" y="36" width="24" height="84" rx="3" fill="currentColor" />
              <rect x="156" y="8" width="18" height="112" rx="3" fill="currentColor" />
              <rect x="178" y="28" width="28" height="92" rx="3" fill="currentColor" />
            </svg>

            {eyebrow ? <p className="text-sm font-semibold tracking-wide text-indigo-700 uppercase">{eyebrow}</p> : null}
            {heading ? (
              <H className={`${eyebrow ? "mt-3" : ""} font-serif text-3xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-4xl`}>{heading}</H>
            ) : null}
            {intro ? <p className="mt-4 max-w-2xl text-base leading-7 text-pretty text-neutral-600 sm:text-lg sm:leading-8">{intro}</p> : null}

            <form role="search" aria-label={heading || "Search the catalog"} action={catalogUrl || "/catalog"} method="get" className="mt-8">
              <div className="flex flex-col gap-4 sm:flex-row sm:items-end">
                <div className="min-w-0 flex-1">
                  <label htmlFor={`${uid}-q`} className="block text-sm font-semibold text-neutral-900">
                    {inputLabel || "Search the catalog"}
                  </label>
                  <div className="relative mt-2">
                    <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="pointer-events-none absolute top-1/2 left-3.5 size-5 -translate-y-1/2 text-neutral-500">
                      <path fillRule="evenodd" d="M9 3.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11ZM2 9a7 7 0 1 1 12.452 4.391l3.328 3.329a.75.75 0 1 1-1.06 1.06l-3.329-3.328A7 7 0 0 1 2 9Z" clipRule="evenodd" />
                    </svg>
                    <input
                      id={`${uid}-q`}
                      type="search"
                      name={queryParam || "q"}
                      placeholder={placeholder || undefined}
                      autoComplete="off"
                      className="block min-h-12 w-full rounded-xl border-0 bg-white py-3 pr-4 pl-11 text-base text-neutral-950 ring-1 ring-neutral-300 placeholder:text-neutral-500 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-none"
                    />
                  </div>
                </div>
                {showFormats ? (
                  <div className="min-w-0 sm:w-44">
                    <label htmlFor={`${uid}-format`} className="block text-sm font-semibold text-neutral-900">
                      {formatLabel || "Format"}
                    </label>
                    <div className="relative mt-2">
                      <select
                        id={`${uid}-format`}
                        name={formatParam}
                        defaultValue=""
                        className="block min-h-12 w-full appearance-none rounded-xl border-0 bg-white py-3 pr-10 pl-4 text-base text-neutral-950 ring-1 ring-neutral-300 ring-inset focus:ring-2 focus:ring-indigo-600 focus:outline-none"
                      >
                        <option value="">All formats</option>
                        {formatList.map((f, i) => (
                          <option key={`${f.value}-${i}`} value={f.value}>
                            {f.label}
                          </option>
                        ))}
                      </select>
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="pointer-events-none absolute top-1/2 right-3 size-5 -translate-y-1/2 text-neutral-500">
                        <path fillRule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" clipRule="evenodd" />
                      </svg>
                    </div>
                  </div>
                ) : null}
              </div>
              <button
                type="submit"
                className={`mt-4 inline-flex min-h-12 w-full items-center justify-center gap-2 rounded-xl bg-indigo-600 px-6 py-3 text-base font-semibold text-white shadow-sm transition hover:bg-indigo-500 sm:w-auto ${focusRing}`}
              >
                {buttonLabel || "Search"}
                <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>
              </button>
            </form>

            {links.length || askLabel ? (
              <div className="mt-10 flex flex-col gap-6 border-t border-neutral-200 pt-6 lg:flex-row lg:items-center lg:justify-between">
                {links.length ? (
                  <nav aria-label={quickLinksLabel || "Catalog shortcuts"} className="flex flex-col gap-2 sm:flex-row sm:flex-wrap sm:items-center sm:gap-x-2">
                    {quickLinksLabel ? <p className="text-sm font-semibold text-neutral-500 sm:mr-2">{quickLinksLabel}</p> : null}
                    <ul role="list" className="flex flex-wrap gap-2">
                      {links.map((l, i) => (
                        <li key={`${l.label}-${i}`}>
                          <a
                            href={l.href || "#"}
                            className={`inline-flex min-h-11 items-center gap-2 rounded-full bg-neutral-100 px-4 py-2 text-sm font-medium text-neutral-800 transition hover:bg-indigo-50 hover:text-indigo-800 ${focusRing}`}
                          >
                            <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 shrink-0 text-indigo-600">
                              {icons[l.icon] ?? icons.list}
                            </svg>
                            {l.label}
                          </a>
                        </li>
                      ))}
                    </ul>
                  </nav>
                ) : null}
                {askLabel ? (
                  <p className="flex flex-wrap items-center gap-x-2 text-sm text-neutral-600">
                    {askPrompt ? <span>{askPrompt}</span> : null}
                    <a
                      href={askHref || "#"}
                      className={`inline-flex min-h-11 items-center gap-1.5 rounded font-semibold text-indigo-700 underline decoration-indigo-300 underline-offset-4 hover:decoration-indigo-700 ${focusRing}`}
                    >
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4">
                        <path fillRule="evenodd" d="M10 2c-2.236 0-4.43.18-6.57.524C1.993 2.755 1 4.014 1 5.426v5.148c0 1.413.993 2.67 2.43 2.902 1.168.188 2.352.327 3.55.414.28.02.521.18.642.413l1.713 3.293a.75.75 0 0 0 1.33 0l1.713-3.293a.783.783 0 0 1 .642-.413 41.102 41.102 0 0 0 3.55-.414c1.437-.231 2.43-1.49 2.43-2.902V5.426c0-1.413-.993-2.67-2.43-2.902A41.289 41.289 0 0 0 10 2Z" clipRule="evenodd" />
                      </svg>
                      {askLabel}
                    </a>
                  </p>
                ) : null}
              </div>
            ) : null}
          </div>
        </div>
      </section>
    );
  },
};
```
