# Prompt library

Browse reusable prompts, fill in their variables and select a finished prompt.

Access: pro. Category: Blocks. Kind: composite.

## When to use

- Use it when a page needs browse reusable prompts, fill in their variables and select a finished prompt.
- Choose it inside an authenticated product surface when the host application owns routing, persistence, and service calls.

## Alternatives

- Choose empty-state instead when empty collections, search results and errors with a clear next action is the actual interface need, rather than prompt library.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Prompt library

```sh
npx shadcn@latest add @tidal-pro/prompt-library
```

Stylesheets: `components/ui/tidal.css`, `components/ui/prompt-library.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/prompt-library.css";
import{TidalPromptLibrary}from"./components/ui/prompt-library";
export default(p:Parameters<typeof TidalPromptLibrary>[0])=><div className="tidal-scope"><TidalPromptLibrary {...p}/></div>;
```

## Structured props

- `TidalPromptLibrary.categories: ReadonlyArray<TidalPromptCategory>`: Required categories value accepted by this exported component.
- `TidalPromptLibrary.categoryId: string`: Required category id value accepted by this exported component.
- `TidalPromptLibrary.favorites: ReadonlyArray<string>`: Required favorites value accepted by this exported component.
- `TidalPromptLibrary.favoritesOnly: boolean`: Required favorites only value accepted by this exported component.
- `TidalPromptLibrary.onCategoryChange: (id: string) => void`: Callback invoked when the category change interaction is proposed.
- `TidalPromptLibrary.onFavoriteChange: (id: string, saved: boolean) => void`: Callback invoked when the favorite change interaction is proposed.
- `TidalPromptLibrary.onFavoritesOnlyChange: (only: boolean) => void`: Callback invoked when the favorites only change interaction is proposed.
- `TidalPromptLibrary.onQueryChange: (value: string) => void`: Callback invoked when the query change interaction is proposed.
- `TidalPromptLibrary.onSelectedChange: (id: string) => void`: Callback invoked when the selected change interaction is proposed.
- `TidalPromptLibrary.onUse: (prompt: TidalPromptRecord, rendered: string, event: MouseEvent<HTMLButtonElement>) => void`: Callback invoked when the use interaction is proposed.
- `TidalPromptLibrary.onVariableChange: (id: string, value: string) => void`: Callback invoked when the variable change interaction is proposed.
- `TidalPromptLibrary.prompts: ReadonlyArray<TidalPromptRecord>`: Required prompts value accepted by this exported component.
- `TidalPromptLibrary.query: string`: Required query value accepted by this exported component.
- `TidalPromptLibrary.selectedId: string | null`: Required selected id value accepted by this exported component.
- `TidalPromptLibrary.title: ReactNode`: Required title value accepted by this exported component.
- `TidalPromptLibrary.values: Readonly<Record<string, string>>`: Required values value accepted by this exported component.
- `TidalPromptLibrary.actionProps?: ActionProps | undefined`: Optional action props value accepted by this exported component.
- `TidalPromptLibrary.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalPromptLibrary.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalPromptLibrary.favoriteProps?: ((prompt: TidalPromptRecord) => ActionProps) | undefined`: Optional favorite props value accepted by this exported component.
- `TidalPromptLibrary.formatCount?: ((count: number) => ReactNodeLike) | undefined` (default (count) => `${count} ${count === 1 ? "prompt" : "prompts"}`): Optional format count value accepted by this exported component.
- `TidalPromptLibrary.headingLevel?: "h2" | "h3" | "h4" | "h5" | undefined` (default "h2"): Optional heading level value accepted by this exported component.
- `TidalPromptLibrary.labels?: Partial<{ search: string; category: string; all: string; saved: string; save: string; remove: string; empty: string; choose: string; preview: string; variables: string; use: string; required: string; invalid: string; }> | undefined` (default {}): Optional labels value accepted by this exported component.
- `TidalPromptLibrary.selectProps?: ((prompt: TidalPromptRecord) => ActionProps) | undefined`: Optional select props value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/prompt-library.tsx) | [Manifest](https://tidalui.com/examples/prompt-library.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
import "./components/ui/tidal.css";

import { useState } from "react";

import { TidalPromptLibrary, type TidalPromptRecord } from "./components/ui/prompt-library";

import "./components/ui/prompt-library.css";

import "./components/ui/search-field.css";

import "./components/ui/textarea.css";

import "./components/ui/native-select.css";



export const promptCategories = [
  { id: "research", label: "Research" },
  { id: "product", label: "Product" },
  { id: "writing", label: "Writing" },
];

export const promptRecords: readonly TidalPromptRecord[] = [
  {
    id: "interview",
    title: "Customer interview summary",
    description: "Turn interview notes into evidence and next steps.",
    categoryId: "research",
    content:
      "Summarize these customer notes into pains, requests and next steps. Separate observed evidence from suggestions.\n\n{{notes}}",
    variables: [
      {
        id: "notes",
        label: "Interview notes",
        placeholder: "Paste the notes to summarize",
        required: true,
      },
    ],
  },
  {
    id: "release",
    title: "Release note",
    description: "Explain a product change in plain language.",
    categoryId: "writing",
    content:
      "Write a concise release note for this change. Explain what changed, who it helps, and how to use it. Avoid unsupported claims.\n\n{{change}}",
    variables: [{ id: "change", label: "Product change", required: true }],
  },
  {
    id: "empty",
    title: "Empty-state copy",
    description: "Write a clear next step for a new workspace.",
    categoryId: "product",
    content:
      "Write a short heading, one sentence, and a button label for an empty {{screen}} screen. Help the user take the first useful action.",
    variables: [{ id: "screen", label: "Screen name", required: true }],
  },
];

export function PromptLibraryDemo() {
  const [query, setQuery] = useState(""),
    [category, setCategory] = useState(""),
    [favorites, setFavorites] = useState<readonly string[]>(["interview"]),
    [saved, setSaved] = useState(false),
    [selected, setSelected] = useState<string | null>("interview"),
    [values, setValues] = useState<Readonly<Record<string, string>>>({
      notes: "The team needs a faster way to review open requests.",
    }),
    [status, setStatus] = useState("");
  return (
    <div style={{ width: "100%", maxWidth: 1120, marginInline: "auto" }}>
      <TidalPromptLibrary
        title="Prompt library"
        description="Reusable starting points for product work."
        prompts={promptRecords}
        categories={promptCategories}
        query={query}
        onQueryChange={setQuery}
        categoryId={category}
        onCategoryChange={setCategory}
        favorites={favorites}
        onFavoriteChange={(id, on) =>
          setFavorites((v) => (on ? [...v, id] : v.filter((x) => x !== id)))
        }
        favoritesOnly={saved}
        onFavoritesOnlyChange={setSaved}
        selectedId={selected}
        onSelectedChange={setSelected}
        values={values}
        onVariableChange={(id, value) =>
          setValues((v) => ({ ...v, [id]: value }))
        }
        onUse={(p) =>
          setStatus(p.title + " selected in this preview. No model was called.")
        }
      />
      {status && (
        <p role="status" style={{ fontSize: 12, color: "var(--t-muted)" }}>
          {status}
        </p>
      )}
    </div>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <PromptLibraryDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Controlled prompt records, categories, search text, category filter, favorites, saved-only filter, selection and variable values. Unique known IDs and declared {{variable}} names are validated. Search matches titles and descriptions locally. Variables render as labelled Textarea fields; exact text substitution produces a read-only preview and required empty fields disable Use prompt. Optional empty values substitute an empty string. Native selection/favorite/use buttons preserve caller-first prevention and disabled state. Accepted Search input, Native select and Textarea supply controls; native section ref, translated labels, h2-h5 hierarchy, empty results, RTL and narrow stacking are supported. Removed or disabled owned focus recovers only from source/body to the persistent root. No model call, clipboard action, request, storage, persistence or execution occurs; onUse receives the selected record and exact rendered text. Use/select/favorite button props accept native React19 refs with cleanup; prop getters resolve once per visible prompt and the same result owns rendering, availability and callbacks. formatCount localizes the exact visible result count, including zero.
