# Add the "Dashboard Grid" block to this P1 project

Add a Puck component from P1 Blocks (https://p1-blocks.prolificdigital.io/blocks/dashboard-grid) to this Pantheon Content Publisher (P1) Next.js project. The layout for dashboard widgets: a titled section with a drop zone that arranges widgets in 1–4 columns.

## Steps

1. Create `components/puck/dashboard-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 { dashboardGridBlock } from "./components/puck/dashboard-grid-block";`
3. Register it under `components` as `DashboardGridBlock: dashboardGridBlock`.
4. Add `"DashboardGridBlock"` 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/dashboard-grid-block.tsx`

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

/**
 * Dashboard Grid — the layout for dashboard widgets. A titled section with a drop zone
 * (Puck slot) that lays its widgets out in 1–4 responsive columns.
 * Register: `DashboardGridBlock: dashboardGridBlock` in puck.config.tsx.
 */

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

export type DashboardGridProps = {
  heading: string;
  headingLevel: Heading;
  description: string;
  updated: string;
  actionLabel: string;
  actionHref: string;
  columns: "1" | "2" | "3" | "4";
  background: "tinted" | "white";
  widgets: unknown;
};

const COLUMNS: Record<DashboardGridProps["columns"], string> = {
  "1": "grid-cols-1",
  "2": "grid-cols-1 md:grid-cols-2",
  "3": "grid-cols-1 md:grid-cols-2 xl:grid-cols-3",
  "4": "grid-cols-1 sm:grid-cols-2 xl:grid-cols-4",
};

export const dashboardGridBlock: ComponentConfig<DashboardGridProps> = {
  label: "Dashboard Grid",
  fields: {
    heading: { type: "text", label: "Heading", metadata: { help: "Leave blank for a grid with no header, e.g. a second row of widgets." } },
    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." },
    },
    description: { type: "textarea", label: "Description" },
    updated: {
      type: "text",
      label: "Last updated",
      metadata: { help: "Bind to your data source's timestamp, e.g. {{ metrics.updated_at }}." },
    },
    actionLabel: { type: "text", label: "Action link text", metadata: { help: "e.g. Download CSV. Leave blank to hide it." } },
    actionHref: { type: "text", label: "Action link" },
    columns: {
      type: "select",
      label: "Columns (desktop)",
      options: [
        { label: "1", value: "1" },
        { label: "2", value: "2" },
        { label: "3", value: "3" },
        { label: "4", value: "4" },
      ],
      metadata: { help: "Widgets stack to one column on phones. Use a second grid for a row with a different column count." },
    },
    background: {
      type: "radio",
      label: "Background",
      options: [
        { label: "Tinted", value: "tinted" },
        { label: "White", value: "white" },
      ],
    },
    widgets: { type: "slot", label: "Widgets" },
  },
  defaultProps: {
    heading: "Program dashboard",
    headingLevel: "h2",
    description: "Key numbers for this quarter, refreshed from our reporting system.",
    updated: "Updated Oct 7, 2026, 9:00 a.m.",
    actionLabel: "Download data (CSV)",
    actionHref: "#",
    columns: "4",
    background: "tinted",
    widgets: [],
  },
  render: ({ heading, headingLevel, description, updated, actionLabel, actionHref, columns, background, widgets }) => {
    const H = headingLevel || "h2";
    // Puck hands a slot to render as a component; outside the editor it may be absent.
    const Widgets = typeof widgets === "function" ? (widgets as (p: { className?: string; minEmptyHeight?: number }) => React.ReactNode) : null;
    const hasHeader = Boolean(heading || description || updated || actionLabel);
    return (
      // A grid with no header is a continuation row, so it tucks up under the grid above it.
      <section data-dashboard-grid className={`px-4 sm:px-6 lg:px-8 ${hasHeader ? "py-10 sm:py-12" : "pb-10 sm:pb-12"} ${background === "white" ? "bg-white" : "bg-neutral-50"}`}>
        <div className="mx-auto max-w-7xl">
          {hasHeader ? (
            <div className="mb-6 flex flex-col gap-4 sm:mb-8 sm:flex-row sm:items-end sm:justify-between">
              <div className="min-w-0">
                {heading ? <H className="text-2xl font-semibold tracking-tight text-balance text-neutral-950 sm:text-3xl">{heading}</H> : null}
                {description ? <p className="mt-2 max-w-2xl text-base leading-7 text-neutral-600">{description}</p> : null}
              </div>
              {updated || actionLabel ? (
                <div className="flex shrink-0 flex-wrap items-center gap-x-4 gap-y-2">
                  {updated ? (
                    <p className="inline-flex items-center gap-2 text-sm text-neutral-600">
                      <span aria-hidden="true" className="relative flex size-2">
                        <span className="absolute inline-flex size-full animate-ping rounded-full bg-indigo-400 opacity-60 motion-reduce:animate-none" />
                        <span className="relative inline-flex size-2 rounded-full bg-indigo-600" />
                      </span>
                      {updated}
                    </p>
                  ) : null}
                  {actionLabel ? (
                    <a
                      href={actionHref || "#"}
                      className="inline-flex min-h-11 items-center gap-2 rounded-lg bg-white px-4 text-sm font-semibold text-neutral-900 shadow-xs ring-1 ring-neutral-950/10 transition hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
                    >
                      <svg aria-hidden="true" viewBox="0 0 20 20" fill="currentColor" className="size-4 text-neutral-500">
                        <path d="M10.75 2.75a.75.75 0 0 0-1.5 0v8.614L6.295 8.235a.75.75 0 1 0-1.09 1.03l4.25 4.5a.75.75 0 0 0 1.09 0l4.25-4.5a.75.75 0 0 0-1.09-1.03l-2.955 3.129V2.75Z" />
                        <path d="M3.5 12.75a.75.75 0 0 0-1.5 0v2.5A2.75 2.75 0 0 0 4.75 18h10.5A2.75 2.75 0 0 0 18 15.25v-2.5a.75.75 0 0 0-1.5 0v2.5c0 .69-.56 1.25-1.25 1.25H4.75c-.69 0-1.25-.56-1.25-1.25v-2.5Z" />
                      </svg>
                      {actionLabel}
                    </a>
                  ) : null}
                </div>
              ) : null}
            </div>
          ) : null}
          {Widgets ? <Widgets className={`grid gap-4 sm:gap-6 [&>*]:min-w-0 ${COLUMNS[columns] ?? COLUMNS["4"]}`} minEmptyHeight={160} /> : null}
        </div>
      </section>
    );
  },
};
```
